blob: 0cb4a56feee067311325fd478572b9ed69173304 [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 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001261 final long identity = Binder.clearCallingIdentity();
1262 try {
1263 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1264 } finally {
1265 Binder.restoreCallingIdentity(identity);
1266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 }
1268
1269 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001270 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001271 }
1272
Wink Savilleb564aae2014-10-23 10:18:09 -07001273 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 if (DBG) log("answerRingingCall...");
1275 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1276 // but that can probably wait till the big TelephonyManager API overhaul.
1277 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1278 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001279
1280 final long identity = Binder.clearCallingIdentity();
1281 try {
1282 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1283 } finally {
1284 Binder.restoreCallingIdentity(identity);
1285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 }
1287
1288 /**
1289 * Make the actual telephony calls to implement answerRingingCall().
1290 * This should only be called from the main thread of the Phone app.
1291 * @see #answerRingingCall
1292 *
1293 * TODO: it would be nice to return true if we answered the call, or
1294 * false if there wasn't actually a ringing incoming call, or some
1295 * other error occurred. (In other words, pass back the return value
1296 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1297 * But that would require calling this method via sendRequest() rather
1298 * than sendRequestAsync(), and right now we don't actually *need* that
1299 * return value, so let's just return void for now.
1300 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001301 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001302 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001304 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1305 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 if (hasActiveCall && hasHoldingCall) {
1307 // Both lines are in use!
1308 // TODO: provide a flag to let the caller specify what
1309 // policy to use if both lines are in use. (The current
1310 // behavior is hardwired to "answer incoming, end ongoing",
1311 // which is how the CALL button is specced to behave.)
1312 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1313 return;
1314 } else {
1315 // answerCall() will automatically hold the current active
1316 // call, if there is one.
1317 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1318 return;
1319 }
1320 } else {
1321 // No call was ringing.
1322 return;
1323 }
1324 }
1325
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001327 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001329 public void silenceRinger() {
1330 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 }
1332
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001333 @Override
1334 public boolean isOffhook(String callingPackage) {
1335 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001336 }
1337
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001338 @Override
1339 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001341 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001342 return false;
1343 }
1344
Malcolm Chenaabec062018-02-28 15:00:40 -08001345 final long identity = Binder.clearCallingIdentity();
1346 try {
1347 final Phone phone = getPhone(subId);
1348 if (phone != null) {
1349 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1350 } else {
1351 return false;
1352 }
1353 } finally {
1354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 }
1357
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001358 @Override
1359 public boolean isRinging(String callingPackage) {
1360 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001363 @Override
1364 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001366 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001367 return false;
1368 }
1369
Malcolm Chenaabec062018-02-28 15:00:40 -08001370 final long identity = Binder.clearCallingIdentity();
1371 try {
1372 final Phone phone = getPhone(subId);
1373 if (phone != null) {
1374 return (phone.getState() == PhoneConstants.State.RINGING);
1375 } else {
1376 return false;
1377 }
1378 } finally {
1379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 }
1382
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001383 @Override
1384 public boolean isIdle(String callingPackage) {
1385 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001386 }
1387
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001388 @Override
1389 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001391 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001392 return false;
1393 }
1394
Malcolm Chenaabec062018-02-28 15:00:40 -08001395 final long identity = Binder.clearCallingIdentity();
1396 try {
1397 final Phone phone = getPhone(subId);
1398 if (phone != null) {
1399 return (phone.getState() == PhoneConstants.State.IDLE);
1400 } else {
1401 return false;
1402 }
1403 } finally {
1404 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 }
1407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001409 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001410 }
1411
Wink Savilleb564aae2014-10-23 10:18:09 -07001412 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001413 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001414 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1415 }
1416
1417 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001418 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001419 }
1420
Wink Savilleb564aae2014-10-23 10:18:09 -07001421 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001422 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001423 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1424 }
1425
1426 /** {@hide} */
1427 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001428 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001429 }
1430
Wink Savilleb564aae2014-10-23 10:18:09 -07001431 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001433
1434 final long identity = Binder.clearCallingIdentity();
1435 try {
1436 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1437 checkSimPin.start();
1438 return checkSimPin.unlockSim(null, pin);
1439 } finally {
1440 Binder.restoreCallingIdentity(identity);
1441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442 }
1443
Wink Saville9de0f752013-10-22 19:04:03 -07001444 /** {@hide} */
1445 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001446 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001447 }
1448
Wink Savilleb564aae2014-10-23 10:18:09 -07001449 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001451
1452 final long identity = Binder.clearCallingIdentity();
1453 try {
1454 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1455 checkSimPuk.start();
1456 return checkSimPuk.unlockSim(puk, pin);
1457 } finally {
1458 Binder.restoreCallingIdentity(identity);
1459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 }
1461
1462 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001463 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 * a synchronous one.
1465 */
1466 private static class UnlockSim extends Thread {
1467
1468 private final IccCard mSimCard;
1469
1470 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001471 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1472 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473
1474 // For replies from SimCard interface
1475 private Handler mHandler;
1476
1477 // For async handler to identify request type
1478 private static final int SUPPLY_PIN_COMPLETE = 100;
1479
1480 public UnlockSim(IccCard simCard) {
1481 mSimCard = simCard;
1482 }
1483
1484 @Override
1485 public void run() {
1486 Looper.prepare();
1487 synchronized (UnlockSim.this) {
1488 mHandler = new Handler() {
1489 @Override
1490 public void handleMessage(Message msg) {
1491 AsyncResult ar = (AsyncResult) msg.obj;
1492 switch (msg.what) {
1493 case SUPPLY_PIN_COMPLETE:
1494 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1495 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001496 mRetryCount = msg.arg1;
1497 if (ar.exception != null) {
1498 if (ar.exception instanceof CommandException &&
1499 ((CommandException)(ar.exception)).getCommandError()
1500 == CommandException.Error.PASSWORD_INCORRECT) {
1501 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1502 } else {
1503 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1504 }
1505 } else {
1506 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 mDone = true;
1509 UnlockSim.this.notifyAll();
1510 }
1511 break;
1512 }
1513 }
1514 };
1515 UnlockSim.this.notifyAll();
1516 }
1517 Looper.loop();
1518 }
1519
1520 /*
1521 * Use PIN or PUK to unlock SIM card
1522 *
1523 * If PUK is null, unlock SIM card with PIN
1524 *
1525 * If PUK is not null, unlock SIM card with PUK and set PIN code
1526 */
Wink Saville9de0f752013-10-22 19:04:03 -07001527 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528
1529 while (mHandler == null) {
1530 try {
1531 wait();
1532 } catch (InterruptedException e) {
1533 Thread.currentThread().interrupt();
1534 }
1535 }
1536 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1537
1538 if (puk == null) {
1539 mSimCard.supplyPin(pin, callback);
1540 } else {
1541 mSimCard.supplyPuk(puk, pin, callback);
1542 }
1543
1544 while (!mDone) {
1545 try {
1546 Log.d(LOG_TAG, "wait for done");
1547 wait();
1548 } catch (InterruptedException e) {
1549 // Restore the interrupted status
1550 Thread.currentThread().interrupt();
1551 }
1552 }
1553 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001554 int[] resultArray = new int[2];
1555 resultArray[0] = mResult;
1556 resultArray[1] = mRetryCount;
1557 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 }
1559 }
1560
1561 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001562 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001563
1564 }
1565
Wink Savilleb564aae2014-10-23 10:18:09 -07001566 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 // No permission check needed here: this call is harmless, and it's
1568 // needed for the ServiceState.requestStateUpdate() call (which is
1569 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001570 final long identity = Binder.clearCallingIdentity();
1571 try {
1572 final Phone phone = getPhone(subId);
1573 if (phone != null) {
1574 phone.updateServiceLocation();
1575 }
1576 } finally {
1577 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 }
1580
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001581 @Override
1582 public boolean isRadioOn(String callingPackage) {
1583 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001584 }
1585
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001586 @Override
1587 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001589 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001590 return false;
1591 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001592
1593 final long identity = Binder.clearCallingIdentity();
1594 try {
1595 return isRadioOnForSubscriber(subId);
1596 } finally {
1597 Binder.restoreCallingIdentity(identity);
1598 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001599 }
1600
1601 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001602 final long identity = Binder.clearCallingIdentity();
1603 try {
1604 final Phone phone = getPhone(subId);
1605 if (phone != null) {
1606 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1607 } else {
1608 return false;
1609 }
1610 } finally {
1611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 }
1614
1615 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001616 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 }
Wink Saville36469e72014-06-11 15:17:00 -07001618
Wink Savilleb564aae2014-10-23 10:18:09 -07001619 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001621
1622 final long identity = Binder.clearCallingIdentity();
1623 try {
1624 final Phone phone = getPhone(subId);
1625 if (phone != null) {
1626 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1627 }
1628 } finally {
1629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 }
Wink Saville36469e72014-06-11 15:17:00 -07001631 }
1632
1633 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001634 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001635 }
1636
Wink Savilleb564aae2014-10-23 10:18:09 -07001637 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001638 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001639
1640 final long identity = Binder.clearCallingIdentity();
1641 try {
1642 final Phone phone = getPhone(subId);
1643 if (phone == null) {
1644 return false;
1645 }
1646 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1647 toggleRadioOnOffForSubscriber(subId);
1648 }
1649 return true;
1650 } finally {
1651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
Wink Saville36469e72014-06-11 15:17:00 -07001654
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001655 public boolean needMobileRadioShutdown() {
1656 /*
1657 * If any of the Radios are available, it will need to be
1658 * shutdown. So return true if any Radio is available.
1659 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1663 Phone phone = PhoneFactory.getPhone(i);
1664 if (phone != null && phone.isRadioAvailable()) return true;
1665 }
1666 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1667 return false;
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001670 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001671 }
1672
Malcolm Chenaabec062018-02-28 15:00:40 -08001673 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001674 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001675 enforceModifyPermission();
1676
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1680 logv("Shutting down Phone " + i);
1681 shutdownRadioUsingPhoneId(i);
1682 }
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001685 }
1686 }
1687
1688 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001689 Phone phone = PhoneFactory.getPhone(phoneId);
1690 if (phone != null && phone.isRadioAvailable()) {
1691 phone.shutdownRadio();
1692 }
1693 }
1694
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001696 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001697
1698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1701 if (defaultPhone != null) {
1702 defaultPhone.setRadioPower(turnOn);
1703 return true;
1704 } else {
1705 loge("There's no default phone.");
1706 return false;
1707 }
1708 } finally {
1709 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001710 }
Wink Saville36469e72014-06-11 15:17:00 -07001711 }
1712
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.setRadioPower(turnOn);
1721 return true;
1722 } else {
1723 return false;
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
Wink Saville36469e72014-06-11 15:17:00 -07001730 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001731 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public boolean enableDataConnectivity() {
1733 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001734
1735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 int subId = mSubscriptionController.getDefaultDataSubId();
1738 final Phone phone = getPhone(subId);
1739 if (phone != null) {
1740 phone.setUserDataEnabled(true);
1741 return true;
1742 } else {
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
Wink Saville36469e72014-06-11 15:17:00 -07001750 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 public boolean disableDataConnectivity() {
1753 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001754
1755 final long identity = Binder.clearCallingIdentity();
1756 try {
1757 int subId = mSubscriptionController.getDefaultDataSubId();
1758 final Phone phone = getPhone(subId);
1759 if (phone != null) {
1760 phone.setUserDataEnabled(false);
1761 return true;
1762 } else {
1763 return false;
1764 }
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
Sanket Padawe356d7632015-06-22 14:03:32 -07001770 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001771 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001772 final long identity = Binder.clearCallingIdentity();
1773 try {
1774 final Phone phone = getPhone(subId);
1775 if (phone != null) {
1776 return phone.isDataAllowed();
1777 } else {
1778 return false;
1779 }
1780 } finally {
1781 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
1784
1785 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001786 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001787 }
1788
pkanwarae03a6b2016-11-06 20:37:09 -08001789 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001790 enforceCallPermission();
1791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1795 return;
1796 }
1797 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1798 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1799 } finally {
1800 Binder.restoreCallingIdentity(identity);
1801 }
pkanwar32d516d2016-10-14 19:37:38 -07001802 };
1803
Wink Savilleb564aae2014-10-23 10:18:09 -07001804 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001806
1807 final long identity = Binder.clearCallingIdentity();
1808 try {
1809 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1810 return false;
1811 }
1812 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1813 } finally {
1814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 }
1817
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001819 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001820 }
1821
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001822 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001823 final long identity = Binder.clearCallingIdentity();
1824 try {
1825 Phone phone = PhoneFactory.getPhone(slotIndex);
1826 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1827 PhoneConstantConversions.convertCallState(phone.getState());
1828 } finally {
1829 Binder.restoreCallingIdentity(identity);
1830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
Sanket Padawe356d7632015-06-22 14:03:32 -07001833 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1838 if (phone != null) {
1839 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1840 } else {
1841 return PhoneConstantConversions.convertDataState(
1842 PhoneConstants.DataState.DISCONNECTED);
1843 }
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 }
1848
Sanket Padawe356d7632015-06-22 14:03:32 -07001849 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001851 final long identity = Binder.clearCallingIdentity();
1852 try {
1853 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1854 if (phone != null) {
1855 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1856 } else {
1857 return TelephonyManager.DATA_ACTIVITY_NONE;
1858 }
1859 } finally {
1860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 }
1863
1864 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001865 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001866 mPhone.getContext().getSystemService(AppOpsManager.class)
1867 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001868 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001869 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001870 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 }
1872
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001873 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 if (DBG_LOC) log("getCellLocation: is active user");
1877 Bundle data = new Bundle();
1878 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1879 if (phone == null) {
1880 return null;
1881 }
1882
1883 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1884 return data;
1885 } finally {
1886 Binder.restoreCallingIdentity(identity);
1887 }
Svetoslav64fad262015-04-14 14:35:21 -07001888 }
1889
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 public String getNetworkCountryIsoForPhone(int phoneId) {
1892 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1893 // registered cell info, so return a NULL country instead.
1894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001897 // Todo: fix this when we can get the actual cellular network info when the device
1898 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001899 if (TelephonyManager.NETWORK_TYPE_IWLAN
1900 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1901 return "";
1902 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001903 Phone phone = PhoneFactory.getPhone(phoneId);
1904 if (phone != null) {
1905 ServiceStateTracker sst = phone.getServiceStateTracker();
1906 if (sst != null) {
1907 LocaleTracker lt = sst.getLocaleTracker();
1908 if (lt != null) {
1909 return lt.getCurrentCountry();
1910 }
1911 }
1912 }
1913 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001914 } finally {
1915 Binder.restoreCallingIdentity(identity);
1916 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001917 }
1918
1919 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001921 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001922 }
1923
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001925 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 mApp.enforceCallingOrSelfPermission(
1927 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 final Phone phone = getPhone(subId);
1932 if (phone != null) {
1933 phone.enableLocationUpdates();
1934 }
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
1940 @Override
1941 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001942 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001943 }
1944
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001946 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 mApp.enforceCallingOrSelfPermission(
1948 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001949
1950 final long identity = Binder.clearCallingIdentity();
1951 try {
1952 final Phone phone = getPhone(subId);
1953 if (phone != null) {
1954 phone.disableLocationUpdates();
1955 }
1956 } finally {
1957 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
1960
1961 @Override
1962 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001963 public List<NeighboringCellInfo>
1964 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001965 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1966 throw new SecurityException(
1967 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1968 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001969
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1971 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1972 return null;
1973 }
Svetoslav64fad262015-04-14 14:35:21 -07001974
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001975 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976
Nathan Haroldf180aac2018-06-01 18:43:55 -07001977 List<CellInfo> info = getAllCellInfo(callingPackage);
1978 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979
Nathan Haroldf180aac2018-06-01 18:43:55 -07001980 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1981 for (CellInfo ci : info) {
1982 if (ci instanceof CellInfoGsm) {
1983 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1984 } else if (ci instanceof CellInfoWcdma) {
1985 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001988 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
1991
1992 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001993 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001994 mPhone.getContext().getSystemService(AppOpsManager.class)
1995 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001996 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001997 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001998 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002001 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002002 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08002003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2006 for (Phone phone : PhoneFactory.getPhones()) {
2007 final List<CellInfo> info = phone.getAllCellInfo(workSource);
2008 if (info != null) cellInfos.addAll(info);
2009 }
2010 return cellInfos;
2011 } finally {
2012 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014 }
2015
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002016 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002018 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 mPhone.setCellInfoListRate(rateInMillis, workSource);
2024 } finally {
2025 Binder.restoreCallingIdentity(identity);
2026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028
Shishir Agrawala9f32182016-04-12 12:00:16 -07002029 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002030 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002031 Phone phone = PhoneFactory.getPhone(slotIndex);
2032 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002033 return null;
2034 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002035 int subId = phone.getSubId();
2036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2037 mApp, subId, callingPackage, "getImeiForSlot")) {
2038 return null;
2039 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002040
2041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 return phone.getImei();
2044 } finally {
2045 Binder.restoreCallingIdentity(identity);
2046 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002047 }
2048
2049 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002050 public String getTypeAllocationCodeForSlot(int slotIndex) {
2051 Phone phone = PhoneFactory.getPhone(slotIndex);
2052 String tac = null;
2053 if (phone != null) {
2054 String imei = phone.getImei();
2055 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2056 }
2057 return tac;
2058 }
2059
2060 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002061 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002062 Phone phone = PhoneFactory.getPhone(slotIndex);
2063 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002064 return null;
2065 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002066 int subId = phone.getSubId();
2067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2068 mApp, subId, callingPackage, "getMeidForSlot")) {
2069 return null;
2070 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002071
2072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 return phone.getMeid();
2075 } finally {
2076 Binder.restoreCallingIdentity(identity);
2077 }
Jack Yu2af8d712017-03-15 17:14:14 -07002078 }
2079
2080 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002081 public String getManufacturerCodeForSlot(int slotIndex) {
2082 Phone phone = PhoneFactory.getPhone(slotIndex);
2083 String manufacturerCode = null;
2084 if (phone != null) {
2085 String meid = phone.getMeid();
2086 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2087 }
2088 return manufacturerCode;
2089 }
2090
2091 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002092 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002093 Phone phone = PhoneFactory.getPhone(slotIndex);
2094 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002095 return null;
2096 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002097 int subId = phone.getSubId();
2098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2099 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2100 return null;
2101 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 return phone.getDeviceSvn();
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
2108 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002109 }
2110
fionaxu43304da2017-11-27 22:51:16 -08002111 @Override
2112 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 final Phone phone = getPhone(subId);
2116 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
fionaxu43304da2017-11-27 22:51:16 -08002120 }
2121
2122 @Override
2123 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 return phone == null ? null : phone.getCarrierName();
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
2130 }
fionaxu43304da2017-11-27 22:51:16 -08002131 }
2132
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 //
2134 // Internal helper methods.
2135 //
2136
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002137 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2139 *
2140 * @throws SecurityException if the caller does not have the required permission
2141 */
2142 private void enforceModifyPermission() {
2143 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2144 }
2145
2146 /**
2147 * Make sure the caller has the CALL_PHONE permission.
2148 *
2149 * @throws SecurityException if the caller does not have the required permission
2150 */
2151 private void enforceCallPermission() {
2152 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2153 }
2154
Stuart Scott8eef64f2015-04-08 15:13:54 -07002155 private void enforceConnectivityInternalPermission() {
2156 mApp.enforceCallingOrSelfPermission(
2157 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2158 "ConnectivityService");
2159 }
2160
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 private String createTelUrl(String number) {
2162 if (TextUtils.isEmpty(number)) {
2163 return null;
2164 }
2165
Jake Hambye994d462014-02-03 13:10:13 -08002166 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Ihab Awadf9e92732013-12-05 18:02:52 -08002169 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2171 }
2172
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002173 private static void logv(String msg) {
2174 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2175 }
2176
Ihab Awadf9e92732013-12-05 18:02:52 -08002177 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2179 }
2180
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002181 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002183 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002184 }
2185
Sanket Padawe356d7632015-06-22 14:03:32 -07002186 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002187 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002188 final long identity = Binder.clearCallingIdentity();
2189 try {
2190 final Phone phone = PhoneFactory.getPhone(slotIndex);
2191 if (phone == null) {
2192 return PhoneConstants.PHONE_TYPE_NONE;
2193 } else {
2194 return phone.getPhoneType();
2195 }
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200
2201 /**
2202 * Returns the CDMA ERI icon index to display
2203 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002204 @Override
2205 public int getCdmaEriIconIndex(String callingPackage) {
2206 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002207 }
2208
Sanket Padawe356d7632015-06-22 14:03:32 -07002209 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002210 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002212 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002213 return -1;
2214 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002215
2216 final long identity = Binder.clearCallingIdentity();
2217 try {
2218 final Phone phone = getPhone(subId);
2219 if (phone != null) {
2220 return phone.getCdmaEriIconIndex();
2221 } else {
2222 return -1;
2223 }
2224 } finally {
2225 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 }
2228
2229 /**
2230 * Returns the CDMA ERI icon mode,
2231 * 0 - ON
2232 * 1 - FLASHING
2233 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 @Override
2235 public int getCdmaEriIconMode(String callingPackage) {
2236 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002237 }
2238
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002240 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002242 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002243 return -1;
2244 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002245
2246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 final Phone phone = getPhone(subId);
2249 if (phone != null) {
2250 return phone.getCdmaEriIconMode();
2251 } else {
2252 return -1;
2253 }
2254 } finally {
2255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 }
2258
2259 /**
2260 * Returns the CDMA ERI text,
2261 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 @Override
2263 public String getCdmaEriText(String callingPackage) {
2264 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002265 }
2266
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002268 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002270 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002271 return null;
2272 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002273
2274 final long identity = Binder.clearCallingIdentity();
2275 try {
2276 final Phone phone = getPhone(subId);
2277 if (phone != null) {
2278 return phone.getCdmaEriText();
2279 } else {
2280 return null;
2281 }
2282 } finally {
2283 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
2287 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002288 * Returns the CDMA MDN.
2289 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002290 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002291 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2293 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002294
2295 final long identity = Binder.clearCallingIdentity();
2296 try {
2297 final Phone phone = getPhone(subId);
2298 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2299 return phone.getLine1Number();
2300 } else {
2301 return null;
2302 }
2303 } finally {
2304 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002305 }
2306 }
2307
2308 /**
2309 * Returns the CDMA MIN.
2310 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002312 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2314 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002315
2316 final long identity = Binder.clearCallingIdentity();
2317 try {
2318 final Phone phone = getPhone(subId);
2319 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2320 return phone.getCdmaMin();
2321 } else {
2322 return null;
2323 }
2324 } finally {
2325 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002326 }
2327 }
2328
2329 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 * Returns true if CDMA provisioning needs to run.
2331 */
2332 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002333 final long identity = Binder.clearCallingIdentity();
2334 try {
2335 return mPhone.needsOtaServiceProvisioning();
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
2341 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002342 * Sets the voice mail number of a given subId.
2343 */
2344 @Override
2345 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002346 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2351 new Pair<String, String>(alphaTag, number), new Integer(subId));
2352 return success;
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
2355 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002356 }
2357
Ta-wei Yen87c49842016-05-13 21:19:52 -07002358 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002359 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2360 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2361 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2362 if (!TextUtils.equals(callingPackage, systemDialer)) {
2363 throw new SecurityException("caller must be system dialer");
2364 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2369 if (phoneAccountHandle == null) {
2370 return null;
2371 }
2372 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2373 } finally {
2374 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002375 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002376 }
2377
2378 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002379 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002382 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002383 return null;
2384 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002385
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 return RemoteVvmTaskManager
2389 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002393 }
2394
2395 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002396 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2397 VisualVoicemailSmsFilterSettings settings) {
2398 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002399
2400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2403 mPhone.getContext(), callingPackage, subId, settings);
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
2406 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002407 }
2408
2409 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002410 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002412
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2416 mPhone.getContext(), callingPackage, subId);
2417 } finally {
2418 Binder.restoreCallingIdentity(identity);
2419 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002420 }
2421
2422 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002423 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2424 String callingPackage, int subId) {
2425 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002426
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2430 mPhone.getContext(), callingPackage, subId);
2431 } finally {
2432 Binder.restoreCallingIdentity(identity);
2433 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002434 }
2435
2436 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002437 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002438 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002439
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2443 mPhone.getContext(), subId);
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
2446 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002447 }
2448
2449 @Override
2450 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2451 String number, int port, String text, PendingIntent sentIntent) {
2452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002453 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002454 enforceSendSmsPermission();
2455 // Make the calls as the phone process.
2456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2459 if (port == 0) {
2460 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2461 sentIntent, null, false);
2462 } else {
2463 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2464 smsManager.sendDataMessageWithSelfPermissions(number, null,
2465 (short) port, data, sentIntent, null);
2466 }
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
2469 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002470 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002471 /**
fionaxu0152e512016-11-14 13:36:14 -08002472 * Sets the voice activation state of a given subId.
2473 */
2474 @Override
2475 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2477 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
2481 final Phone phone = getPhone(subId);
2482 if (phone != null) {
2483 phone.setVoiceActivationState(activationState);
2484 } else {
2485 loge("setVoiceActivationState fails with invalid subId: " + subId);
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002489 }
2490 }
2491
2492 /**
2493 * Sets the data activation state of a given subId.
2494 */
2495 @Override
2496 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2498 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = getPhone(subId);
2503 if (phone != null) {
2504 phone.setDataActivationState(activationState);
2505 } else {
2506 loge("setVoiceActivationState fails with invalid subId: " + subId);
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002510 }
2511 }
2512
2513 /**
2514 * Returns the voice activation state of a given subId.
2515 */
2516 @Override
2517 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002518 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002519
fionaxu0152e512016-11-14 13:36:14 -08002520 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002521 final long identity = Binder.clearCallingIdentity();
2522 try {
2523 if (phone != null) {
2524 return phone.getVoiceActivationState();
2525 } else {
2526 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002530 }
2531 }
2532
2533 /**
2534 * Returns the data activation state of a given subId.
2535 */
2536 @Override
2537 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002538 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002539
fionaxu0152e512016-11-14 13:36:14 -08002540 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 if (phone != null) {
2544 return phone.getDataActivationState();
2545 } else {
2546 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2547 }
2548 } finally {
2549 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002550 }
2551 }
2552
2553 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 * Returns the unread count of voicemails
2555 */
2556 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002557 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002558 }
2559
2560 /**
2561 * Returns the unread count of voicemails for a subId
2562 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002564 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 final Phone phone = getPhone(subId);
2568 if (phone != null) {
2569 return phone.getVoiceMessageCount();
2570 } else {
2571 return 0;
2572 }
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 }
2577
2578 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002579 * returns true, if the device is in a state where both voice and data
2580 * are supported simultaneously. This can change based on location or network condition.
2581 */
2582 @Override
2583 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
2590 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002591 }
2592
2593 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002594 * Send the dialer code if called from the current default dialer or the caller has
2595 * carrier privilege.
2596 * @param inputCode The dialer code to send
2597 */
2598 @Override
2599 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2600 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2601 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2602 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002603 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2604 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002605 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002606
2607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 mPhone.sendDialerSpecialCode(inputCode);
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
2612 }
fionaxu235cc5e2017-03-06 22:25:57 -08002613 }
2614
2615 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002616 * Returns the data network type.
2617 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 *
2619 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2620 */
2621 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002622 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 final Phone phone = getPhone(getDefaultSubscription());
2626 if (phone != null) {
2627 return phone.getServiceState().getDataNetworkType();
2628 } else {
2629 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002633 }
Wink Saville36469e72014-06-11 15:17:00 -07002634 }
2635
Pengquan Meng0c05b502018-09-06 09:59:22 -07002636 @Override
2637 public int getNetworkSelectionMode(int subId) {
2638 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2639 }
2640
Wink Saville36469e72014-06-11 15:17:00 -07002641 /**
2642 * Returns the network type for a subId
2643 */
2644 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002645 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002647 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002648 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2649 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002650
Malcolm Chenaabec062018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone phone = getPhone(subId);
2654 if (phone != null) {
2655 return phone.getServiceState().getDataNetworkType();
2656 } else {
2657 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2658 }
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
2663
2664 /**
2665 * Returns the data network type
2666 */
2667 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002668 public int getDataNetworkType(String callingPackage) {
2669 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002670 }
2671
2672 /**
2673 * Returns the data network type for a subId
2674 */
2675 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002676 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002678 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002679 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2680 }
2681
Malcolm Chenaabec062018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = getPhone(subId);
2685 if (phone != null) {
2686 return phone.getServiceState().getDataNetworkType();
2687 } else {
2688 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2689 }
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694
2695 /**
Wink Saville36469e72014-06-11 15:17:00 -07002696 * Returns the Voice network type for a subId
2697 */
2698 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002699 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002701 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002702 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2703 }
2704
Malcolm Chenaabec062018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 final Phone phone = getPhone(subId);
2708 if (phone != null) {
2709 return phone.getServiceState().getVoiceNetworkType();
2710 } else {
2711 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2712 }
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
2717
2718 /**
2719 * @return true if a ICC card is present
2720 */
2721 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002722 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002723 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2724 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002725 }
2726
2727 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002728 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002729 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002730 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002731 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 final Phone phone = PhoneFactory.getPhone(slotIndex);
2735 if (phone != null) {
2736 return phone.getIccCard().hasIccCard();
2737 } else {
2738 return false;
2739 }
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
2744
2745 /**
2746 * Return if the current radio is LTE on CDMA. This
2747 * is a tri-state return value as for a period of time
2748 * the mode may be unknown.
2749 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002750 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002752 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002753 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002754 @Override
2755 public int getLteOnCdmaMode(String callingPackage) {
2756 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002757 }
2758
Sanket Padawe356d7632015-06-22 14:03:32 -07002759 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002760 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002762 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002763 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2764 }
2765
Malcolm Chenaabec062018-02-28 15:00:40 -08002766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(subId);
2769 if (phone == null) {
2770 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2771 } else {
2772 return phone.getLteOnCdmaMode();
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 }
Wink Saville36469e72014-06-11 15:17:00 -07002777 }
2778
2779 public void setPhone(Phone phone) {
2780 mPhone = phone;
2781 }
2782
2783 /**
2784 * {@hide}
2785 * Returns Default subId, 0 in the case of single standby.
2786 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002787 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002788 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002789 }
2790
Shishir Agrawala9f32182016-04-12 12:00:16 -07002791 private int getSlotForDefaultSubscription() {
2792 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2793 }
2794
Wink Savilleb564aae2014-10-23 10:18:09 -07002795 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002796 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002798
2799 /**
2800 * @see android.telephony.TelephonyManager.WifiCallingChoices
2801 */
2802 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2806 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2807 getWhenToMakeWifiCallsDefaultPreference());
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
2810 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002811 }
2812
2813 /**
2814 * @see android.telephony.TelephonyManager.WifiCallingChoices
2815 */
2816 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2820 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2821 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2822 } finally {
2823 Binder.restoreCallingIdentity(identity);
2824 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002825 }
2826
Sailesh Nepald1e68152013-12-12 19:08:02 -08002827 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002828 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002829 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002830 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002831
Shishir Agrawal566b7612013-10-28 14:41:00 -07002832 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002833 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2834 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2836 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002838
Malcolm Chenaabec062018-02-28 15:00:40 -08002839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 if (TextUtils.equals(ISDR_AID, aid)) {
2842 // Only allows LPA to open logical channel to ISD-R.
2843 ComponentInfo bestComponent =
2844 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2845 if (bestComponent == null
2846 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2847 loge("The calling package is not allowed to access ISD-R.");
2848 throw new SecurityException(
2849 "The calling package is not allowed to access ISD-R.");
2850 }
Derek Tan740e1672017-06-27 14:56:27 -07002851 }
Derek Tan740e1672017-06-27 14:56:27 -07002852
Malcolm Chenaabec062018-02-28 15:00:40 -08002853 if (DBG) {
2854 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2855 }
2856 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2857 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2858 if (DBG) log("iccOpenLogicalChannel: " + response);
2859 return response;
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
2862 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002863 }
2864
2865 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002866 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2868 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002869
Malcolm Chenaabec062018-02-28 15:00:40 -08002870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2873 if (channel < 0) {
2874 return false;
2875 }
2876 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2877 if (DBG) log("iccCloseLogicalChannel: " + success);
2878 return success;
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002881 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002882 }
2883
2884 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002885 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002886 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2888 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002889
Malcolm Chenaabec062018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 if (DBG) {
2893 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2894 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2895 + p3 + " data=" + data);
2896 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002897
Malcolm Chenaabec062018-02-28 15:00:40 -08002898 if (channel < 0) {
2899 return "";
2900 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002901
Malcolm Chenaabec062018-02-28 15:00:40 -08002902 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2903 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2904 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002905
Malcolm Chenaabec062018-02-28 15:00:40 -08002906 // Append the returned status code to the end of the response payload.
2907 String s = Integer.toHexString(
2908 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2909 if (response.payload != null) {
2910 s = IccUtils.bytesToHexString(response.payload) + s;
2911 }
2912 return s;
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002915 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002916 }
Jake Hambye994d462014-02-03 13:10:13 -08002917
Evan Charltonc66da362014-05-16 14:06:40 -07002918 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002919 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2920 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2922 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002923 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002924
Malcolm Chenaabec062018-02-28 15:00:40 -08002925 final long identity = Binder.clearCallingIdentity();
2926 try {
2927 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2928 && TextUtils.equals(ISDR_AID, data)) {
2929 // Only allows LPA to select ISD-R.
2930 ComponentInfo bestComponent =
2931 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2932 if (bestComponent == null
2933 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2934 loge("The calling package is not allowed to select ISD-R.");
2935 throw new SecurityException(
2936 "The calling package is not allowed to select ISD-R.");
2937 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002938 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002939
Malcolm Chenaabec062018-02-28 15:00:40 -08002940 if (DBG) {
2941 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2942 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2943 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002944
Malcolm Chenaabec062018-02-28 15:00:40 -08002945 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2946 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2947 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002948
Malcolm Chenaabec062018-02-28 15:00:40 -08002949 // Append the returned status code to the end of the response payload.
2950 String s = Integer.toHexString(
2951 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2952 if (response.payload != null) {
2953 s = IccUtils.bytesToHexString(response.payload) + s;
2954 }
2955 return s;
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002958 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002959 }
2960
2961 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002962 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002963 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2965 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002966
Malcolm Chenaabec062018-02-28 15:00:40 -08002967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 if (DBG) {
2970 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2971 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2972 }
2973
2974 IccIoResult response =
2975 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2976 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2977 subId);
2978
2979 if (DBG) {
2980 log("Exchange SIM_IO [R]" + response);
2981 }
2982
2983 byte[] result = null;
2984 int length = 2;
2985 if (response.payload != null) {
2986 length = 2 + response.payload.length;
2987 result = new byte[length];
2988 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2989 } else {
2990 result = new byte[length];
2991 }
2992
2993 result[length - 1] = (byte) response.sw2;
2994 result[length - 2] = (byte) response.sw1;
2995 return result;
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002998 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002999 }
3000
Nathan Haroldb3014052017-01-25 15:57:32 -08003001 /**
3002 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3003 * on a particular subscription
3004 */
sqianb6e41952018-03-12 14:54:01 -07003005 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3007 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3008 return null;
3009 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003010 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
3011 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3012 return null;
3013 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003014
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3018 if (response instanceof String[]) {
3019 return (String[]) response;
3020 }
3021 // Response is an Exception of some kind,
3022 // which is signalled to the user as a NULL retval
3023 return null;
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003026 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003027 }
3028
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003030 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3032 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003033
Malcolm Chenaabec062018-02-28 15:00:40 -08003034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3037 if (response.payload == null) {
3038 return "";
3039 }
Evan Charltonc66da362014-05-16 14:06:40 -07003040
Malcolm Chenaabec062018-02-28 15:00:40 -08003041 // Append the returned status code to the end of the response payload.
3042 String s = Integer.toHexString(
3043 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3044 s = IccUtils.bytesToHexString(response.payload) + s;
3045 return s;
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
Evan Charltonc66da362014-05-16 14:06:40 -07003049 }
3050
Jake Hambye994d462014-02-03 13:10:13 -08003051 /**
3052 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3053 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3054 *
3055 * @param itemID the ID of the item to read
3056 * @return the NV item as a String, or null on error.
3057 */
3058 @Override
3059 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3062 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003063
3064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003067 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003068 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3069 return value;
3070 } finally {
3071 Binder.restoreCallingIdentity(identity);
3072 }
Jake Hambye994d462014-02-03 13:10:13 -08003073 }
3074
3075 /**
3076 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3077 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3078 *
3079 * @param itemID the ID of the item to read
3080 * @param itemValue the value to write, as a String
3081 * @return true on success; false on any failure
3082 */
3083 @Override
3084 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003085 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3087 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003088
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3092 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003093 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003094 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3095 return success;
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
Jake Hambye994d462014-02-03 13:10:13 -08003099 }
3100
3101 /**
3102 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3103 * Used for device configuration by some CDMA operators.
3104 *
3105 * @param preferredRoamingList byte array containing the new PRL
3106 * @return true on success; false on any failure
3107 */
3108 @Override
3109 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3111 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003112
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3116 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3117 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3118 return success;
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
Jake Hambye994d462014-02-03 13:10:13 -08003122 }
3123
3124 /**
3125 * Perform the specified type of NV config reset.
3126 * Used for device configuration by some CDMA operators.
3127 *
3128 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3129 * @return true on success; false on any failure
3130 */
3131 @Override
3132 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3134 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003135
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 if (DBG) log("nvResetConfig: type " + resetType);
3139 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3140 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3141 return success;
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
3144 }
Jake Hambye994d462014-02-03 13:10:13 -08003145 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003146
Svet Ganovb320e182015-04-16 12:30:10 -07003147 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003149 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003150 return new String[0];
3151 }
3152
Malcolm Chenaabec062018-02-28 15:00:40 -08003153 final long identity = Binder.clearCallingIdentity();
3154 try {
3155 return mPhone.getPcscfAddress(apnType);
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
Wink Saville36469e72014-06-11 15:17:00 -07003159 }
3160
Brad Ebinger51f743a2017-01-23 13:50:20 -08003161 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003162 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3163 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003164 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003165 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003166 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003167
3168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 PhoneFactory.getImsResolver().enableIms(slotId);
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
3173 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003174 }
3175
3176 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003177 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3178 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003179 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003180 public void disableIms(int slotId) {
3181 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003182
3183 final long identity = Binder.clearCallingIdentity();
3184 try {
3185 PhoneFactory.getImsResolver().disableIms(slotId);
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003189 }
3190
3191 /**
3192 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3193 * feature or {@link null} if the service is not available. If the feature is available, the
3194 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3195 */
3196 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003197 IImsServiceFeatureCallback callback) {
3198 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003199
3200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003206 }
3207
3208 /**
3209 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3210 * feature during emergency calling or {@link null} if the service is not available. If the
3211 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3212 * listener for feature updates.
3213 */
3214 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3215 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003223 }
3224
Brad Ebinger5f64b052017-12-14 14:26:15 -08003225 /**
3226 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3227 * specified.
3228 */
3229 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3230 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003231
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003238 }
3239
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003240 /**
3241 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3242 * specified.
3243 */
3244 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3245 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003246
3247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003253 }
3254
Brad Ebinger884c07b2018-02-15 16:17:40 -08003255 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003256 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3257 * available, false if the IMS resolver is idle.
3258 */
3259 public boolean isResolvingImsBinding() {
3260 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003261
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 return PhoneFactory.getImsResolver().isResolvingBinding();
3265 } finally {
3266 Binder.restoreCallingIdentity(identity);
3267 }
Brad Ebinger67801702018-03-02 13:43:36 -08003268 }
3269
Brad Ebingerdac2f002018-04-03 15:17:52 -07003270 /**
3271 * Sets the ImsService Package Name that Telephony will bind to.
3272 *
3273 * @param slotId the slot ID that the ImsService should bind for.
3274 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3275 * ImsService is the device default ImsService.
3276 * @param packageName The package name of the application that contains the ImsService to bind
3277 * to.
3278 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3279 * @hide
3280 */
3281 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003282 int[] subIds = SubscriptionManager.getSubId(slotId);
3283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3284 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3285 "setImsService");
3286
Malcolm Chenaabec062018-02-28 15:00:40 -08003287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3290 isCarrierImsService, packageName);
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003294 }
3295
3296 /**
3297 * Return the ImsService configuration.
3298 *
3299 * @param slotId The slot that the ImsService is associated with.
3300 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3301 * the device default.
3302 * @return the package name of the ImsService configuration.
3303 */
3304 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003305 int[] subIds = SubscriptionManager.getSubId(slotId);
3306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3307 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3308 "getImsService");
3309
Malcolm Chenaabec062018-02-28 15:00:40 -08003310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3313 isCarrierImsService);
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003317 }
3318
Wink Saville36469e72014-06-11 15:17:00 -07003319 public void setImsRegistrationState(boolean registered) {
3320 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003321
3322 final long identity = Binder.clearCallingIdentity();
3323 try {
3324 mPhone.setImsRegistrationState(registered);
3325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
Wink Saville36469e72014-06-11 15:17:00 -07003328 }
3329
3330 /**
Stuart Scott54788802015-03-30 13:18:01 -07003331 * Set the network selection mode to automatic.
3332 *
3333 */
3334 @Override
3335 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3337 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003338
3339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3342 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
Stuart Scott54788802015-03-30 13:18:01 -07003346 }
3347
3348 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003349 * Set the network selection mode to manual with the selected carrier.
3350 */
3351 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003352 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003353 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3355 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003356
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003360 /* operatorAlphaLong */ "",
3361 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003362 operatorNumeric);
3363 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3364 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3365 persistSelection);
3366 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003370 }
3371
3372 /**
3373 * Scans for available networks.
3374 */
3375 @Override
3376 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3378 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003379
Pengquan Meng0c05b502018-09-06 09:59:22 -07003380 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003381 try {
3382 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003383 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003384 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003388 }
3389
3390 /**
yinxub1bed742017-04-17 11:45:04 -07003391 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003392 *
yinxub1bed742017-04-17 11:45:04 -07003393 * @param subId id of the subscription
3394 * @param request contains the radio access networks with bands/channels to scan
3395 * @param messenger callback messenger for scan results or errors
3396 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003397 * @return the id of the requested scan which can be used to stop the scan.
3398 */
3399 @Override
3400 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3401 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3403 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003404
3405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 return mNetworkScanRequestTracker.startNetworkScan(
3408 request, messenger, binder, getPhone(subId));
3409 } finally {
3410 Binder.restoreCallingIdentity(identity);
3411 }
yinxu504e1392017-04-12 16:03:22 -07003412 }
3413
3414 /**
3415 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003416 *
3417 * @param subId id of the subscription
3418 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003419 */
3420 @Override
3421 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3423 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003424
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
yinxu504e1392017-04-12 16:03:22 -07003431 }
3432
3433 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003434 * Get the calculated preferred network type.
3435 * Used for debugging incorrect network type.
3436 *
3437 * @return the preferred network type, defined in RILConstants.java.
3438 */
3439 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003440 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003442 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003443 return RILConstants.PREFERRED_NETWORK_MODE;
3444 }
3445
Malcolm Chenaabec062018-02-28 15:00:40 -08003446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 // FIXME: need to get SubId from somewhere.
3449 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
Junda Liu84d15a22014-07-02 11:21:04 -07003453 }
3454
3455 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003456 * Get the preferred network type.
3457 * Used for device configuration by some CDMA operators.
3458 *
3459 * @return the preferred network type, defined in RILConstants.java.
3460 */
3461 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003462 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3464 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003465
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 if (DBG) log("getPreferredNetworkType");
3469 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3470 int networkType = (result != null ? result[0] : -1);
3471 if (DBG) log("getPreferredNetworkType: " + networkType);
3472 return networkType;
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
3475 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003476 }
3477
3478 /**
3479 * Set the preferred network type.
3480 * Used for device configuration by some CDMA operators.
3481 *
3482 * @param networkType the preferred network type, defined in RILConstants.java.
3483 * @return true on success; false on any failure.
3484 */
3485 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003486 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3488 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003489
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3493 Boolean success = (Boolean) sendRequest(
3494 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3495 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3496 if (success) {
3497 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3498 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3499 }
3500 return success;
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003503 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003504 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003505
3506 /**
Junda Liu475951f2014-11-07 16:45:03 -08003507 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3508 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3509 * tethering.
3510 *
3511 * @return 0: Not required. 1: required. 2: Not set.
3512 * @hide
3513 */
3514 @Override
3515 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003516 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003517
3518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3521 Settings.Global.TETHER_DUN_REQUIRED, 2);
3522 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3523 // config_tether_apndata.
3524 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3525 dunRequired = 1;
3526 }
3527 return dunRequired;
3528 } finally {
3529 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003530 }
Junda Liu475951f2014-11-07 16:45:03 -08003531 }
3532
3533 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003534 * Set mobile data enabled
3535 * Used by the user through settings etc to turn on/off mobile data
3536 *
3537 * @param enable {@code true} turn turn data on, else {@code false}
3538 */
3539 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003540 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3542 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 int phoneId = mSubscriptionController.getPhoneId(subId);
3547 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3548 Phone phone = PhoneFactory.getPhone(phoneId);
3549 if (phone != null) {
3550 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3551 phone.setUserDataEnabled(enable);
3552 } else {
3553 loge("setUserDataEnabled: no phone for subId=" + subId);
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003557 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003558 }
3559
3560 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003561 * Get the user enabled state of Mobile Data.
3562 *
3563 * TODO: remove and use isUserDataEnabled.
3564 * This can't be removed now because some vendor codes
3565 * calls through ITelephony directly while they should
3566 * use TelephonyManager.
3567 *
3568 * @return true on enabled
3569 */
3570 @Override
3571 public boolean getDataEnabled(int subId) {
3572 return isUserDataEnabled(subId);
3573 }
3574
3575 /**
3576 * Get whether mobile data is enabled per user setting.
3577 *
3578 * There are other factors deciding whether mobile data is actually enabled, but they are
3579 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003580 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003581 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003582 *
3583 * @return {@code true} if data is enabled else {@code false}
3584 */
3585 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003586 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003587 try {
3588 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3589 null);
3590 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3592 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003593 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003594
3595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 int phoneId = mSubscriptionController.getPhoneId(subId);
3598 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3599 Phone phone = PhoneFactory.getPhone(phoneId);
3600 if (phone != null) {
3601 boolean retVal = phone.isUserDataEnabled();
3602 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3603 return retVal;
3604 } else {
3605 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3606 return false;
3607 }
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003610 }
3611 }
3612
3613 /**
3614 * Get whether mobile data is enabled.
3615 *
3616 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3617 * whether mobile data is actually enabled.
3618 *
3619 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3620 *
3621 * @return {@code true} if data is enabled else {@code false}
3622 */
3623 @Override
3624 public boolean isDataEnabled(int subId) {
3625 try {
3626 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3627 null);
3628 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3630 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003631 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003632
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 int phoneId = mSubscriptionController.getPhoneId(subId);
3636 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3637 Phone phone = PhoneFactory.getPhone(phoneId);
3638 if (phone != null) {
3639 boolean retVal = phone.isDataEnabled();
3640 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3641 return retVal;
3642 } else {
3643 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3644 return false;
3645 }
3646 } finally {
3647 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003648 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003649 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003650
3651 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003652 public int getCarrierPrivilegeStatus(int subId) {
3653 final Phone phone = getPhone(subId);
3654 if (phone == null) {
3655 loge("getCarrierPrivilegeStatus: Invalid subId");
3656 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3657 }
3658 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003659 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003660 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003661 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3662 }
3663 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003664 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003665 }
Junda Liu29340342014-07-10 15:23:27 -07003666
3667 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003668 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3669 final Phone phone = getPhone(subId);
3670 if (phone == null) {
3671 loge("getCarrierPrivilegeStatus: Invalid subId");
3672 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3673 }
3674 UiccProfile profile =
3675 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3676 if (profile == null) {
3677 loge("getCarrierPrivilegeStatus: No UICC");
3678 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3679 }
3680 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3681 }
3682
3683 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003684 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003685 if (TextUtils.isEmpty(pkgName))
3686 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003687 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003688 if (card == null) {
3689 loge("checkCarrierPrivilegesForPackage: No UICC");
3690 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3691 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003692 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3693 }
3694
3695 @Override
3696 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003697 if (TextUtils.isEmpty(pkgName))
3698 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003699 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3700 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3701 UiccCard card = UiccController.getInstance().getUiccCard(i);
3702 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003703 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003704 continue;
3705 }
3706
3707 result = card.getCarrierPrivilegeStatus(
3708 mPhone.getContext().getPackageManager(), pkgName);
3709 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3710 break;
3711 }
3712 }
3713
3714 return result;
Junda Liu29340342014-07-10 15:23:27 -07003715 }
Derek Tan89e89d42014-07-08 17:00:10 -07003716
3717 @Override
Junda Liue64de782015-04-16 17:19:16 -07003718 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3719 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3720 loge("phoneId " + phoneId + " is not valid.");
3721 return null;
3722 }
3723 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003724 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003725 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003726 return null ;
3727 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003728 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003729 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003730 }
3731
Amith Yamasani6e118872016-02-19 12:53:51 -08003732 @Override
3733 public List<String> getPackagesWithCarrierPrivileges() {
3734 PackageManager pm = mPhone.getContext().getPackageManager();
3735 List<String> privilegedPackages = new ArrayList<>();
3736 List<PackageInfo> packages = null;
3737 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3738 UiccCard card = UiccController.getInstance().getUiccCard(i);
3739 if (card == null) {
3740 // No UICC in that slot.
3741 continue;
3742 }
3743 if (card.hasCarrierPrivilegeRules()) {
3744 if (packages == null) {
3745 // Only check packages in user 0 for now
3746 packages = pm.getInstalledPackagesAsUser(
3747 PackageManager.MATCH_DISABLED_COMPONENTS
3748 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3749 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3750 }
3751 for (int p = packages.size() - 1; p >= 0; p--) {
3752 PackageInfo pkgInfo = packages.get(p);
3753 if (pkgInfo != null && pkgInfo.packageName != null
3754 && card.getCarrierPrivilegeStatus(pkgInfo)
3755 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3756 privilegedPackages.add(pkgInfo.packageName);
3757 }
3758 }
3759 }
3760 }
3761 return privilegedPackages;
3762 }
3763
Wink Savilleb564aae2014-10-23 10:18:09 -07003764 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003765 final Phone phone = getPhone(subId);
3766 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003767 if (card == null) {
3768 loge("getIccId: No UICC");
3769 return null;
3770 }
3771 String iccId = card.getIccId();
3772 if (TextUtils.isEmpty(iccId)) {
3773 loge("getIccId: ICC ID is null or empty.");
3774 return null;
3775 }
3776 return iccId;
3777 }
3778
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003779 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003780 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3781 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003782 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3783 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003784
Malcolm Chenaabec062018-02-28 15:00:40 -08003785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 final String iccId = getIccId(subId);
3788 final Phone phone = getPhone(subId);
3789 if (phone == null) {
3790 return false;
3791 }
3792 final String subscriberId = phone.getSubscriberId();
3793
3794 if (DBG_MERGE) {
3795 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3796 + subscriberId + " to " + number);
3797 }
3798
3799 if (TextUtils.isEmpty(iccId)) {
3800 return false;
3801 }
3802
3803 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3804
3805 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3806 if (alphaTag == null) {
3807 editor.remove(alphaTagPrefKey);
3808 } else {
3809 editor.putString(alphaTagPrefKey, alphaTag);
3810 }
3811
3812 // Record both the line number and IMSI for this ICCID, since we need to
3813 // track all merged IMSIs based on line number
3814 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3815 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3816 if (number == null) {
3817 editor.remove(numberPrefKey);
3818 editor.remove(subscriberPrefKey);
3819 } else {
3820 editor.putString(numberPrefKey, number);
3821 editor.putString(subscriberPrefKey, subscriberId);
3822 }
3823
3824 editor.commit();
3825 return true;
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003828 }
Derek Tan7226c842014-07-02 17:42:23 -07003829 }
3830
3831 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003832 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003833 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003835 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003836 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003837 return null;
3838 }
Derek Tan97ebb422014-09-05 16:55:38 -07003839
Malcolm Chenaabec062018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 String iccId = getIccId(subId);
3843 if (iccId != null) {
3844 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3845 if (DBG_MERGE) {
3846 log("getLine1NumberForDisplay returning "
3847 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3848 }
3849 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003850 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003851 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3852 return null;
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003855 }
Derek Tan7226c842014-07-02 17:42:23 -07003856 }
3857
3858 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003859 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003861 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003862 return null;
3863 }
Derek Tan97ebb422014-09-05 16:55:38 -07003864
Malcolm Chenaabec062018-02-28 15:00:40 -08003865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 String iccId = getIccId(subId);
3868 if (iccId != null) {
3869 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3870 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3871 }
3872 return null;
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003875 }
Derek Tan7226c842014-07-02 17:42:23 -07003876 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003877
3878 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003879 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003880 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3881 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003882 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003883 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3884 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003885 return null;
3886 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003887
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003888 final long identity = Binder.clearCallingIdentity();
3889 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003890 final Context context = mPhone.getContext();
3891 final TelephonyManager tele = TelephonyManager.from(context);
3892 final SubscriptionManager sub = SubscriptionManager.from(context);
3893
3894 // Figure out what subscribers are currently active
3895 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3896 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3897 // the process, where TelephonyManager was instantiated.
3898 // Otherwise AppOps check will fail.
3899
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003900 final int[] subIds = sub.getActiveSubscriptionIdList();
3901 for (int subId : subIds) {
3902 activeSubscriberIds.add(tele.getSubscriberId(subId));
3903 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003904
3905 // First pass, find a number override for an active subscriber
3906 String mergeNumber = null;
3907 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3908 for (String key : prefs.keySet()) {
3909 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3910 final String subscriberId = (String) prefs.get(key);
3911 if (activeSubscriberIds.contains(subscriberId)) {
3912 final String iccId = key.substring(
3913 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3914 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3915 mergeNumber = (String) prefs.get(numberKey);
3916 if (DBG_MERGE) {
3917 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3918 + " for active subscriber " + subscriberId);
3919 }
3920 if (!TextUtils.isEmpty(mergeNumber)) {
3921 break;
3922 }
3923 }
3924 }
3925 }
3926
3927 // Shortcut when no active merged subscribers
3928 if (TextUtils.isEmpty(mergeNumber)) {
3929 return null;
3930 }
3931
3932 // Second pass, find all subscribers under that line override
3933 final ArraySet<String> result = new ArraySet<>();
3934 for (String key : prefs.keySet()) {
3935 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3936 final String number = (String) prefs.get(key);
3937 if (mergeNumber.equals(number)) {
3938 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3939 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3940 final String subscriberId = (String) prefs.get(subscriberKey);
3941 if (!TextUtils.isEmpty(subscriberId)) {
3942 result.add(subscriberId);
3943 }
3944 }
3945 }
3946 }
3947
3948 final String[] resultArray = result.toArray(new String[result.size()]);
3949 Arrays.sort(resultArray);
3950 if (DBG_MERGE) {
3951 Slog.d(LOG_TAG,
3952 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3953 }
3954 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003955 } finally {
3956 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003957 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003958 }
3959
3960 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003961 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003962 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3963 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003964
3965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 final Phone phone = getPhone(subId);
3968 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
3971 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003972 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003973
3974 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003975 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003976 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3977 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003978 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003979
3980 final long identity = Binder.clearCallingIdentity();
3981 try {
3982 final Phone phone = getPhone(subId);
3983 if (phone == null) {
3984 return false;
3985 }
3986 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3987 cdmaNonRoamingList);
3988 } finally {
3989 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003990 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003991 }
3992
3993 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003994 @Deprecated
3995 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3996 enforceModifyPermission();
3997
3998 int returnValue = 0;
3999 try {
vagdevie435a3e2018-08-15 16:01:53 -07004000 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004001 if(result.exception == null) {
4002 if (result.result != null) {
4003 byte[] responseData = (byte[])(result.result);
4004 if(responseData.length > oemResp.length) {
4005 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4006 responseData.length + "bytes. Buffer Size is " +
4007 oemResp.length + "bytes.");
4008 }
4009 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4010 returnValue = responseData.length;
4011 }
4012 } else {
4013 CommandException ex = (CommandException) result.exception;
4014 returnValue = ex.getCommandError().ordinal();
4015 if(returnValue > 0) returnValue *= -1;
4016 }
4017 } catch (RuntimeException e) {
4018 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4019 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4020 if(returnValue > 0) returnValue *= -1;
4021 }
4022
4023 return returnValue;
4024 }
4025
4026 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004027 public void setRadioCapability(RadioAccessFamily[] rafs) {
4028 try {
4029 ProxyController.getInstance().setRadioCapability(rafs);
4030 } catch (RuntimeException e) {
4031 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4032 }
4033 }
4034
4035 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004036 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004037 Phone phone = PhoneFactory.getPhone(phoneId);
4038 if (phone == null) {
4039 return RadioAccessFamily.RAF_UNKNOWN;
4040 }
4041 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004043 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004044 return RadioAccessFamily.RAF_UNKNOWN;
4045 }
4046
Malcolm Chenaabec062018-02-28 15:00:40 -08004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004053 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004054
4055 @Override
4056 public void enableVideoCalling(boolean enable) {
4057 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004058
4059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4062 } finally {
4063 Binder.restoreCallingIdentity(identity);
4064 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004065 }
4066
4067 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004068 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4070 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4071 return false;
4072 }
Svet Ganovb320e182015-04-16 12:30:10 -07004073
Malcolm Chenaabec062018-02-28 15:00:40 -08004074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 // Check the user preference and the system-level IMS setting. Even if the user has
4077 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4078 // In the long run, we may instead need to check if there exists a connection service
4079 // which can support video calling.
4080 ImsManager imsManager =
4081 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4082 return imsManager.isVtEnabledByPlatform()
4083 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4084 && imsManager.isVtEnabledByUser();
4085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004088 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004089
Andrew Leea1239f22015-03-02 17:44:07 -08004090 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004091 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4093 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4094 return false;
4095 }
4096
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 CarrierConfigManager configManager =
4100 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4101 return configManager.getConfigForSubId(mPhone.getSubId())
4102 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
Andrew Leea1239f22015-03-02 17:44:07 -08004106 }
4107
4108 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004109 public boolean isWorldPhone(int subId, String callingPackage) {
4110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4111 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4112 return false;
4113 }
4114
4115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 CarrierConfigManager configManager =
4118 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4119 return configManager.getConfigForSubId(mPhone.getSubId())
4120 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
Andrew Leea1239f22015-03-02 17:44:07 -08004124 }
4125
Andrew Lee9431b832015-03-09 18:46:45 -07004126 @Override
4127 public boolean isTtyModeSupported() {
4128 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004129 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004130 }
4131
4132 @Override
4133 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
Andrew Lee9431b832015-03-09 18:46:45 -07004140 }
4141
Hall Liu98187582018-01-22 19:15:32 -08004142 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4146 mPhone.getSubId()).getBoolean(
4147 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4148 boolean isDeviceSupported =
4149 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4150 return isCarrierSupported && isDeviceSupported;
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
4153 }
Hall Liu98187582018-01-22 19:15:32 -08004154 }
4155
Hall Liu3ad5f012018-04-06 16:23:39 -07004156 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 return isRttSupported() && Settings.Secure.getInt(
4160 mPhone.getContext().getContentResolver(),
4161 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004165 }
4166
Sanket Padawe7310cc72015-01-14 09:53:20 -08004167 /**
4168 * Returns the unique device ID of phone, for example, the IMEI for
4169 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4170 *
4171 * <p>Requires Permission:
4172 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4173 */
4174 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004175 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004176 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004177 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004178 return null;
4179 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004180 int subId = phone.getSubId();
4181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4182 mApp, subId, callingPackage, "getDeviceId")) {
4183 return null;
4184 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004185
4186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 return phone.getDeviceId();
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004192 }
4193
Ping Sunc67b7c22016-03-02 19:16:45 +08004194 /**
4195 * {@hide}
4196 * Returns the IMS Registration Status on a particular subid
4197 *
4198 * @param subId
4199 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004200 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004201 Phone phone = getPhone(subId);
4202 if (phone != null) {
4203 return phone.isImsRegistered();
4204 } else {
4205 return false;
4206 }
4207 }
4208
Santos Cordon7a1885b2015-02-03 11:15:19 -08004209 @Override
4210 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
4213 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004217 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004218
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004219 /**
4220 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004221 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004222 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004223 final long identity = Binder.clearCallingIdentity();
4224 try {
4225 Phone phone = getPhone(subId);
4226 if (phone != null) {
4227 return phone.isWifiCallingEnabled();
4228 } else {
4229 return false;
4230 }
4231 } finally {
4232 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004233 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004234 }
4235
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004236 /**
4237 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004238 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004239 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 Phone phone = getPhone(subId);
4243 if (phone != null) {
4244 return phone.isVolteEnabled();
4245 } else {
4246 return false;
4247 }
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004250 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004251 }
Svet Ganovb320e182015-04-16 12:30:10 -07004252
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004253 /**
4254 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004255 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004256 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 Phone phone = getPhone(subId);
4260 if (phone != null) {
4261 return phone.isVideoEnabled();
4262 } else {
4263 return false;
4264 }
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004267 }
4268 }
4269
4270 /**
4271 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4272 * defined in {@link ImsRegistrationImplBase}.
4273 */
4274 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004275 final long identity = Binder.clearCallingIdentity();
4276 try {
4277 Phone phone = getPhone(subId);
4278 if (phone != null) {
4279 return phone.getImsRegistrationTech();
4280 } else {
4281 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4282 }
4283 } finally {
4284 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004285 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004286 }
4287
Stuart Scott8eef64f2015-04-08 15:13:54 -07004288 @Override
4289 public void factoryReset(int subId) {
4290 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004291 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4292 return;
4293 }
4294
Svet Ganovcc087f82015-05-12 20:35:54 -07004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004297 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4298 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004299 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004300 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004301 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4302 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004303 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004304 }
4305 } finally {
4306 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004307 }
4308 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004309
4310 @Override
4311 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 // We query all subscriptions instead of just the active ones, because
4315 // this might be called early on in the provisioning flow when the
4316 // subscriptions potentially aren't active yet.
4317 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4318 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004319 return null;
4320 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004321
Malcolm Chenaabec062018-02-28 15:00:40 -08004322 // This function may be called very early, say, from the setup wizard, at
4323 // which point we won't have a default subscription set. If that's the case
4324 // we just choose the first, which will be valid in "most cases".
4325 final int defaultSubId = getDefaultSubscription();
4326 SubscriptionInfo info = null;
4327 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4328 info = slist.get(0);
4329 } else {
4330 for (SubscriptionInfo item : slist) {
4331 if (item.getSubscriptionId() == defaultSubId) {
4332 info = item;
4333 break;
4334 }
4335 }
4336
4337 if (info == null) {
4338 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004339 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004340 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004341
Malcolm Chenaabec062018-02-28 15:00:40 -08004342 // Try and fetch the locale from the carrier properties or from the SIM language
4343 // preferences (EF-PL and EF-LI)...
4344 final int mcc = info.getMcc();
4345 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4346 String simLanguage = null;
4347 if (defaultPhone != null) {
4348 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4349 if (localeFromDefaultSim != null) {
4350 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4351 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4352 return localeFromDefaultSim.toLanguageTag();
4353 } else {
4354 simLanguage = localeFromDefaultSim.getLanguage();
4355 }
4356 }
4357 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004358
Malcolm Chenaabec062018-02-28 15:00:40 -08004359 // The SIM language preferences only store a language (e.g. fr = French), not an
4360 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4361 // the SIM and carrier preferences does not include a country we add the country
4362 // determined from the SIM MCC to provide an exact locale.
4363 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4364 simLanguage);
4365 if (mccLocale != null) {
4366 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4367 return mccLocale.toLanguageTag();
4368 }
4369
4370 if (DBG) log("No locale found - returning null");
4371 return null;
4372 } finally {
4373 Binder.restoreCallingIdentity(identity);
4374 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004375 }
4376
4377 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004378 return mSubscriptionController.getAllSubInfoList(
4379 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004380 }
4381
Malcolm Chenaabec062018-02-28 15:00:40 -08004382 /**
4383 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4384 */
4385 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4386 return mSubscriptionController.getActiveSubscriptionInfoList(
4387 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004388 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004389
Chenjie Yu1ba97252018-01-11 18:16:20 -08004390 private final ModemActivityInfo mLastModemActivityInfo =
4391 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4392
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004393 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004394 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4395 * representing the state of the modem.
4396 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004397 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4398 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004399 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004400 */
4401 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004402 public void requestModemActivityInfo(ResultReceiver result) {
4403 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004404 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004405 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004406
Malcolm Chenaabec062018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004409 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004410 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4411 CMD_GET_MODEM_ACTIVITY_INFO,
4412 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004413 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004414 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4415 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4416 mergedTxTimeMs[i] =
4417 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4418 }
4419 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4420 mLastModemActivityInfo.setSleepTimeMillis(
4421 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4422 mLastModemActivityInfo.setIdleTimeMillis(
4423 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4424 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4425 mLastModemActivityInfo.setRxTimeMillis(
4426 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4427 mLastModemActivityInfo.setEnergyUsed(
4428 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004429 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004430 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4431 mLastModemActivityInfo.getSleepTimeMillis(),
4432 mLastModemActivityInfo.getIdleTimeMillis(),
4433 mLastModemActivityInfo.getTxTimeMillis(),
4434 mLastModemActivityInfo.getRxTimeMillis(),
4435 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004436 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004437 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004438 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004439 result.send(0, bundle);
4440 } finally {
4441 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004442 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004443 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004444
Siddharth Rayc339f892018-06-17 15:02:38 -07004445 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4446 // less than total activity duration.
4447 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4448 if (info == null) {
4449 return false;
4450 }
4451 int activityDurationMs =
4452 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4453 int totalTxTimeMs = 0;
4454 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4455 totalTxTimeMs += info.getTxTimeMillis()[i];
4456 }
4457 return (info.isValid()
4458 && (info.getSleepTimeMillis() <= activityDurationMs)
4459 && (info.getIdleTimeMillis() <= activityDurationMs)
4460 && (info.getRxTimeMillis() <= activityDurationMs)
4461 && (totalTxTimeMs <= activityDurationMs));
4462 }
4463
Jack Yu85bd38a2015-11-09 11:34:32 -08004464 /**
4465 * {@hide}
4466 * Returns the service state information on specified subscription.
4467 */
4468 @Override
4469 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004471 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004472 return null;
4473 }
4474
Malcolm Chenaabec062018-02-28 15:00:40 -08004475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 final Phone phone = getPhone(subId);
4478 if (phone == null) {
4479 return null;
4480 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004481
Malcolm Chenaabec062018-02-28 15:00:40 -08004482 return phone.getServiceState();
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004486 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004487
4488 /**
4489 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4490 *
4491 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4492 * voicemail ringtone.
4493 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4494 * PhoneAccount.
4495 */
4496 @Override
4497 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004498 final long identity = Binder.clearCallingIdentity();
4499 try {
4500 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4501 if (phone == null) {
4502 phone = mPhone;
4503 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004504
Malcolm Chenaabec062018-02-28 15:00:40 -08004505 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004509 }
4510
4511 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004512 * Sets the per-account voicemail ringtone.
4513 *
4514 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4515 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4516 *
4517 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4518 * voicemail ringtone.
4519 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4520 * PhoneAccount.
4521 */
4522 @Override
4523 public void setVoicemailRingtoneUri(String callingPackage,
4524 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4526 if (!TextUtils.equals(callingPackage,
4527 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4529 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4530 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004531 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004532
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4536 if (phone == null) {
4537 phone = mPhone;
4538 }
4539 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4540 } finally {
4541 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004542 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004543 }
4544
4545 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004546 * Returns whether vibration is set for voicemail notification in Phone settings.
4547 *
4548 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4549 * voicemail vibration setting.
4550 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4551 */
4552 @Override
4553 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4557 if (phone == null) {
4558 phone = mPhone;
4559 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004560
Malcolm Chenaabec062018-02-28 15:00:40 -08004561 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4562 } finally {
4563 Binder.restoreCallingIdentity(identity);
4564 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004565 }
4566
Youhan Wange64578a2016-05-02 15:32:42 -07004567 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004568 * Sets the per-account voicemail vibration.
4569 *
4570 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4571 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4572 *
4573 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4574 * voicemail vibration setting.
4575 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4576 * specific PhoneAccount.
4577 */
4578 @Override
4579 public void setVoicemailVibrationEnabled(String callingPackage,
4580 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4582 if (!TextUtils.equals(callingPackage,
4583 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4585 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4586 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004587 }
4588
Malcolm Chenaabec062018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
4590 try {
4591 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4592 if (phone == null) {
4593 phone = mPhone;
4594 }
4595 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004598 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004599 }
4600
4601 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004602 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4603 *
4604 * @throws SecurityException if the caller does not have the required permission
4605 */
4606 private void enforceReadPrivilegedPermission() {
4607 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4608 null);
4609 }
4610
4611 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004612 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4613 * permission.
4614 *
4615 * @throws SecurityException if the caller does not have the required permission
4616 */
4617 private void enforceSendSmsPermission() {
4618 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4619 }
4620
4621 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004622 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004623 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004624 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004625 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004626 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004627 final long identity = Binder.clearCallingIdentity();
4628 try {
4629 ComponentName componentName =
4630 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4631 if (componentName == null) {
4632 throw new SecurityException(
4633 "Caller not current active visual voicemail package[null]");
4634 }
4635 String vvmPackage = componentName.getPackageName();
4636 if (!callingPackage.equals(vvmPackage)) {
4637 throw new SecurityException("Caller not current active visual voicemail package["
4638 + vvmPackage + "]");
4639 }
4640 } finally {
4641 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004642 }
4643 }
4644
4645 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004646 * Return the application ID for the app type.
4647 *
4648 * @param subId the subscription ID that this request applies to.
4649 * @param appType the uicc app type.
4650 * @return Application ID for specificied app type, or null if no uicc.
4651 */
4652 @Override
4653 public String getAidForAppType(int subId, int appType) {
4654 enforceReadPrivilegedPermission();
4655 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004656
4657 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004658 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004659 if (phone == null) {
4660 return null;
4661 }
4662 String aid = null;
4663 try {
4664 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4665 .getApplicationByType(appType).getAid();
4666 } catch (Exception e) {
4667 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4668 }
4669 return aid;
4670 } finally {
4671 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004672 }
Youhan Wange64578a2016-05-02 15:32:42 -07004673 }
4674
Youhan Wang4001d252016-05-11 10:29:41 -07004675 /**
4676 * Return the Electronic Serial Number.
4677 *
4678 * @param subId the subscription ID that this request applies to.
4679 * @return ESN or null if error.
4680 */
4681 @Override
4682 public String getEsn(int subId) {
4683 enforceReadPrivilegedPermission();
4684 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004687 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004688 if (phone == null) {
4689 return null;
4690 }
4691 String esn = null;
4692 try {
4693 esn = phone.getEsn();
4694 } catch (Exception e) {
4695 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4696 }
4697 return esn;
4698 } finally {
4699 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004700 }
Youhan Wang4001d252016-05-11 10:29:41 -07004701 }
4702
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004703 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004704 * Return the Preferred Roaming List Version.
4705 *
4706 * @param subId the subscription ID that this request applies to.
4707 * @return PRLVersion or null if error.
4708 */
4709 @Override
4710 public String getCdmaPrlVersion(int subId) {
4711 enforceReadPrivilegedPermission();
4712 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004713
4714 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004715 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004716 if (phone == null) {
4717 return null;
4718 }
4719 String cdmaPrlVersion = null;
4720 try {
4721 cdmaPrlVersion = phone.getCdmaPrlVersion();
4722 } catch (Exception e) {
4723 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4724 }
4725 return cdmaPrlVersion;
4726 } finally {
4727 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004728 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004729 }
4730
4731 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004732 * Get snapshot of Telephony histograms
4733 * @return List of Telephony histograms
4734 * @hide
4735 */
4736 @Override
4737 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4739 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004740
4741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 return RIL.getTelephonyRILTimingHistograms();
4744 } finally {
4745 Binder.restoreCallingIdentity(identity);
4746 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004747 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004748
4749 /**
4750 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004751 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004752 * Require system privileges. In the future we may add this to carrier APIs.
4753 *
4754 * @return The number of carriers set successfully, should match length of carriers
4755 */
4756 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004757 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004758 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004759 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004760
Meng Wang9b7c4e92017-02-17 11:41:27 -08004761 if (carriers == null) {
4762 throw new NullPointerException("carriers cannot be null");
4763 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004764
Malcolm Chenaabec062018-02-28 15:00:40 -08004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004768 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4769 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004770 return retVal[0];
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004774 }
4775
4776 /**
4777 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004778 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004779 * Require system privileges. In the future we may add this to carrier APIs.
4780 *
4781 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4782 * means all carriers are allowed.
4783 */
4784 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004785 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004786 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004787 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004788
4789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004792 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4793 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004797 }
4798
fionaxu59545b42016-05-25 15:53:37 -07004799 /**
4800 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4801 * @param subId the subscription ID that this action applies to.
4802 * @param enabled control enable or disable metered apns.
4803 * {@hide}
4804 */
4805 @Override
4806 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4807 enforceModifyPermission();
4808 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004809
4810 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004811 if (phone == null) {
4812 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4813 return;
4814 }
4815 try {
4816 phone.carrierActionSetMeteredApnsEnabled(enabled);
4817 } catch (Exception e) {
4818 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004819 } finally {
4820 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004821 }
4822 }
4823
4824 /**
4825 * Action set from carrier signalling broadcast receivers to enable/disable radio
4826 * @param subId the subscription ID that this action applies to.
4827 * @param enabled control enable or disable radio.
4828 * {@hide}
4829 */
4830 @Override
4831 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4832 enforceModifyPermission();
4833 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004834
4835 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004836 if (phone == null) {
4837 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4838 return;
4839 }
4840 try {
4841 phone.carrierActionSetRadioEnabled(enabled);
4842 } catch (Exception e) {
4843 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004844 } finally {
4845 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004846 }
4847 }
4848
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004849 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004850 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4851 * network status based on which carrier apps could apply actions accordingly,
4852 * enable/disable default url handler for example.
4853 *
4854 * @param subId the subscription ID that this action applies to.
4855 * @param report control start/stop reporting the default network status.
4856 * {@hide}
4857 */
4858 @Override
4859 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4860 enforceModifyPermission();
4861 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004862
4863 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004864 if (phone == null) {
4865 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4866 return;
4867 }
4868 try {
4869 phone.carrierActionReportDefaultNetworkStatus(report);
4870 } catch (Exception e) {
4871 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004872 } finally {
4873 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004874 }
4875 }
4876
4877 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004878 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4879 * bug report is being generated.
4880 */
4881 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004882 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004883 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4884 != PackageManager.PERMISSION_GRANTED) {
4885 writer.println("Permission Denial: can't dump Phone from pid="
4886 + Binder.getCallingPid()
4887 + ", uid=" + Binder.getCallingUid()
4888 + "without permission "
4889 + android.Manifest.permission.DUMP);
4890 return;
4891 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004892 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004893 }
Jack Yueb89b242016-06-22 13:27:47 -07004894
Brad Ebingerdac2f002018-04-03 15:17:52 -07004895 @Override
4896 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4897 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4898 throws RemoteException {
4899 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4900 }
4901
Jack Yueb89b242016-06-22 13:27:47 -07004902 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004903 * Get aggregated video call data usage since boot.
4904 *
4905 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4906 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004907 * {@hide}
4908 */
4909 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004910 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004911 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4912 null);
4913
Malcolm Chenaabec062018-02-28 15:00:40 -08004914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 // NetworkStatsService keeps tracking the active network interface and identity. It
4917 // records the delta with the corresponding network identity.
4918 // We just return the total video call data usage snapshot since boot.
4919 Phone phone = getPhone(subId);
4920 if (phone != null) {
4921 return phone.getVtDataUsage(perUidStats);
4922 }
4923 return null;
4924 } finally {
4925 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004926 }
Jack Yueb89b242016-06-22 13:27:47 -07004927 }
Jack Yu75ab2952016-07-08 14:29:33 -07004928
4929 /**
4930 * Policy control of data connection. Usually used when data limit is passed.
4931 * @param enabled True if enabling the data, otherwise disabling.
4932 * @param subId Subscription index
4933 * {@hide}
4934 */
4935 @Override
4936 public void setPolicyDataEnabled(boolean enabled, int subId) {
4937 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004938
4939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 Phone phone = getPhone(subId);
4942 if (phone != null) {
4943 phone.setPolicyDataEnabled(enabled);
4944 }
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004947 }
4948 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004949
4950 /**
4951 * Get Client request stats
4952 * @return List of Client Request Stats
4953 * @hide
4954 */
4955 @Override
4956 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004958 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004959 return null;
4960 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004961 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004962
Malcolm Chenaabec062018-02-28 15:00:40 -08004963 final long identity = Binder.clearCallingIdentity();
4964 try {
4965 if (phone != null) {
4966 return phone.getClientRequestStats();
4967 }
4968
4969 return null;
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004973 }
4974
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004975 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004976 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004977 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004978 }
Jack Yueb4124c2017-02-16 15:32:43 -08004979
4980 /**
Grace Chen70990072017-03-24 17:21:30 -07004981 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004982 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004983 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004984 * @param state State of SIM (power down, power up, pass through)
4985 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4986 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4987 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004988 *
4989 **/
4990 @Override
Grace Chen70990072017-03-24 17:21:30 -07004991 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004992 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004993 Phone phone = PhoneFactory.getPhone(slotIndex);
4994
vagdevie435a3e2018-08-15 16:01:53 -07004995 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4996
Malcolm Chenaabec062018-02-28 15:00:40 -08004997 final long identity = Binder.clearCallingIdentity();
4998 try {
4999 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005000 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08005001 }
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005004 }
5005 }
Shuo Qiandd210312017-04-12 22:11:33 +00005006
Tyler Gunn65d45c22017-06-05 11:22:26 -07005007 private boolean isUssdApiAllowed(int subId) {
5008 CarrierConfigManager configManager =
5009 (CarrierConfigManager) mPhone.getContext().getSystemService(
5010 Context.CARRIER_CONFIG_SERVICE);
5011 if (configManager == null) {
5012 return false;
5013 }
5014 PersistableBundle pb = configManager.getConfigForSubId(subId);
5015 if (pb == null) {
5016 return false;
5017 }
5018 return pb.getBoolean(
5019 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5020 }
5021
Shuo Qiandd210312017-04-12 22:11:33 +00005022 /**
5023 * Check if phone is in emergency callback mode
5024 * @return true if phone is in emergency callback mode
5025 * @param subId sub id
5026 */
goneil9c5f4872017-12-05 14:07:56 -08005027 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005028 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08005029 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00005030 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08005031
5032 final long identity = Binder.clearCallingIdentity();
5033 try {
5034 if (phone != null) {
5035 return phone.isInEcm();
5036 } else {
5037 return false;
5038 }
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005041 }
5042 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005043
5044 /**
5045 * Get the current signal strength information for the given subscription.
5046 * Because this information is not updated when the device is in a low power state
5047 * it should not be relied-upon to be current.
5048 * @param subId Subscription index
5049 * @return the most recent cached signal strength info from the modem
5050 */
5051 @Override
5052 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
5055 Phone p = getPhone(subId);
5056 if (p == null) {
5057 return null;
5058 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005059
Malcolm Chenaabec062018-02-28 15:00:40 -08005060 return p.getSignalStrength();
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
5063 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005064 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005065
Pengquan Meng9140aec2018-08-22 14:49:57 -07005066 /**
5067 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5068 *
5069 * <p>Requires one of the following permissions:
5070 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5071 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5072 * privileges.
5073 *
5074 * @param subId subscription id
5075 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5076 * {@code false}.
5077 */
5078 @Override
5079 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005080 boolean isEnabled = false;
5081 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005082 try {
5083 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005084 null /* message */);
5085 Phone phone = getPhone(subId);
5086 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005087 } catch (Exception e) {
5088 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5089 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005092 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005093 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005094 }
5095
5096
5097 /**
5098 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5099 *
5100 * <p> Requires permission:
5101 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5102 * privileges.
5103 *
5104 * @param subId subscription id
5105 * @param isEnabled {@code true} means enable, {@code false} means disable.
5106 */
5107 @Override
5108 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5112 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005113
Pengquan Meng0c05b502018-09-06 09:59:22 -07005114 Phone phone = getPhone(subId);
5115 if (phone != null) {
5116 phone.setDataRoamingEnabled(isEnabled);
5117 }
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005120 }
5121 }
5122
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005123 @Override
5124 public UiccSlotInfo[] getUiccSlotsInfo() {
5125 enforceReadPrivilegedPermission();
5126
Malcolm Chenaabec062018-02-28 15:00:40 -08005127 final long identity = Binder.clearCallingIdentity();
5128 try {
5129 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005130 if (slots == null) {
5131 Rlog.i(LOG_TAG, "slots is null.");
5132 return null;
5133 }
5134
Malcolm Chenaabec062018-02-28 15:00:40 -08005135 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5136 for (int i = 0; i < slots.length; i++) {
5137 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005138 if (slot == null) {
5139 continue;
5140 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005141
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005142 String cardId;
5143 UiccCard card = slot.getUiccCard();
5144 if (card != null) {
5145 cardId = card.getCardId();
5146 } else {
5147 cardId = slot.getIccId();
5148 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005149
Malcolm Chenaabec062018-02-28 15:00:40 -08005150 int cardState = 0;
5151 switch (slot.getCardState()) {
5152 case CARDSTATE_ABSENT:
5153 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5154 break;
5155 case CARDSTATE_PRESENT:
5156 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5157 break;
5158 case CARDSTATE_ERROR:
5159 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5160 break;
5161 case CARDSTATE_RESTRICTED:
5162 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5163 break;
5164 default:
5165 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005166
Malcolm Chenaabec062018-02-28 15:00:40 -08005167 }
5168
5169 infos[i] = new UiccSlotInfo(
5170 slot.isActive(),
5171 slot.isEuicc(),
5172 cardId,
5173 cardState,
5174 slot.getPhoneId(),
5175 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005176 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005177 return infos;
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005180 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005181 }
5182
5183 @Override
5184 public boolean switchSlots(int[] physicalSlots) {
5185 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005186
5187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005193 }
Jack Yu4c988042018-02-27 15:30:01 -08005194
5195 @Override
5196 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5197 enforceModifyPermission();
5198 final Phone phone = getPhone(subId);
5199 if (phone == null) {
5200 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5201 return;
5202 }
5203
Malcolm Chenaabec062018-02-28 15:00:40 -08005204 final long identity = Binder.clearCallingIdentity();
5205 try {
5206 phone.setRadioIndicationUpdateMode(filters, mode);
5207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
Jack Yu4c988042018-02-27 15:30:01 -08005210 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005211
5212 /**
goneil47ffb6e2018-04-06 15:40:58 -07005213 * A test API to reload the UICC profile.
5214 *
5215 * <p>Requires that the calling app has permission
5216 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5217 * @hide
5218 */
5219 @Override
5220 public void refreshUiccProfile(int subId) {
5221 enforceModifyPermission();
5222
5223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 Phone phone = getPhone(subId);
5226 if (phone == null) {
5227 return;
5228 }
5229 UiccCard uiccCard = phone.getUiccCard();
5230 if (uiccCard == null) {
5231 return;
5232 }
5233 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5234 if (uiccProfile == null) {
5235 return;
5236 }
5237 uiccProfile.refresh();
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
5241 }
5242
5243 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005244 * Returns false if the mobile data is disabled by default, otherwise return true.
5245 */
5246 private boolean getDefaultDataEnabled() {
5247 return "true".equalsIgnoreCase(
5248 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5249 }
5250
5251 /**
5252 * Returns true if the data roaming is enabled by default, i.e the system property
5253 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5254 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5255 */
5256 private boolean getDefaultDataRoamingEnabled(int subId) {
5257 final CarrierConfigManager configMgr = (CarrierConfigManager)
5258 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5259 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5260 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5261 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5262 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5263 return isDataRoamingEnabled;
5264 }
5265
5266 /**
5267 * Returns the default network type for the given {@code subId}, if the default network type is
5268 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5269 */
5270 private int getDefaultNetworkType(int subId) {
5271 return Integer.parseInt(
5272 TelephonyManager.getTelephonyProperty(
5273 mSubscriptionController.getPhoneId(subId),
5274 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5275 String.valueOf(Phone.PREFERRED_NT_MODE)));
5276 }
fionaxua13278b2018-03-21 00:08:13 -07005277
5278 @Override
5279 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5280 gid1, String gid2, String plmn, String spn) {
5281 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005282
5283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 final Phone phone = getPhone(subId);
5286 if (phone == null) {
5287 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5288 return;
5289 }
5290 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005293 }
fionaxua13278b2018-03-21 00:08:13 -07005294 }
5295
5296 @Override
5297 public int getCarrierIdListVersion(int subId) {
5298 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 final Phone phone = getPhone(subId);
5303 if (phone == null) {
5304 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5305 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5306 }
5307 return phone.getCarrierIdListVersion();
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005310 }
fionaxua13278b2018-03-21 00:08:13 -07005311 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005312
5313 @Override
5314 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5316 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5317 return -1;
5318 }
5319
5320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005327
5328 @Override
5329 public int getCdmaRoamingMode(int subId) {
5330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5331 mApp, subId, "getCdmaRoamingMode");
5332
5333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
5339 }
5340
5341 @Override
5342 public boolean setCdmaRoamingMode(int subId, int mode) {
5343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5344 mApp, subId, "setCdmaRoamingMode");
5345
5346 final long identity = Binder.clearCallingIdentity();
5347 try {
5348 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
5352 }
5353
5354 @Override
5355 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5357 mApp, subId, "setCdmaSubscriptionMode");
5358
5359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
5365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005366}