blob: 33b83afe9f12f01fb41e760417314975aacdbca9 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080086import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080088
Andrew Lee312e8172014-10-23 17:01:36 -070089import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080090import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070091import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070092import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070093import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070094import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070095import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080098import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -070099import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100100import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700101import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700102import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700104import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800105import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700106import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700107import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700108import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700109import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700110import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700111import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800112import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800113import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700114import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.uicc.IccIoResult;
116import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800117import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700118import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800119import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800121import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000122import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700123import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800124import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700125import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800126import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700127import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700128import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800129
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700130import java.io.FileDescriptor;
131import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800132import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800134import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800135import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100136import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138
139/**
140 * Implementation of the ITelephony interface.
141 */
Santos Cordon117fee72014-05-16 17:56:12 -0700142public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143 private static final String LOG_TAG = "PhoneInterfaceManager";
144 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
145 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800146 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147
148 // Message codes used with mMainThreadHandler
149 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700150 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
151 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152 private static final int CMD_OPEN_CHANNEL = 9;
153 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
154 private static final int CMD_CLOSE_CHANNEL = 11;
155 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800156 private static final int CMD_NV_READ_ITEM = 13;
157 private static final int EVENT_NV_READ_ITEM_DONE = 14;
158 private static final int CMD_NV_WRITE_ITEM = 15;
159 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
160 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
161 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
162 private static final int CMD_NV_RESET_CONFIG = 19;
163 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800164 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
165 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
166 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
167 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800168 private static final int CMD_SEND_ENVELOPE = 25;
169 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000170 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
171 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700172 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
173 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
174 private static final int CMD_EXCHANGE_SIM_IO = 31;
175 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800176 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
177 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700178 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
179 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700180 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
181 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700182 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
183 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
184 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
185 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700186 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
187 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
188 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
189 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700190 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800191 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
192 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193 private static final int CMD_SWITCH_SLOTS = 50;
194 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700195 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
196 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
197 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
198 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
199 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
200 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
201 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
202 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800204 // Parameters of select command.
205 private static final int SELECT_COMMAND = 0xA4;
206 private static final int SELECT_P1 = 0x04;
207 private static final int SELECT_P2 = 0;
208 private static final int SELECT_P3 = 0x10;
209
Pengquan Meng85728fb2018-03-12 16:31:21 -0700210 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
211 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
212 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
213
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214 /** The singleton instance. */
215 private static PhoneInterfaceManager sInstance;
216
Wink Saville3ab207e2014-11-20 13:07:20 -0800217 private PhoneGlobals mApp;
218 private Phone mPhone;
219 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700220 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800221 private AppOpsManager mAppOps;
222 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800223 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800224 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700225 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
Derek Tan97ebb422014-09-05 16:55:38 -0700227 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
228 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700230
Derek Tan740e1672017-06-27 14:56:27 -0700231 // The AID of ISD-R.
232 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
233
yinxub1bed742017-04-17 11:45:04 -0700234 private NetworkScanRequestTracker mNetworkScanRequestTracker;
235
David Kelly5e06a7f2018-03-12 14:10:59 +0000236 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
237 private static final int MANUFACTURER_CODE_LENGTH = 8;
238
Derek Tan89e89d42014-07-08 17:00:10 -0700239 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700240 * A request object to use for transmitting data to an ICC.
241 */
242 private static final class IccAPDUArgument {
243 public int channel, cla, command, p1, p2, p3;
244 public String data;
245
246 public IccAPDUArgument(int channel, int cla, int command,
247 int p1, int p2, int p3, String data) {
248 this.channel = channel;
249 this.cla = cla;
250 this.command = command;
251 this.p1 = p1;
252 this.p2 = p2;
253 this.p3 = p3;
254 this.data = data;
255 }
256 }
257
258 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700259 * A request object to use for transmitting data to an ICC.
260 */
261 private static final class ManualNetworkSelectionArgument {
262 public OperatorInfo operatorInfo;
263 public boolean persistSelection;
264
265 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
266 this.operatorInfo = operatorInfo;
267 this.persistSelection = persistSelection;
268 }
269 }
270
271 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
273 * request after sending. The main thread will notify the request when it is complete.
274 */
275 private static final class MainThreadRequest {
276 /** The argument to use for the request */
277 public Object argument;
278 /** The result of the request that is run on the main thread */
279 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800280 // The subscriber id that this request applies to. Defaults to
281 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
282 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283
vagdevie435a3e2018-08-15 16:01:53 -0700284 public WorkSource workSource;
285
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 public MainThreadRequest(Object argument) {
287 this.argument = argument;
288 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800289
vagdevie435a3e2018-08-15 16:01:53 -0700290 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800291 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800292 if (subId != null) {
293 this.subId = subId;
294 }
vagdevie435a3e2018-08-15 16:01:53 -0700295 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 }
298
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800299 private static final class IncomingThirdPartyCallArgs {
300 public final ComponentName component;
301 public final String callId;
302 public final String callerDisplayName;
303
304 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
305 String callerDisplayName) {
306 this.component = component;
307 this.callId = callId;
308 this.callerDisplayName = callerDisplayName;
309 }
310 }
311
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 /**
313 * A handler that processes messages on the main thread in the phone process. Since many
314 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
315 * inbound binder threads to the main thread in the phone process. The Binder thread
316 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
317 * on, which will be notified when the operation completes and will contain the result of the
318 * request.
319 *
320 * <p>If a MainThreadRequest object is provided in the msg.obj field,
321 * note that request.result must be set to something non-null for the calling thread to
322 * unblock.
323 */
324 private final class MainThreadHandler extends Handler {
325 @Override
326 public void handleMessage(Message msg) {
327 MainThreadRequest request;
328 Message onCompleted;
329 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800330 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700331 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
333 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700334 case CMD_HANDLE_USSD_REQUEST: {
335 request = (MainThreadRequest) msg.obj;
336 final Phone phone = getPhoneFromRequest(request);
337 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
338 String ussdRequest = ussdObject.first;
339 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700340
Pengquan Meng0c05b502018-09-06 09:59:22 -0700341 if (!isUssdApiAllowed(request.subId)) {
342 // Carrier does not support use of this API, return failure.
343 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
344 UssdResponse response = new UssdResponse(ussdRequest, null);
345 Bundle returnData = new Bundle();
346 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
347 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700348
Pengquan Meng0c05b502018-09-06 09:59:22 -0700349 request.result = true;
350 notifyRequester(request);
351 return;
352 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700353
Pengquan Meng0c05b502018-09-06 09:59:22 -0700354 try {
355 request.result = phone != null
356 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
357 } catch (CallStateException cse) {
358 request.result = false;
359 }
360 // Wake up the requesting thread
361 notifyRequester(request);
362 break;
pkanwar32d516d2016-10-14 19:37:38 -0700363 }
364
Yorke Lee716f67e2015-06-17 15:39:16 -0700365 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700367 final Phone phone = getPhoneFromRequest(request);
368 request.result = phone != null ?
369 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
370 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700372 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700376 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700377 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700378 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800379 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700380 if (uiccCard == null) {
381 loge("iccTransmitApduLogicalChannel: No UICC");
382 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700383 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700384 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700385 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
386 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700387 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700388 iccArgument.channel, iccArgument.cla, iccArgument.command,
389 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700390 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700391 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700392 break;
393
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700394 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700395 ar = (AsyncResult) msg.obj;
396 request = (MainThreadRequest) ar.userObj;
397 if (ar.exception == null && ar.result != null) {
398 request.result = ar.result;
399 } else {
400 request.result = new IccIoResult(0x6F, 0, (byte[])null);
401 if (ar.result == null) {
402 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800403 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700404 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800405 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700406 } else {
407 loge("iccTransmitApduLogicalChannel: Unknown exception");
408 }
409 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700410 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700411 break;
412
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
414 request = (MainThreadRequest) msg.obj;
415 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800416 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 if (uiccCard == null) {
418 loge("iccTransmitApduBasicChannel: No UICC");
419 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700420 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 } else {
422 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
423 request);
424 uiccCard.iccTransmitApduBasicChannel(
425 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
426 iccArgument.p3, iccArgument.data, onCompleted);
427 }
428 break;
429
430 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
431 ar = (AsyncResult) msg.obj;
432 request = (MainThreadRequest) ar.userObj;
433 if (ar.exception == null && ar.result != null) {
434 request.result = ar.result;
435 } else {
436 request.result = new IccIoResult(0x6F, 0, (byte[])null);
437 if (ar.result == null) {
438 loge("iccTransmitApduBasicChannel: Empty response");
439 } else if (ar.exception instanceof CommandException) {
440 loge("iccTransmitApduBasicChannel: CommandException: " +
441 ar.exception);
442 } else {
443 loge("iccTransmitApduBasicChannel: Unknown exception");
444 }
445 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700446 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 break;
448
449 case CMD_EXCHANGE_SIM_IO:
450 request = (MainThreadRequest) msg.obj;
451 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800452 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 if (uiccCard == null) {
454 loge("iccExchangeSimIO: No UICC");
455 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 } else {
458 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
459 request);
460 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
461 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
462 iccArgument.data, onCompleted);
463 }
464 break;
465
466 case EVENT_EXCHANGE_SIM_IO_DONE:
467 ar = (AsyncResult) msg.obj;
468 request = (MainThreadRequest) ar.userObj;
469 if (ar.exception == null && ar.result != null) {
470 request.result = ar.result;
471 } else {
472 request.result = new IccIoResult(0x6f, 0, (byte[])null);
473 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700474 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 break;
476
Derek Tan4d5e5c12014-02-04 11:54:58 -0800477 case CMD_SEND_ENVELOPE:
478 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800479 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700480 if (uiccCard == null) {
481 loge("sendEnvelopeWithStatus: No UICC");
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700483 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700484 } else {
485 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
486 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
487 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800488 break;
489
490 case EVENT_SEND_ENVELOPE_DONE:
491 ar = (AsyncResult) msg.obj;
492 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700493 if (ar.exception == null && ar.result != null) {
494 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800495 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700496 request.result = new IccIoResult(0x6F, 0, (byte[])null);
497 if (ar.result == null) {
498 loge("sendEnvelopeWithStatus: Empty response");
499 } else if (ar.exception instanceof CommandException) {
500 loge("sendEnvelopeWithStatus: CommandException: " +
501 ar.exception);
502 } else {
503 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
504 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800505 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700506 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800507 break;
508
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 case CMD_OPEN_CHANNEL:
510 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800511 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800512 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700513 if (uiccCard == null) {
514 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800515 request.result = new IccOpenLogicalChannelResponse(-1,
516 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 } else {
519 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800520 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
521 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 break;
524
525 case EVENT_OPEN_CHANNEL_DONE:
526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700529 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 int[] result = (int[]) ar.result;
531 int channelId = result[0];
532 byte[] selectResponse = null;
533 if (result.length > 1) {
534 selectResponse = new byte[result.length - 1];
535 for (int i = 1; i < result.length; ++i) {
536 selectResponse[i - 1] = (byte) result[i];
537 }
538 }
539 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700540 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 if (ar.result == null) {
543 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 if (ar.exception != null) {
546 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
547 }
548
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700549 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700550 if (ar.exception instanceof CommandException) {
551 CommandException.Error error =
552 ((CommandException) (ar.exception)).getCommandError();
553 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700554 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700555 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700556 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 }
558 }
559 openChannelResp = new IccOpenLogicalChannelResponse(
560 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700562 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
566 case CMD_CLOSE_CHANNEL:
567 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800568 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 if (uiccCard == null) {
570 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900571 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700572 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700573 } else {
574 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
575 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
576 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 break;
578
579 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800580 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
581 break;
582
583 case CMD_NV_READ_ITEM:
584 request = (MainThreadRequest) msg.obj;
585 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700586 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800587 break;
588
589 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800592 if (ar.exception == null && ar.result != null) {
593 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800595 request.result = "";
596 if (ar.result == null) {
597 loge("nvReadItem: Empty response");
598 } else if (ar.exception instanceof CommandException) {
599 loge("nvReadItem: CommandException: " +
600 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800602 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
604 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
Jake Hambye994d462014-02-03 13:10:13 -0800608 case CMD_NV_WRITE_ITEM:
609 request = (MainThreadRequest) msg.obj;
610 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
611 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700612 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
613 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800614 break;
615
616 case EVENT_NV_WRITE_ITEM_DONE:
617 handleNullReturnEvent(msg, "nvWriteItem");
618 break;
619
620 case CMD_NV_WRITE_CDMA_PRL:
621 request = (MainThreadRequest) msg.obj;
622 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
623 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
624 break;
625
626 case EVENT_NV_WRITE_CDMA_PRL_DONE:
627 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
628 break;
629
630 case CMD_NV_RESET_CONFIG:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
633 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
634 break;
635
636 case EVENT_NV_RESET_CONFIG_DONE:
637 handleNullReturnEvent(msg, "nvResetConfig");
638 break;
639
Jake Hamby7c27be32014-03-03 13:25:59 -0800640 case CMD_GET_PREFERRED_NETWORK_TYPE:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700643 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800644 break;
645
646 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result; // Integer
651 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800652 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800653 if (ar.result == null) {
654 loge("getPreferredNetworkType: Empty response");
655 } else if (ar.exception instanceof CommandException) {
656 loge("getPreferredNetworkType: CommandException: " +
657 ar.exception);
658 } else {
659 loge("getPreferredNetworkType: Unknown exception");
660 }
661 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700662 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800663 break;
664
665 case CMD_SET_PREFERRED_NETWORK_TYPE:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
668 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700669 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800670 break;
671
672 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
673 handleNullReturnEvent(msg, "setPreferredNetworkType");
674 break;
675
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000676 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
677 request = (MainThreadRequest)msg.obj;
678 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700679 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000680 break;
681
682 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
683 ar = (AsyncResult)msg.obj;
684 request = (MainThreadRequest)ar.userObj;
685 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700686 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000687 break;
688
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800689 case CMD_SET_VOICEMAIL_NUMBER:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
692 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800693 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
694 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800695 break;
696
697 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
698 handleNullReturnEvent(msg, "setVoicemailNumber");
699 break;
700
Stuart Scott54788802015-03-30 13:18:01 -0700701 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
704 request);
705 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
706 break;
707
708 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
709 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
710 break;
711
Shishir Agrawal302c8692015-06-19 13:49:39 -0700712 case CMD_PERFORM_NETWORK_SCAN:
713 request = (MainThreadRequest) msg.obj;
714 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
715 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
716 break;
717
718 case EVENT_PERFORM_NETWORK_SCAN_DONE:
719 ar = (AsyncResult) msg.obj;
720 request = (MainThreadRequest) ar.userObj;
721 CellNetworkScanResult cellScanResult;
722 if (ar.exception == null && ar.result != null) {
723 cellScanResult = new CellNetworkScanResult(
724 CellNetworkScanResult.STATUS_SUCCESS,
725 (List<OperatorInfo>) ar.result);
726 } else {
727 if (ar.result == null) {
728 loge("getCellNetworkScanResults: Empty response");
729 }
730 if (ar.exception != null) {
731 loge("getCellNetworkScanResults: Exception: " + ar.exception);
732 }
733 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
734 if (ar.exception instanceof CommandException) {
735 CommandException.Error error =
736 ((CommandException) (ar.exception)).getCommandError();
737 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
738 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
739 } else if (error == CommandException.Error.GENERIC_FAILURE) {
740 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
741 }
742 }
743 cellScanResult = new CellNetworkScanResult(errorCode, null);
744 }
745 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700746 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700747 break;
748
749 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
750 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700751 ManualNetworkSelectionArgument selArg =
752 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700753 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
754 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700755 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
756 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700757 break;
758
759 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
760 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
761 break;
762
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700763 case CMD_GET_MODEM_ACTIVITY_INFO:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700766 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700767 break;
768
769 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
772 if (ar.exception == null && ar.result != null) {
773 request.result = ar.result;
774 } else {
775 if (ar.result == null) {
776 loge("queryModemActivityInfo: Empty response");
777 } else if (ar.exception instanceof CommandException) {
778 loge("queryModemActivityInfo: CommandException: " +
779 ar.exception);
780 } else {
781 loge("queryModemActivityInfo: Unknown exception");
782 }
783 }
Amit Mahajand4766222016-01-28 15:28:28 -0800784 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
785 if (request.result == null) {
786 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
787 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700788 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700789 break;
790
Meng Wang1a7c35a2016-05-05 20:56:15 -0700791 case CMD_SET_ALLOWED_CARRIERS:
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
794 mPhone.setAllowedCarriers(
795 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700796 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700797 break;
798
799 case EVENT_SET_ALLOWED_CARRIERS_DONE:
800 ar = (AsyncResult) msg.obj;
801 request = (MainThreadRequest) ar.userObj;
802 if (ar.exception == null && ar.result != null) {
803 request.result = ar.result;
804 } else {
805 if (ar.result == null) {
806 loge("setAllowedCarriers: Empty response");
807 } else if (ar.exception instanceof CommandException) {
808 loge("setAllowedCarriers: CommandException: " +
809 ar.exception);
810 } else {
811 loge("setAllowedCarriers: Unknown exception");
812 }
813 }
814 // Result cannot be null. Return -1 on error.
815 if (request.result == null) {
816 request.result = new int[]{-1};
817 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700818 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700819 break;
820
821 case CMD_GET_ALLOWED_CARRIERS:
822 request = (MainThreadRequest) msg.obj;
823 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700824 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700825 break;
826
827 case EVENT_GET_ALLOWED_CARRIERS_DONE:
828 ar = (AsyncResult) msg.obj;
829 request = (MainThreadRequest) ar.userObj;
830 if (ar.exception == null && ar.result != null) {
831 request.result = ar.result;
832 } else {
833 if (ar.result == null) {
834 loge("getAllowedCarriers: Empty response");
835 } else if (ar.exception instanceof CommandException) {
836 loge("getAllowedCarriers: CommandException: " +
837 ar.exception);
838 } else {
839 loge("getAllowedCarriers: Unknown exception");
840 }
841 }
842 // Result cannot be null. Return empty list of CarrierIdentifier.
843 if (request.result == null) {
844 request.result = new ArrayList<CarrierIdentifier>(0);
845 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700846 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 break;
848
Nathan Haroldb3014052017-01-25 15:57:32 -0800849 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 request.result = new IllegalArgumentException(
856 "Failed to retrieve Forbidden Plmns");
857 if (ar.result == null) {
858 loge("getForbiddenPlmns: Empty response");
859 } else {
860 loge("getForbiddenPlmns: Unknown exception");
861 }
862 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700863 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800864 break;
865
866 case CMD_GET_FORBIDDEN_PLMNS:
867 request = (MainThreadRequest) msg.obj;
868 uiccCard = getUiccCardFromRequest(request);
869 if (uiccCard == null) {
870 loge("getForbiddenPlmns() UiccCard is null");
871 request.result = new IllegalArgumentException(
872 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700873 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800874 break;
875 }
876 Integer appType = (Integer) request.argument;
877 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
878 if (uiccApp == null) {
879 loge("getForbiddenPlmns() no app with specified type -- "
880 + appType);
881 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700882 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800883 break;
884 } else {
885 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
886 + " specified type -- " + appType);
887 }
888 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
889 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
890 onCompleted);
891 break;
892
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000893 case CMD_SWITCH_SLOTS:
894 request = (MainThreadRequest) msg.obj;
895 int[] physicalSlots = (int[]) request.argument;
896 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
897 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
898 break;
899
900 case EVENT_SWITCH_SLOTS_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700904 notifyRequester(request);
905 break;
906 case CMD_GET_NETWORK_SELECTION_MODE:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
909 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
910 break;
911
912 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 if (ar.exception != null) {
916 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
917 } else {
918 int mode = ((int[]) ar.result)[0];
919 if (mode == 0) {
920 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
921 } else {
922 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
923 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000924 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700925 notifyRequester(request);
926 break;
927 case CMD_GET_CDMA_ROAMING_MODE:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
930 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
931 break;
932 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception != null) {
936 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
937 } else {
938 request.result = ((int[]) ar.result)[0];
939 }
940 notifyRequester(request);
941 break;
942 case CMD_SET_CDMA_ROAMING_MODE:
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
945 int mode = (int) request.argument;
946 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
947 break;
948 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 request.result = ar.exception == null;
952 notifyRequester(request);
953 break;
954 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
957 int subscriptionMode = (int) request.argument;
958 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
959 break;
960 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 request.result = ar.exception == null;
964 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000965 break;
966
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700967 default:
968 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
969 break;
970 }
971 }
Jake Hambye994d462014-02-03 13:10:13 -0800972
Pengquan Meng0c05b502018-09-06 09:59:22 -0700973 private void notifyRequester(MainThreadRequest request) {
974 synchronized (request) {
975 request.notifyAll();
976 }
977 }
978
Jake Hambye994d462014-02-03 13:10:13 -0800979 private void handleNullReturnEvent(Message msg, String command) {
980 AsyncResult ar = (AsyncResult) msg.obj;
981 MainThreadRequest request = (MainThreadRequest) ar.userObj;
982 if (ar.exception == null) {
983 request.result = true;
984 } else {
985 request.result = false;
986 if (ar.exception instanceof CommandException) {
987 loge(command + ": CommandException: " + ar.exception);
988 } else {
989 loge(command + ": Unknown exception");
990 }
991 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700992 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700994 }
995
996 /**
997 * Posts the specified command to be executed on the main thread,
998 * waits for the request to complete, and returns the result.
999 * @see #sendRequestAsync
1000 */
1001 private Object sendRequest(int command, Object argument) {
vagdevie435a3e2018-08-15 16:01:53 -07001002 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1003 }
1004
1005 /**
1006 * Posts the specified command to be executed on the main thread,
1007 * waits for the request to complete, and returns the result.
1008 * @see #sendRequestAsync
1009 */
1010 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1011 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1012 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001013 }
1014
1015 /**
1016 * Posts the specified command to be executed on the main thread,
1017 * waits for the request to complete, and returns the result.
1018 * @see #sendRequestAsync
1019 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001020 private Object sendRequest(int command, Object argument, Integer subId) {
vagdevie435a3e2018-08-15 16:01:53 -07001021 return sendRequest(command, argument, subId, null);
1022 }
1023
1024 /**
1025 * Posts the specified command to be executed on the main thread,
1026 * waits for the request to complete, and returns the result.
1027 * @see #sendRequestAsync
1028 */
1029 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001030 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1031 throw new RuntimeException("This method will deadlock if called from the main thread.");
1032 }
1033
vagdevie435a3e2018-08-15 16:01:53 -07001034 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001035 Message msg = mMainThreadHandler.obtainMessage(command, request);
1036 msg.sendToTarget();
1037
1038 // Wait for the request to complete
1039 synchronized (request) {
1040 while (request.result == null) {
1041 try {
1042 request.wait();
1043 } catch (InterruptedException e) {
1044 // Do nothing, go back and wait until the request is complete
1045 }
1046 }
1047 }
1048 return request.result;
1049 }
1050
1051 /**
1052 * Asynchronous ("fire and forget") version of sendRequest():
1053 * Posts the specified command to be executed on the main thread, and
1054 * returns immediately.
1055 * @see #sendRequest
1056 */
1057 private void sendRequestAsync(int command) {
1058 mMainThreadHandler.sendEmptyMessage(command);
1059 }
1060
1061 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001062 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1063 * @see {@link #sendRequest(int,Object)}
1064 */
1065 private void sendRequestAsync(int command, Object argument) {
1066 MainThreadRequest request = new MainThreadRequest(argument);
1067 Message msg = mMainThreadHandler.obtainMessage(command, request);
1068 msg.sendToTarget();
1069 }
1070
1071 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001072 * Initialize the singleton PhoneInterfaceManager instance.
1073 * This is only done once, at startup, from PhoneApp.onCreate().
1074 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001075 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 synchronized (PhoneInterfaceManager.class) {
1077 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001078 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 } else {
1080 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1081 }
1082 return sInstance;
1083 }
1084 }
1085
1086 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001087 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001088 mApp = app;
1089 mPhone = phone;
1090 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001091 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001092 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1093 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001094 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001095 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001096 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001097 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001098 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001099
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001100 publish();
1101 }
1102
1103 private void publish() {
1104 if (DBG) log("publish: " + this);
1105
1106 ServiceManager.addService("phone", this);
1107 }
1108
Stuart Scott584921c2015-01-15 17:10:34 -08001109 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001110 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1111 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001112 }
1113
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001114 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1115 Phone phone = getPhoneFromRequest(request);
1116 return phone == null ? null :
1117 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1118 }
1119
Wink Saville36469e72014-06-11 15:17:00 -07001120 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001121 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001122 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 //
1125 // Implementation of the ITelephony interface.
1126 //
1127
1128 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001129 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001130 }
1131
Wink Savilleb564aae2014-10-23 10:18:09 -07001132 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 if (DBG) log("dial: " + number);
1134 // No permission check needed here: This is just a wrapper around the
1135 // ACTION_DIAL intent, which is available to any app since it puts up
1136 // the UI before it does anything.
1137
Malcolm Chenaabec062018-02-28 15:00:40 -08001138 final long identity = Binder.clearCallingIdentity();
1139 try {
1140 String url = createTelUrl(number);
1141 if (url == null) {
1142 return;
1143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001144
Malcolm Chenaabec062018-02-28 15:00:40 -08001145 // PENDING: should we just silently fail if phone is offhook or ringing?
1146 PhoneConstants.State state = mCM.getState(subId);
1147 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1148 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1149 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1150 mApp.startActivity(intent);
1151 }
1152 } finally {
1153 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154 }
1155 }
1156
1157 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001158 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001159 }
1160
Wink Savilleb564aae2014-10-23 10:18:09 -07001161 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 if (DBG) log("call: " + number);
1163
1164 // This is just a wrapper around the ACTION_CALL intent, but we still
1165 // need to do a permission check since we're calling startActivity()
1166 // from the context of the phone app.
1167 enforceCallPermission();
1168
1169 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1170 != AppOpsManager.MODE_ALLOWED) {
1171 return;
1172 }
1173
Malcolm Chenaabec062018-02-28 15:00:40 -08001174 final long identity = Binder.clearCallingIdentity();
1175 try {
1176 String url = createTelUrl(number);
1177 if (url == null) {
1178 return;
1179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180
Malcolm Chenaabec062018-02-28 15:00:40 -08001181 boolean isValid = false;
1182 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1183 if (slist != null) {
1184 for (SubscriptionInfo subInfoRecord : slist) {
1185 if (subInfoRecord.getSubscriptionId() == subId) {
1186 isValid = true;
1187 break;
1188 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001189 }
Wink Saville08874612014-08-31 19:19:58 -07001190 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001191 if (!isValid) {
1192 return;
1193 }
Wink Saville08874612014-08-31 19:19:58 -07001194
Malcolm Chenaabec062018-02-28 15:00:40 -08001195 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1196 intent.putExtra(SUBSCRIPTION_KEY, subId);
1197 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1198 mApp.startActivity(intent);
1199 } finally {
1200 Binder.restoreCallingIdentity(identity);
1201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 }
1203
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 /**
1205 * End a call based on call state
1206 * @return true is a call was ended
1207 */
1208 public boolean endCall() {
Hall Liu91943182018-09-14 17:42:41 -07001209 return false;
Wink Saville36469e72014-06-11 15:17:00 -07001210 }
1211
1212 /**
1213 * End a call based on the call state of the subId
1214 * @return true is a call was ended
1215 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001216 public boolean endCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001217 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 }
1219
1220 public void answerRingingCall() {
Hall Liu91943182018-09-14 17:42:41 -07001221 // Deprecated.
Wink Saville36469e72014-06-11 15:17:00 -07001222 }
1223
Wink Savilleb564aae2014-10-23 10:18:09 -07001224 public void answerRingingCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001225 // Deprecated
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 }
1227
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001229 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001231 public void silenceRinger() {
1232 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 }
1234
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001235 @Override
1236 public boolean isOffhook(String callingPackage) {
1237 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001238 }
1239
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001240 @Override
1241 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001243 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001244 return false;
1245 }
1246
Malcolm Chenaabec062018-02-28 15:00:40 -08001247 final long identity = Binder.clearCallingIdentity();
1248 try {
1249 final Phone phone = getPhone(subId);
1250 if (phone != null) {
1251 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1252 } else {
1253 return false;
1254 }
1255 } finally {
1256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001260 @Override
1261 public boolean isRinging(String callingPackage) {
1262 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001265 @Override
1266 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001268 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 return false;
1270 }
1271
Malcolm Chenaabec062018-02-28 15:00:40 -08001272 final long identity = Binder.clearCallingIdentity();
1273 try {
1274 final Phone phone = getPhone(subId);
1275 if (phone != null) {
1276 return (phone.getState() == PhoneConstants.State.RINGING);
1277 } else {
1278 return false;
1279 }
1280 } finally {
1281 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 }
1284
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001285 @Override
1286 public boolean isIdle(String callingPackage) {
1287 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001288 }
1289
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001290 @Override
1291 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001293 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001294 return false;
1295 }
1296
Malcolm Chenaabec062018-02-28 15:00:40 -08001297 final long identity = Binder.clearCallingIdentity();
1298 try {
1299 final Phone phone = getPhone(subId);
1300 if (phone != null) {
1301 return (phone.getState() == PhoneConstants.State.IDLE);
1302 } else {
1303 return false;
1304 }
1305 } finally {
1306 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 }
1309
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001311 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001312 }
1313
Wink Savilleb564aae2014-10-23 10:18:09 -07001314 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001315 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001316 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1317 }
1318
1319 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001321 }
1322
Wink Savilleb564aae2014-10-23 10:18:09 -07001323 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001324 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001325 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1326 }
1327
1328 /** {@hide} */
1329 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001330 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001331 }
1332
Wink Savilleb564aae2014-10-23 10:18:09 -07001333 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001335
1336 final long identity = Binder.clearCallingIdentity();
1337 try {
1338 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1339 checkSimPin.start();
1340 return checkSimPin.unlockSim(null, pin);
1341 } finally {
1342 Binder.restoreCallingIdentity(identity);
1343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 }
1345
Wink Saville9de0f752013-10-22 19:04:03 -07001346 /** {@hide} */
1347 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001348 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001349 }
1350
Wink Savilleb564aae2014-10-23 10:18:09 -07001351 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001352 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001353
1354 final long identity = Binder.clearCallingIdentity();
1355 try {
1356 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1357 checkSimPuk.start();
1358 return checkSimPuk.unlockSim(puk, pin);
1359 } finally {
1360 Binder.restoreCallingIdentity(identity);
1361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 }
1363
1364 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001365 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 * a synchronous one.
1367 */
1368 private static class UnlockSim extends Thread {
1369
1370 private final IccCard mSimCard;
1371
1372 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001373 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1374 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375
1376 // For replies from SimCard interface
1377 private Handler mHandler;
1378
1379 // For async handler to identify request type
1380 private static final int SUPPLY_PIN_COMPLETE = 100;
1381
1382 public UnlockSim(IccCard simCard) {
1383 mSimCard = simCard;
1384 }
1385
1386 @Override
1387 public void run() {
1388 Looper.prepare();
1389 synchronized (UnlockSim.this) {
1390 mHandler = new Handler() {
1391 @Override
1392 public void handleMessage(Message msg) {
1393 AsyncResult ar = (AsyncResult) msg.obj;
1394 switch (msg.what) {
1395 case SUPPLY_PIN_COMPLETE:
1396 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1397 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001398 mRetryCount = msg.arg1;
1399 if (ar.exception != null) {
1400 if (ar.exception instanceof CommandException &&
1401 ((CommandException)(ar.exception)).getCommandError()
1402 == CommandException.Error.PASSWORD_INCORRECT) {
1403 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1404 } else {
1405 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1406 }
1407 } else {
1408 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 mDone = true;
1411 UnlockSim.this.notifyAll();
1412 }
1413 break;
1414 }
1415 }
1416 };
1417 UnlockSim.this.notifyAll();
1418 }
1419 Looper.loop();
1420 }
1421
1422 /*
1423 * Use PIN or PUK to unlock SIM card
1424 *
1425 * If PUK is null, unlock SIM card with PIN
1426 *
1427 * If PUK is not null, unlock SIM card with PUK and set PIN code
1428 */
Wink Saville9de0f752013-10-22 19:04:03 -07001429 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430
1431 while (mHandler == null) {
1432 try {
1433 wait();
1434 } catch (InterruptedException e) {
1435 Thread.currentThread().interrupt();
1436 }
1437 }
1438 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1439
1440 if (puk == null) {
1441 mSimCard.supplyPin(pin, callback);
1442 } else {
1443 mSimCard.supplyPuk(puk, pin, callback);
1444 }
1445
1446 while (!mDone) {
1447 try {
1448 Log.d(LOG_TAG, "wait for done");
1449 wait();
1450 } catch (InterruptedException e) {
1451 // Restore the interrupted status
1452 Thread.currentThread().interrupt();
1453 }
1454 }
1455 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001456 int[] resultArray = new int[2];
1457 resultArray[0] = mResult;
1458 resultArray[1] = mRetryCount;
1459 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 }
1461 }
1462
1463 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001464 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001465
1466 }
1467
Wink Savilleb564aae2014-10-23 10:18:09 -07001468 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 // No permission check needed here: this call is harmless, and it's
1470 // needed for the ServiceState.requestStateUpdate() call (which is
1471 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001472 final long identity = Binder.clearCallingIdentity();
1473 try {
1474 final Phone phone = getPhone(subId);
1475 if (phone != null) {
1476 phone.updateServiceLocation();
1477 }
1478 } finally {
1479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001483 @Override
1484 public boolean isRadioOn(String callingPackage) {
1485 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001488 @Override
1489 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001491 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001492 return false;
1493 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001494
1495 final long identity = Binder.clearCallingIdentity();
1496 try {
1497 return isRadioOnForSubscriber(subId);
1498 } finally {
1499 Binder.restoreCallingIdentity(identity);
1500 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001501 }
1502
1503 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001504 final long identity = Binder.clearCallingIdentity();
1505 try {
1506 final Phone phone = getPhone(subId);
1507 if (phone != null) {
1508 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1509 } else {
1510 return false;
1511 }
1512 } finally {
1513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 }
1516
1517 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001518 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519 }
Wink Saville36469e72014-06-11 15:17:00 -07001520
Wink Savilleb564aae2014-10-23 10:18:09 -07001521 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001523
1524 final long identity = Binder.clearCallingIdentity();
1525 try {
1526 final Phone phone = getPhone(subId);
1527 if (phone != null) {
1528 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1529 }
1530 } finally {
1531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001532 }
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
1535 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001540 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001541
1542 final long identity = Binder.clearCallingIdentity();
1543 try {
1544 final Phone phone = getPhone(subId);
1545 if (phone == null) {
1546 return false;
1547 }
1548 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1549 toggleRadioOnOffForSubscriber(subId);
1550 }
1551 return true;
1552 } finally {
1553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
Wink Saville36469e72014-06-11 15:17:00 -07001556
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001557 public boolean needMobileRadioShutdown() {
1558 /*
1559 * If any of the Radios are available, it will need to be
1560 * shutdown. So return true if any Radio is available.
1561 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001562 final long identity = Binder.clearCallingIdentity();
1563 try {
1564 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1565 Phone phone = PhoneFactory.getPhone(i);
1566 if (phone != null && phone.isRadioAvailable()) return true;
1567 }
1568 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1569 return false;
1570 } finally {
1571 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001572 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001573 }
1574
Malcolm Chenaabec062018-02-28 15:00:40 -08001575 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001576 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001577 enforceModifyPermission();
1578
1579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1582 logv("Shutting down Phone " + i);
1583 shutdownRadioUsingPhoneId(i);
1584 }
1585 } finally {
1586 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001587 }
1588 }
1589
1590 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001591 Phone phone = PhoneFactory.getPhone(phoneId);
1592 if (phone != null && phone.isRadioAvailable()) {
1593 phone.shutdownRadio();
1594 }
1595 }
1596
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001598 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001599
1600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1603 if (defaultPhone != null) {
1604 defaultPhone.setRadioPower(turnOn);
1605 return true;
1606 } else {
1607 loge("There's no default phone.");
1608 return false;
1609 }
1610 } finally {
1611 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001612 }
Wink Saville36469e72014-06-11 15:17:00 -07001613 }
1614
Wink Savilleb564aae2014-10-23 10:18:09 -07001615 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001617
1618 final long identity = Binder.clearCallingIdentity();
1619 try {
1620 final Phone phone = getPhone(subId);
1621 if (phone != null) {
1622 phone.setRadioPower(turnOn);
1623 return true;
1624 } else {
1625 return false;
1626 }
1627 } finally {
1628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 }
1631
Wink Saville36469e72014-06-11 15:17:00 -07001632 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 public boolean enableDataConnectivity() {
1635 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001636
1637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 int subId = mSubscriptionController.getDefaultDataSubId();
1640 final Phone phone = getPhone(subId);
1641 if (phone != null) {
1642 phone.setUserDataEnabled(true);
1643 return true;
1644 } else {
1645 return false;
1646 }
1647 } finally {
1648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651
Wink Saville36469e72014-06-11 15:17:00 -07001652 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 public boolean disableDataConnectivity() {
1655 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001656
1657 final long identity = Binder.clearCallingIdentity();
1658 try {
1659 int subId = mSubscriptionController.getDefaultDataSubId();
1660 final Phone phone = getPhone(subId);
1661 if (phone != null) {
1662 phone.setUserDataEnabled(false);
1663 return true;
1664 } else {
1665 return false;
1666 }
1667 } finally {
1668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 }
1671
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001673 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001674 final long identity = Binder.clearCallingIdentity();
1675 try {
1676 final Phone phone = getPhone(subId);
1677 if (phone != null) {
1678 return phone.isDataAllowed();
1679 } else {
1680 return false;
1681 }
1682 } finally {
1683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 }
1686
1687 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001688 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001689 }
1690
pkanwarae03a6b2016-11-06 20:37:09 -08001691 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001692 enforceCallPermission();
1693
1694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1697 return;
1698 }
1699 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1700 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
1703 }
pkanwar32d516d2016-10-14 19:37:38 -07001704 };
1705
Wink Savilleb564aae2014-10-23 10:18:09 -07001706 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001708
1709 final long identity = Binder.clearCallingIdentity();
1710 try {
1711 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1712 return false;
1713 }
1714 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1715 } finally {
1716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001721 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001722 }
1723
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001724 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 Phone phone = PhoneFactory.getPhone(slotIndex);
1728 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1729 PhoneConstantConversions.convertCallState(phone.getState());
1730 } finally {
1731 Binder.restoreCallingIdentity(identity);
1732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
1734
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001737 final long identity = Binder.clearCallingIdentity();
1738 try {
1739 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1740 if (phone != null) {
1741 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1742 } else {
1743 return PhoneConstantConversions.convertDataState(
1744 PhoneConstants.DataState.DISCONNECTED);
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1756 if (phone != null) {
1757 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1758 } else {
1759 return TelephonyManager.DATA_ACTIVITY_NONE;
1760 }
1761 } finally {
1762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 }
1765
1766 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001767 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001768 mPhone.getContext().getSystemService(AppOpsManager.class)
1769 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001771 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001772 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001775 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 if (DBG_LOC) log("getCellLocation: is active user");
1779 Bundle data = new Bundle();
1780 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1781 if (phone == null) {
1782 return null;
1783 }
1784
1785 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1786 return data;
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
1789 }
Svetoslav64fad262015-04-14 14:35:21 -07001790 }
1791
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001793 public String getNetworkCountryIsoForPhone(int phoneId) {
1794 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1795 // registered cell info, so return a NULL country instead.
1796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001799 // Todo: fix this when we can get the actual cellular network info when the device
1800 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001801 if (TelephonyManager.NETWORK_TYPE_IWLAN
1802 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1803 return "";
1804 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001805 Phone phone = PhoneFactory.getPhone(phoneId);
1806 if (phone != null) {
1807 ServiceStateTracker sst = phone.getServiceStateTracker();
1808 if (sst != null) {
1809 LocaleTracker lt = sst.getLocaleTracker();
1810 if (lt != null) {
1811 return lt.getCurrentCountry();
1812 }
1813 }
1814 }
1815 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001816 } finally {
1817 Binder.restoreCallingIdentity(identity);
1818 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001819 }
1820
1821 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001823 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001824 }
1825
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001827 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 mApp.enforceCallingOrSelfPermission(
1829 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001830
1831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 final Phone phone = getPhone(subId);
1834 if (phone != null) {
1835 phone.enableLocationUpdates();
1836 }
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
1842 @Override
1843 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001844 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001845 }
1846
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001848 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 mApp.enforceCallingOrSelfPermission(
1850 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001851
1852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 final Phone phone = getPhone(subId);
1855 if (phone != null) {
1856 phone.disableLocationUpdates();
1857 }
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
1863 @Override
1864 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001865 public List<NeighboringCellInfo>
1866 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001867 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1868 throw new SecurityException(
1869 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1870 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001871
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1873 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1874 return null;
1875 }
Svetoslav64fad262015-04-14 14:35:21 -07001876
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001877 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878
Nathan Haroldf180aac2018-06-01 18:43:55 -07001879 List<CellInfo> info = getAllCellInfo(callingPackage);
1880 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881
Nathan Haroldf180aac2018-06-01 18:43:55 -07001882 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1883 for (CellInfo ci : info) {
1884 if (ci instanceof CellInfoGsm) {
1885 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1886 } else if (ci instanceof CellInfoWcdma) {
1887 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001890 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 }
1892
1893
1894 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001895 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001896 mPhone.getContext().getSystemService(AppOpsManager.class)
1897 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001898 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001899 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001900 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 }
1902
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001903 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001904 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001905 final long identity = Binder.clearCallingIdentity();
1906 try {
1907 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1908 for (Phone phone : PhoneFactory.getPhones()) {
1909 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1910 if (info != null) cellInfos.addAll(info);
1911 }
1912 return cellInfos;
1913 } finally {
1914 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916 }
1917
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001918 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001920 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001921 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001922
1923 final long identity = Binder.clearCallingIdentity();
1924 try {
1925 mPhone.setCellInfoListRate(rateInMillis, workSource);
1926 } finally {
1927 Binder.restoreCallingIdentity(identity);
1928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930
Shishir Agrawala9f32182016-04-12 12:00:16 -07001931 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001932 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001933 Phone phone = PhoneFactory.getPhone(slotIndex);
1934 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001935 return null;
1936 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001937 int subId = phone.getSubId();
1938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1939 mApp, subId, callingPackage, "getImeiForSlot")) {
1940 return null;
1941 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001942
1943 final long identity = Binder.clearCallingIdentity();
1944 try {
1945 return phone.getImei();
1946 } finally {
1947 Binder.restoreCallingIdentity(identity);
1948 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001949 }
1950
1951 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001952 public String getTypeAllocationCodeForSlot(int slotIndex) {
1953 Phone phone = PhoneFactory.getPhone(slotIndex);
1954 String tac = null;
1955 if (phone != null) {
1956 String imei = phone.getImei();
1957 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1958 }
1959 return tac;
1960 }
1961
1962 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001963 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001964 Phone phone = PhoneFactory.getPhone(slotIndex);
1965 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001966 return null;
1967 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001968 int subId = phone.getSubId();
1969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1970 mApp, subId, callingPackage, "getMeidForSlot")) {
1971 return null;
1972 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001973
1974 final long identity = Binder.clearCallingIdentity();
1975 try {
1976 return phone.getMeid();
1977 } finally {
1978 Binder.restoreCallingIdentity(identity);
1979 }
Jack Yu2af8d712017-03-15 17:14:14 -07001980 }
1981
1982 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001983 public String getManufacturerCodeForSlot(int slotIndex) {
1984 Phone phone = PhoneFactory.getPhone(slotIndex);
1985 String manufacturerCode = null;
1986 if (phone != null) {
1987 String meid = phone.getMeid();
1988 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1989 }
1990 return manufacturerCode;
1991 }
1992
1993 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001994 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001995 Phone phone = PhoneFactory.getPhone(slotIndex);
1996 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001997 return null;
1998 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001999 int subId = phone.getSubId();
2000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2001 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2002 return null;
2003 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002004
2005 final long identity = Binder.clearCallingIdentity();
2006 try {
2007 return phone.getDeviceSvn();
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
2010 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002011 }
2012
fionaxu43304da2017-11-27 22:51:16 -08002013 @Override
2014 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002015 final long identity = Binder.clearCallingIdentity();
2016 try {
2017 final Phone phone = getPhone(subId);
2018 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2019 } finally {
2020 Binder.restoreCallingIdentity(identity);
2021 }
fionaxu43304da2017-11-27 22:51:16 -08002022 }
2023
2024 @Override
2025 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002026 final long identity = Binder.clearCallingIdentity();
2027 try {
2028 final Phone phone = getPhone(subId);
2029 return phone == null ? null : phone.getCarrierName();
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
2032 }
fionaxu43304da2017-11-27 22:51:16 -08002033 }
2034
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 //
2036 // Internal helper methods.
2037 //
2038
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002039 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2041 *
2042 * @throws SecurityException if the caller does not have the required permission
2043 */
2044 private void enforceModifyPermission() {
2045 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2046 }
2047
2048 /**
2049 * Make sure the caller has the CALL_PHONE permission.
2050 *
2051 * @throws SecurityException if the caller does not have the required permission
2052 */
2053 private void enforceCallPermission() {
2054 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2055 }
2056
Stuart Scott8eef64f2015-04-08 15:13:54 -07002057 private void enforceConnectivityInternalPermission() {
2058 mApp.enforceCallingOrSelfPermission(
2059 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2060 "ConnectivityService");
2061 }
2062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 private String createTelUrl(String number) {
2064 if (TextUtils.isEmpty(number)) {
2065 return null;
2066 }
2067
Jake Hambye994d462014-02-03 13:10:13 -08002068 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 }
2070
Ihab Awadf9e92732013-12-05 18:02:52 -08002071 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2073 }
2074
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002075 private static void logv(String msg) {
2076 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2077 }
2078
Ihab Awadf9e92732013-12-05 18:02:52 -08002079 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2081 }
2082
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002083 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002085 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002086 }
2087
Sanket Padawe356d7632015-06-22 14:03:32 -07002088 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002089 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002090 final long identity = Binder.clearCallingIdentity();
2091 try {
2092 final Phone phone = PhoneFactory.getPhone(slotIndex);
2093 if (phone == null) {
2094 return PhoneConstants.PHONE_TYPE_NONE;
2095 } else {
2096 return phone.getPhoneType();
2097 }
2098 } finally {
2099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 }
2102
2103 /**
2104 * Returns the CDMA ERI icon index to display
2105 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002106 @Override
2107 public int getCdmaEriIconIndex(String callingPackage) {
2108 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002109 }
2110
Sanket Padawe356d7632015-06-22 14:03:32 -07002111 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002112 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002114 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002115 return -1;
2116 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002117
2118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 final Phone phone = getPhone(subId);
2121 if (phone != null) {
2122 return phone.getCdmaEriIconIndex();
2123 } else {
2124 return -1;
2125 }
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
2131 /**
2132 * Returns the CDMA ERI icon mode,
2133 * 0 - ON
2134 * 1 - FLASHING
2135 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002136 @Override
2137 public int getCdmaEriIconMode(String callingPackage) {
2138 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002139 }
2140
Sanket Padawe356d7632015-06-22 14:03:32 -07002141 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002142 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002144 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002145 return -1;
2146 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002147
2148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 final Phone phone = getPhone(subId);
2151 if (phone != null) {
2152 return phone.getCdmaEriIconMode();
2153 } else {
2154 return -1;
2155 }
2156 } finally {
2157 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
2161 /**
2162 * Returns the CDMA ERI text,
2163 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002164 @Override
2165 public String getCdmaEriText(String callingPackage) {
2166 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002167 }
2168
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002170 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002172 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002173 return null;
2174 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002175
2176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 final Phone phone = getPhone(subId);
2179 if (phone != null) {
2180 return phone.getCdmaEriText();
2181 } else {
2182 return null;
2183 }
2184 } finally {
2185 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 }
2188
2189 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002190 * Returns the CDMA MDN.
2191 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002192 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002193 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2195 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002196
2197 final long identity = Binder.clearCallingIdentity();
2198 try {
2199 final Phone phone = getPhone(subId);
2200 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2201 return phone.getLine1Number();
2202 } else {
2203 return null;
2204 }
2205 } finally {
2206 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002207 }
2208 }
2209
2210 /**
2211 * Returns the CDMA MIN.
2212 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002214 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2216 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002217
2218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 final Phone phone = getPhone(subId);
2221 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2222 return phone.getCdmaMin();
2223 } else {
2224 return null;
2225 }
2226 } finally {
2227 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002228 }
2229 }
2230
2231 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 * Returns true if CDMA provisioning needs to run.
2233 */
2234 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002235 final long identity = Binder.clearCallingIdentity();
2236 try {
2237 return mPhone.needsOtaServiceProvisioning();
2238 } finally {
2239 Binder.restoreCallingIdentity(identity);
2240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
2243 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002244 * Sets the voice mail number of a given subId.
2245 */
2246 @Override
2247 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002248 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002249
2250 final long identity = Binder.clearCallingIdentity();
2251 try {
2252 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2253 new Pair<String, String>(alphaTag, number), new Integer(subId));
2254 return success;
2255 } finally {
2256 Binder.restoreCallingIdentity(identity);
2257 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002258 }
2259
Ta-wei Yen87c49842016-05-13 21:19:52 -07002260 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002261 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2262 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2263 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2264 if (!TextUtils.equals(callingPackage, systemDialer)) {
2265 throw new SecurityException("caller must be system dialer");
2266 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002267
2268 final long identity = Binder.clearCallingIdentity();
2269 try {
2270 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2271 if (phoneAccountHandle == null) {
2272 return null;
2273 }
2274 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2275 } finally {
2276 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002277 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002278 }
2279
2280 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002281 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002282 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002285 return null;
2286 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002287
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 return RemoteVvmTaskManager
2291 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2292 } finally {
2293 Binder.restoreCallingIdentity(identity);
2294 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002295 }
2296
2297 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002298 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2299 VisualVoicemailSmsFilterSettings settings) {
2300 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002301
2302 final long identity = Binder.clearCallingIdentity();
2303 try {
2304 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2305 mPhone.getContext(), callingPackage, subId, settings);
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
2308 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002309 }
2310
2311 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002312 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002314
2315 final long identity = Binder.clearCallingIdentity();
2316 try {
2317 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2318 mPhone.getContext(), callingPackage, subId);
2319 } finally {
2320 Binder.restoreCallingIdentity(identity);
2321 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002322 }
2323
2324 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002325 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2326 String callingPackage, int subId) {
2327 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002328
2329 final long identity = Binder.clearCallingIdentity();
2330 try {
2331 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2332 mPhone.getContext(), callingPackage, subId);
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
2335 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002336 }
2337
2338 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002339 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002340 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2345 mPhone.getContext(), subId);
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
2348 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002349 }
2350
2351 @Override
2352 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2353 String number, int port, String text, PendingIntent sentIntent) {
2354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002355 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002356 enforceSendSmsPermission();
2357 // Make the calls as the phone process.
2358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2361 if (port == 0) {
2362 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2363 sentIntent, null, false);
2364 } else {
2365 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2366 smsManager.sendDataMessageWithSelfPermissions(number, null,
2367 (short) port, data, sentIntent, null);
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
2371 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002372 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002373 /**
fionaxu0152e512016-11-14 13:36:14 -08002374 * Sets the voice activation state of a given subId.
2375 */
2376 @Override
2377 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2379 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002380
2381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 final Phone phone = getPhone(subId);
2384 if (phone != null) {
2385 phone.setVoiceActivationState(activationState);
2386 } else {
2387 loge("setVoiceActivationState fails with invalid subId: " + subId);
2388 }
2389 } finally {
2390 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002391 }
2392 }
2393
2394 /**
2395 * Sets the data activation state of a given subId.
2396 */
2397 @Override
2398 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2400 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002401
2402 final long identity = Binder.clearCallingIdentity();
2403 try {
2404 final Phone phone = getPhone(subId);
2405 if (phone != null) {
2406 phone.setDataActivationState(activationState);
2407 } else {
2408 loge("setVoiceActivationState fails with invalid subId: " + subId);
2409 }
2410 } finally {
2411 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002412 }
2413 }
2414
2415 /**
2416 * Returns the voice activation state of a given subId.
2417 */
2418 @Override
2419 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002420 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002421
fionaxu0152e512016-11-14 13:36:14 -08002422 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 if (phone != null) {
2426 return phone.getVoiceActivationState();
2427 } else {
2428 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2429 }
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002432 }
2433 }
2434
2435 /**
2436 * Returns the data activation state of a given subId.
2437 */
2438 @Override
2439 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002440 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002441
fionaxu0152e512016-11-14 13:36:14 -08002442 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002443 final long identity = Binder.clearCallingIdentity();
2444 try {
2445 if (phone != null) {
2446 return phone.getDataActivationState();
2447 } else {
2448 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2449 }
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002452 }
2453 }
2454
2455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 * Returns the unread count of voicemails
2457 */
2458 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002459 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002460 }
2461
2462 /**
2463 * Returns the unread count of voicemails for a subId
2464 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002465 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002466 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 final Phone phone = getPhone(subId);
2470 if (phone != null) {
2471 return phone.getVoiceMessageCount();
2472 } else {
2473 return 0;
2474 }
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
2480 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002481 * returns true, if the device is in a state where both voice and data
2482 * are supported simultaneously. This can change based on location or network condition.
2483 */
2484 @Override
2485 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 final Phone phone = getPhone(subId);
2489 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002493 }
2494
2495 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002496 * Send the dialer code if called from the current default dialer or the caller has
2497 * carrier privilege.
2498 * @param inputCode The dialer code to send
2499 */
2500 @Override
2501 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2503 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2504 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002505 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2506 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002507 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 mPhone.sendDialerSpecialCode(inputCode);
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
fionaxu235cc5e2017-03-06 22:25:57 -08002515 }
2516
2517 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002518 * Returns the data network type.
2519 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 *
2521 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2522 */
2523 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002524 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002525 final long identity = Binder.clearCallingIdentity();
2526 try {
2527 final Phone phone = getPhone(getDefaultSubscription());
2528 if (phone != null) {
2529 return phone.getServiceState().getDataNetworkType();
2530 } else {
2531 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2532 }
2533 } finally {
2534 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002535 }
Wink Saville36469e72014-06-11 15:17:00 -07002536 }
2537
Pengquan Meng0c05b502018-09-06 09:59:22 -07002538 @Override
2539 public int getNetworkSelectionMode(int subId) {
2540 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2541 }
2542
Wink Saville36469e72014-06-11 15:17:00 -07002543 /**
2544 * Returns the network type for a subId
2545 */
2546 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002547 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002549 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2551 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002552
Malcolm Chenaabec062018-02-28 15:00:40 -08002553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getServiceState().getDataNetworkType();
2558 } else {
2559 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 /**
2567 * Returns the data network type
2568 */
2569 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002570 public int getDataNetworkType(String callingPackage) {
2571 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002572 }
2573
2574 /**
2575 * Returns the data network type for a subId
2576 */
2577 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002578 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002580 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002581 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2582 }
2583
Malcolm Chenaabec062018-02-28 15:00:40 -08002584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 if (phone != null) {
2588 return phone.getServiceState().getDataNetworkType();
2589 } else {
2590 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 }
2596
2597 /**
Wink Saville36469e72014-06-11 15:17:00 -07002598 * Returns the Voice network type for a subId
2599 */
2600 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002601 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002603 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002604 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2605 }
2606
Malcolm Chenaabec062018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 final Phone phone = getPhone(subId);
2610 if (phone != null) {
2611 return phone.getServiceState().getVoiceNetworkType();
2612 } else {
2613 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2614 }
2615 } finally {
2616 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
2620 /**
2621 * @return true if a ICC card is present
2622 */
2623 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002624 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002625 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2626 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002627 }
2628
2629 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002630 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002631 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002633 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 final Phone phone = PhoneFactory.getPhone(slotIndex);
2637 if (phone != null) {
2638 return phone.getIccCard().hasIccCard();
2639 } else {
2640 return false;
2641 }
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 }
2646
2647 /**
2648 * Return if the current radio is LTE on CDMA. This
2649 * is a tri-state return value as for a period of time
2650 * the mode may be unknown.
2651 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002652 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002654 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002656 @Override
2657 public int getLteOnCdmaMode(String callingPackage) {
2658 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002659 }
2660
Sanket Padawe356d7632015-06-22 14:03:32 -07002661 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002662 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002664 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002665 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2666 }
2667
Malcolm Chenaabec062018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone == null) {
2672 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2673 } else {
2674 return phone.getLteOnCdmaMode();
2675 }
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 }
Wink Saville36469e72014-06-11 15:17:00 -07002679 }
2680
2681 public void setPhone(Phone phone) {
2682 mPhone = phone;
2683 }
2684
2685 /**
2686 * {@hide}
2687 * Returns Default subId, 0 in the case of single standby.
2688 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002689 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002690 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002691 }
2692
Shishir Agrawala9f32182016-04-12 12:00:16 -07002693 private int getSlotForDefaultSubscription() {
2694 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2695 }
2696
Wink Savilleb564aae2014-10-23 10:18:09 -07002697 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002698 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002700
2701 /**
2702 * @see android.telephony.TelephonyManager.WifiCallingChoices
2703 */
2704 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2708 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2709 getWhenToMakeWifiCallsDefaultPreference());
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
2712 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002713 }
2714
2715 /**
2716 * @see android.telephony.TelephonyManager.WifiCallingChoices
2717 */
2718 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2722 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2723 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002727 }
2728
Sailesh Nepald1e68152013-12-12 19:08:02 -08002729 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002730 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002731 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002732 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002733
Shishir Agrawal566b7612013-10-28 14:41:00 -07002734 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002735 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2736 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2738 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002740
Malcolm Chenaabec062018-02-28 15:00:40 -08002741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 if (TextUtils.equals(ISDR_AID, aid)) {
2744 // Only allows LPA to open logical channel to ISD-R.
2745 ComponentInfo bestComponent =
2746 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2747 if (bestComponent == null
2748 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2749 loge("The calling package is not allowed to access ISD-R.");
2750 throw new SecurityException(
2751 "The calling package is not allowed to access ISD-R.");
2752 }
Derek Tan740e1672017-06-27 14:56:27 -07002753 }
Derek Tan740e1672017-06-27 14:56:27 -07002754
Malcolm Chenaabec062018-02-28 15:00:40 -08002755 if (DBG) {
2756 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2757 }
2758 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2759 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2760 if (DBG) log("iccOpenLogicalChannel: " + response);
2761 return response;
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002765 }
2766
2767 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002768 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2770 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002771
Malcolm Chenaabec062018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2775 if (channel < 0) {
2776 return false;
2777 }
2778 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2779 if (DBG) log("iccCloseLogicalChannel: " + success);
2780 return success;
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002783 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002784 }
2785
2786 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002787 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002788 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2790 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002791
Malcolm Chenaabec062018-02-28 15:00:40 -08002792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 if (DBG) {
2795 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2796 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2797 + p3 + " data=" + data);
2798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002799
Malcolm Chenaabec062018-02-28 15:00:40 -08002800 if (channel < 0) {
2801 return "";
2802 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002803
Malcolm Chenaabec062018-02-28 15:00:40 -08002804 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2805 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2806 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002807
Malcolm Chenaabec062018-02-28 15:00:40 -08002808 // Append the returned status code to the end of the response payload.
2809 String s = Integer.toHexString(
2810 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2811 if (response.payload != null) {
2812 s = IccUtils.bytesToHexString(response.payload) + s;
2813 }
2814 return s;
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002817 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002818 }
Jake Hambye994d462014-02-03 13:10:13 -08002819
Evan Charltonc66da362014-05-16 14:06:40 -07002820 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002821 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2822 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2824 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002825 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002826
Malcolm Chenaabec062018-02-28 15:00:40 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2830 && TextUtils.equals(ISDR_AID, data)) {
2831 // Only allows LPA to select ISD-R.
2832 ComponentInfo bestComponent =
2833 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2834 if (bestComponent == null
2835 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2836 loge("The calling package is not allowed to select ISD-R.");
2837 throw new SecurityException(
2838 "The calling package is not allowed to select ISD-R.");
2839 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002840 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002841
Malcolm Chenaabec062018-02-28 15:00:40 -08002842 if (DBG) {
2843 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2844 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2845 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002846
Malcolm Chenaabec062018-02-28 15:00:40 -08002847 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2848 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2849 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002850
Malcolm Chenaabec062018-02-28 15:00:40 -08002851 // Append the returned status code to the end of the response payload.
2852 String s = Integer.toHexString(
2853 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2854 if (response.payload != null) {
2855 s = IccUtils.bytesToHexString(response.payload) + s;
2856 }
2857 return s;
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002860 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002861 }
2862
2863 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002864 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002865 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2867 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002868
Malcolm Chenaabec062018-02-28 15:00:40 -08002869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 if (DBG) {
2872 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2873 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2874 }
2875
2876 IccIoResult response =
2877 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2878 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2879 subId);
2880
2881 if (DBG) {
2882 log("Exchange SIM_IO [R]" + response);
2883 }
2884
2885 byte[] result = null;
2886 int length = 2;
2887 if (response.payload != null) {
2888 length = 2 + response.payload.length;
2889 result = new byte[length];
2890 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2891 } else {
2892 result = new byte[length];
2893 }
2894
2895 result[length - 1] = (byte) response.sw2;
2896 result[length - 2] = (byte) response.sw1;
2897 return result;
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002900 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002901 }
2902
Nathan Haroldb3014052017-01-25 15:57:32 -08002903 /**
2904 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2905 * on a particular subscription
2906 */
sqianb6e41952018-03-12 14:54:01 -07002907 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2909 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2910 return null;
2911 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002912 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2913 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2914 return null;
2915 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2920 if (response instanceof String[]) {
2921 return (String[]) response;
2922 }
2923 // Response is an Exception of some kind,
2924 // which is signalled to the user as a NULL retval
2925 return null;
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002928 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002929 }
2930
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002931 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002932 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2934 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002935
Malcolm Chenaabec062018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2939 if (response.payload == null) {
2940 return "";
2941 }
Evan Charltonc66da362014-05-16 14:06:40 -07002942
Malcolm Chenaabec062018-02-28 15:00:40 -08002943 // Append the returned status code to the end of the response payload.
2944 String s = Integer.toHexString(
2945 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2946 s = IccUtils.bytesToHexString(response.payload) + s;
2947 return s;
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
Evan Charltonc66da362014-05-16 14:06:40 -07002951 }
2952
Jake Hambye994d462014-02-03 13:10:13 -08002953 /**
2954 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2955 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2956 *
2957 * @param itemID the ID of the item to read
2958 * @return the NV item as a String, or null on error.
2959 */
2960 @Override
2961 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07002962 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2964 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08002965
2966 final long identity = Binder.clearCallingIdentity();
2967 try {
2968 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07002969 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08002970 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2971 return value;
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
Jake Hambye994d462014-02-03 13:10:13 -08002975 }
2976
2977 /**
2978 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2979 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2980 *
2981 * @param itemID the ID of the item to read
2982 * @param itemValue the value to write, as a String
2983 * @return true on success; false on any failure
2984 */
2985 @Override
2986 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07002987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2989 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08002990
2991 final long identity = Binder.clearCallingIdentity();
2992 try {
2993 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2994 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07002995 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08002996 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2997 return success;
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
Jake Hambye994d462014-02-03 13:10:13 -08003001 }
3002
3003 /**
3004 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3005 * Used for device configuration by some CDMA operators.
3006 *
3007 * @param preferredRoamingList byte array containing the new PRL
3008 * @return true on success; false on any failure
3009 */
3010 @Override
3011 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3013 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003014
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3018 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3019 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3020 return success;
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
Jake Hambye994d462014-02-03 13:10:13 -08003024 }
3025
3026 /**
3027 * Perform the specified type of NV config reset.
3028 * Used for device configuration by some CDMA operators.
3029 *
3030 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3031 * @return true on success; false on any failure
3032 */
3033 @Override
3034 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3036 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 if (DBG) log("nvResetConfig: type " + resetType);
3041 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3042 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3043 return success;
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
Jake Hambye994d462014-02-03 13:10:13 -08003047 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003048
Svet Ganovb320e182015-04-16 12:30:10 -07003049 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003051 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003052 return new String[0];
3053 }
3054
Malcolm Chenaabec062018-02-28 15:00:40 -08003055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 return mPhone.getPcscfAddress(apnType);
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
3060 }
Wink Saville36469e72014-06-11 15:17:00 -07003061 }
3062
Brad Ebinger51f743a2017-01-23 13:50:20 -08003063 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003064 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3065 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003066 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003067 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003068 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003069
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 PhoneFactory.getImsResolver().enableIms(slotId);
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003076 }
3077
3078 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003079 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3080 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003081 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003082 public void disableIms(int slotId) {
3083 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003084
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 PhoneFactory.getImsResolver().disableIms(slotId);
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003091 }
3092
3093 /**
3094 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3095 * feature or {@link null} if the service is not available. If the feature is available, the
3096 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3097 */
3098 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003099 IImsServiceFeatureCallback callback) {
3100 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003101
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003108 }
3109
3110 /**
3111 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3112 * feature during emergency calling or {@link null} if the service is not available. If the
3113 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3114 * listener for feature updates.
3115 */
3116 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3117 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003118
3119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003125 }
3126
Brad Ebinger5f64b052017-12-14 14:26:15 -08003127 /**
3128 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3129 * specified.
3130 */
3131 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3132 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003133
3134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003140 }
3141
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003142 /**
3143 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3144 * specified.
3145 */
3146 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3147 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003155 }
3156
Brad Ebinger884c07b2018-02-15 16:17:40 -08003157 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003158 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3159 * available, false if the IMS resolver is idle.
3160 */
3161 public boolean isResolvingImsBinding() {
3162 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003163
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 return PhoneFactory.getImsResolver().isResolvingBinding();
3167 } finally {
3168 Binder.restoreCallingIdentity(identity);
3169 }
Brad Ebinger67801702018-03-02 13:43:36 -08003170 }
3171
Brad Ebingerdac2f002018-04-03 15:17:52 -07003172 /**
3173 * Sets the ImsService Package Name that Telephony will bind to.
3174 *
3175 * @param slotId the slot ID that the ImsService should bind for.
3176 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3177 * ImsService is the device default ImsService.
3178 * @param packageName The package name of the application that contains the ImsService to bind
3179 * to.
3180 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3181 * @hide
3182 */
3183 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003184 int[] subIds = SubscriptionManager.getSubId(slotId);
3185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3186 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3187 "setImsService");
3188
Malcolm Chenaabec062018-02-28 15:00:40 -08003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3192 isCarrierImsService, packageName);
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003196 }
3197
3198 /**
3199 * Return the ImsService configuration.
3200 *
3201 * @param slotId The slot that the ImsService is associated with.
3202 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3203 * the device default.
3204 * @return the package name of the ImsService configuration.
3205 */
3206 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003207 int[] subIds = SubscriptionManager.getSubId(slotId);
3208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3209 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3210 "getImsService");
3211
Malcolm Chenaabec062018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3215 isCarrierImsService);
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003219 }
3220
Wink Saville36469e72014-06-11 15:17:00 -07003221 public void setImsRegistrationState(boolean registered) {
3222 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003223
3224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 mPhone.setImsRegistrationState(registered);
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
Wink Saville36469e72014-06-11 15:17:00 -07003230 }
3231
3232 /**
Stuart Scott54788802015-03-30 13:18:01 -07003233 * Set the network selection mode to automatic.
3234 *
3235 */
3236 @Override
3237 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3239 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003240
3241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3244 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
Stuart Scott54788802015-03-30 13:18:01 -07003248 }
3249
3250 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003251 * Set the network selection mode to manual with the selected carrier.
3252 */
3253 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003254 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003255 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3257 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003258
3259 final long identity = Binder.clearCallingIdentity();
3260 try {
3261 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003262 /* operatorAlphaLong */ "",
3263 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003264 operatorNumeric);
3265 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3266 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3267 persistSelection);
3268 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003272 }
3273
3274 /**
3275 * Scans for available networks.
3276 */
3277 @Override
3278 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3280 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003281
Pengquan Meng0c05b502018-09-06 09:59:22 -07003282 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003283 try {
3284 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003285 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003286 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003290 }
3291
3292 /**
yinxub1bed742017-04-17 11:45:04 -07003293 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003294 *
yinxub1bed742017-04-17 11:45:04 -07003295 * @param subId id of the subscription
3296 * @param request contains the radio access networks with bands/channels to scan
3297 * @param messenger callback messenger for scan results or errors
3298 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003299 * @return the id of the requested scan which can be used to stop the scan.
3300 */
3301 @Override
3302 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3303 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3305 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003306
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 return mNetworkScanRequestTracker.startNetworkScan(
3310 request, messenger, binder, getPhone(subId));
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
yinxu504e1392017-04-12 16:03:22 -07003314 }
3315
3316 /**
3317 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003318 *
3319 * @param subId id of the subscription
3320 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003321 */
3322 @Override
3323 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3325 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
yinxu504e1392017-04-12 16:03:22 -07003333 }
3334
3335 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003336 * Get the calculated preferred network type.
3337 * Used for debugging incorrect network type.
3338 *
3339 * @return the preferred network type, defined in RILConstants.java.
3340 */
3341 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003342 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003344 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003345 return RILConstants.PREFERRED_NETWORK_MODE;
3346 }
3347
Malcolm Chenaabec062018-02-28 15:00:40 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 // FIXME: need to get SubId from somewhere.
3351 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
Junda Liu84d15a22014-07-02 11:21:04 -07003355 }
3356
3357 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003358 * Get the preferred network type.
3359 * Used for device configuration by some CDMA operators.
3360 *
3361 * @return the preferred network type, defined in RILConstants.java.
3362 */
3363 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003364 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3366 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003367
3368 final long identity = Binder.clearCallingIdentity();
3369 try {
3370 if (DBG) log("getPreferredNetworkType");
3371 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3372 int networkType = (result != null ? result[0] : -1);
3373 if (DBG) log("getPreferredNetworkType: " + networkType);
3374 return networkType;
3375 } finally {
3376 Binder.restoreCallingIdentity(identity);
3377 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003378 }
3379
3380 /**
3381 * Set the preferred network type.
3382 * Used for device configuration by some CDMA operators.
3383 *
3384 * @param networkType the preferred network type, defined in RILConstants.java.
3385 * @return true on success; false on any failure.
3386 */
3387 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003388 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3390 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003391
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3395 Boolean success = (Boolean) sendRequest(
3396 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3397 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3398 if (success) {
3399 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3400 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3401 }
3402 return success;
3403 } finally {
3404 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003405 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003406 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003407
3408 /**
Junda Liu475951f2014-11-07 16:45:03 -08003409 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3410 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3411 * tethering.
3412 *
3413 * @return 0: Not required. 1: required. 2: Not set.
3414 * @hide
3415 */
3416 @Override
3417 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003418 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003419
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3423 Settings.Global.TETHER_DUN_REQUIRED, 2);
3424 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3425 // config_tether_apndata.
3426 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3427 dunRequired = 1;
3428 }
3429 return dunRequired;
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003432 }
Junda Liu475951f2014-11-07 16:45:03 -08003433 }
3434
3435 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003436 * Set mobile data enabled
3437 * Used by the user through settings etc to turn on/off mobile data
3438 *
3439 * @param enable {@code true} turn turn data on, else {@code false}
3440 */
3441 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003442 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3444 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003445
3446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 int phoneId = mSubscriptionController.getPhoneId(subId);
3449 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3450 Phone phone = PhoneFactory.getPhone(phoneId);
3451 if (phone != null) {
3452 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3453 phone.setUserDataEnabled(enable);
3454 } else {
3455 loge("setUserDataEnabled: no phone for subId=" + subId);
3456 }
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003459 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003460 }
3461
3462 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003463 * Get the user enabled state of Mobile Data.
3464 *
3465 * TODO: remove and use isUserDataEnabled.
3466 * This can't be removed now because some vendor codes
3467 * calls through ITelephony directly while they should
3468 * use TelephonyManager.
3469 *
3470 * @return true on enabled
3471 */
3472 @Override
3473 public boolean getDataEnabled(int subId) {
3474 return isUserDataEnabled(subId);
3475 }
3476
3477 /**
3478 * Get whether mobile data is enabled per user setting.
3479 *
3480 * There are other factors deciding whether mobile data is actually enabled, but they are
3481 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003482 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003483 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003484 *
3485 * @return {@code true} if data is enabled else {@code false}
3486 */
3487 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003488 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003489 try {
3490 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3491 null);
3492 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3494 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003495 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003496
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 int phoneId = mSubscriptionController.getPhoneId(subId);
3500 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3501 Phone phone = PhoneFactory.getPhone(phoneId);
3502 if (phone != null) {
3503 boolean retVal = phone.isUserDataEnabled();
3504 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3505 return retVal;
3506 } else {
3507 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3508 return false;
3509 }
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003512 }
3513 }
3514
3515 /**
3516 * Get whether mobile data is enabled.
3517 *
3518 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3519 * whether mobile data is actually enabled.
3520 *
3521 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3522 *
3523 * @return {@code true} if data is enabled else {@code false}
3524 */
3525 @Override
3526 public boolean isDataEnabled(int subId) {
3527 try {
3528 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3529 null);
3530 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3532 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003533 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 int phoneId = mSubscriptionController.getPhoneId(subId);
3538 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3539 Phone phone = PhoneFactory.getPhone(phoneId);
3540 if (phone != null) {
3541 boolean retVal = phone.isDataEnabled();
3542 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3543 return retVal;
3544 } else {
3545 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3546 return false;
3547 }
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003550 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003551 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003552
3553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003554 public int getCarrierPrivilegeStatus(int subId) {
3555 final Phone phone = getPhone(subId);
3556 if (phone == null) {
3557 loge("getCarrierPrivilegeStatus: Invalid subId");
3558 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3559 }
3560 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003561 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003562 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003563 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3564 }
3565 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003566 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003567 }
Junda Liu29340342014-07-10 15:23:27 -07003568
3569 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003570 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3571 final Phone phone = getPhone(subId);
3572 if (phone == null) {
3573 loge("getCarrierPrivilegeStatus: Invalid subId");
3574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3575 }
3576 UiccProfile profile =
3577 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3578 if (profile == null) {
3579 loge("getCarrierPrivilegeStatus: No UICC");
3580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3581 }
3582 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3583 }
3584
3585 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003586 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003587 if (TextUtils.isEmpty(pkgName))
3588 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003589 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003590 if (card == null) {
3591 loge("checkCarrierPrivilegesForPackage: No UICC");
3592 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3593 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003594 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3595 }
3596
3597 @Override
3598 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003599 if (TextUtils.isEmpty(pkgName))
3600 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003601 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3602 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3603 UiccCard card = UiccController.getInstance().getUiccCard(i);
3604 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003605 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003606 continue;
3607 }
3608
3609 result = card.getCarrierPrivilegeStatus(
3610 mPhone.getContext().getPackageManager(), pkgName);
3611 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3612 break;
3613 }
3614 }
3615
3616 return result;
Junda Liu29340342014-07-10 15:23:27 -07003617 }
Derek Tan89e89d42014-07-08 17:00:10 -07003618
3619 @Override
Junda Liue64de782015-04-16 17:19:16 -07003620 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3621 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3622 loge("phoneId " + phoneId + " is not valid.");
3623 return null;
3624 }
3625 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003626 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003627 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003628 return null ;
3629 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003630 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003631 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003632 }
3633
Amith Yamasani6e118872016-02-19 12:53:51 -08003634 @Override
3635 public List<String> getPackagesWithCarrierPrivileges() {
3636 PackageManager pm = mPhone.getContext().getPackageManager();
3637 List<String> privilegedPackages = new ArrayList<>();
3638 List<PackageInfo> packages = null;
3639 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3640 UiccCard card = UiccController.getInstance().getUiccCard(i);
3641 if (card == null) {
3642 // No UICC in that slot.
3643 continue;
3644 }
3645 if (card.hasCarrierPrivilegeRules()) {
3646 if (packages == null) {
3647 // Only check packages in user 0 for now
3648 packages = pm.getInstalledPackagesAsUser(
3649 PackageManager.MATCH_DISABLED_COMPONENTS
3650 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3651 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3652 }
3653 for (int p = packages.size() - 1; p >= 0; p--) {
3654 PackageInfo pkgInfo = packages.get(p);
3655 if (pkgInfo != null && pkgInfo.packageName != null
3656 && card.getCarrierPrivilegeStatus(pkgInfo)
3657 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3658 privilegedPackages.add(pkgInfo.packageName);
3659 }
3660 }
3661 }
3662 }
3663 return privilegedPackages;
3664 }
3665
Wink Savilleb564aae2014-10-23 10:18:09 -07003666 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003667 final Phone phone = getPhone(subId);
3668 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003669 if (card == null) {
3670 loge("getIccId: No UICC");
3671 return null;
3672 }
3673 String iccId = card.getIccId();
3674 if (TextUtils.isEmpty(iccId)) {
3675 loge("getIccId: ICC ID is null or empty.");
3676 return null;
3677 }
3678 return iccId;
3679 }
3680
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003681 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003682 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3683 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003684 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3685 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003686
Malcolm Chenaabec062018-02-28 15:00:40 -08003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 final String iccId = getIccId(subId);
3690 final Phone phone = getPhone(subId);
3691 if (phone == null) {
3692 return false;
3693 }
3694 final String subscriberId = phone.getSubscriberId();
3695
3696 if (DBG_MERGE) {
3697 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3698 + subscriberId + " to " + number);
3699 }
3700
3701 if (TextUtils.isEmpty(iccId)) {
3702 return false;
3703 }
3704
3705 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3706
3707 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3708 if (alphaTag == null) {
3709 editor.remove(alphaTagPrefKey);
3710 } else {
3711 editor.putString(alphaTagPrefKey, alphaTag);
3712 }
3713
3714 // Record both the line number and IMSI for this ICCID, since we need to
3715 // track all merged IMSIs based on line number
3716 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3717 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3718 if (number == null) {
3719 editor.remove(numberPrefKey);
3720 editor.remove(subscriberPrefKey);
3721 } else {
3722 editor.putString(numberPrefKey, number);
3723 editor.putString(subscriberPrefKey, subscriberId);
3724 }
3725
3726 editor.commit();
3727 return true;
3728 } finally {
3729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003730 }
Derek Tan7226c842014-07-02 17:42:23 -07003731 }
3732
3733 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003734 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003735 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003737 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003738 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003739 return null;
3740 }
Derek Tan97ebb422014-09-05 16:55:38 -07003741
Malcolm Chenaabec062018-02-28 15:00:40 -08003742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 String iccId = getIccId(subId);
3745 if (iccId != null) {
3746 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3747 if (DBG_MERGE) {
3748 log("getLine1NumberForDisplay returning "
3749 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3750 }
3751 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003752 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003753 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3754 return null;
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003757 }
Derek Tan7226c842014-07-02 17:42:23 -07003758 }
3759
3760 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003761 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003763 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003764 return null;
3765 }
Derek Tan97ebb422014-09-05 16:55:38 -07003766
Malcolm Chenaabec062018-02-28 15:00:40 -08003767 final long identity = Binder.clearCallingIdentity();
3768 try {
3769 String iccId = getIccId(subId);
3770 if (iccId != null) {
3771 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3772 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3773 }
3774 return null;
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003777 }
Derek Tan7226c842014-07-02 17:42:23 -07003778 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003779
3780 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003781 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003782 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3783 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003785 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3786 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003787 return null;
3788 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003789
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003790 final long identity = Binder.clearCallingIdentity();
3791 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003792 final Context context = mPhone.getContext();
3793 final TelephonyManager tele = TelephonyManager.from(context);
3794 final SubscriptionManager sub = SubscriptionManager.from(context);
3795
3796 // Figure out what subscribers are currently active
3797 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3798 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3799 // the process, where TelephonyManager was instantiated.
3800 // Otherwise AppOps check will fail.
3801
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003802 final int[] subIds = sub.getActiveSubscriptionIdList();
3803 for (int subId : subIds) {
3804 activeSubscriberIds.add(tele.getSubscriberId(subId));
3805 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003806
3807 // First pass, find a number override for an active subscriber
3808 String mergeNumber = null;
3809 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3810 for (String key : prefs.keySet()) {
3811 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3812 final String subscriberId = (String) prefs.get(key);
3813 if (activeSubscriberIds.contains(subscriberId)) {
3814 final String iccId = key.substring(
3815 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3816 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3817 mergeNumber = (String) prefs.get(numberKey);
3818 if (DBG_MERGE) {
3819 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3820 + " for active subscriber " + subscriberId);
3821 }
3822 if (!TextUtils.isEmpty(mergeNumber)) {
3823 break;
3824 }
3825 }
3826 }
3827 }
3828
3829 // Shortcut when no active merged subscribers
3830 if (TextUtils.isEmpty(mergeNumber)) {
3831 return null;
3832 }
3833
3834 // Second pass, find all subscribers under that line override
3835 final ArraySet<String> result = new ArraySet<>();
3836 for (String key : prefs.keySet()) {
3837 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3838 final String number = (String) prefs.get(key);
3839 if (mergeNumber.equals(number)) {
3840 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3841 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3842 final String subscriberId = (String) prefs.get(subscriberKey);
3843 if (!TextUtils.isEmpty(subscriberId)) {
3844 result.add(subscriberId);
3845 }
3846 }
3847 }
3848 }
3849
3850 final String[] resultArray = result.toArray(new String[result.size()]);
3851 Arrays.sort(resultArray);
3852 if (DBG_MERGE) {
3853 Slog.d(LOG_TAG,
3854 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3855 }
3856 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003857 } finally {
3858 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003859 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003860 }
3861
3862 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003863 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003864 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3865 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003866
3867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 final Phone phone = getPhone(subId);
3870 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003874 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003875
3876 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003877 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003878 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3879 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003881
3882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 final Phone phone = getPhone(subId);
3885 if (phone == null) {
3886 return false;
3887 }
3888 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3889 cdmaNonRoamingList);
3890 } finally {
3891 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003892 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003893 }
3894
3895 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003896 @Deprecated
3897 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3898 enforceModifyPermission();
3899
3900 int returnValue = 0;
3901 try {
vagdevie435a3e2018-08-15 16:01:53 -07003902 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003903 if(result.exception == null) {
3904 if (result.result != null) {
3905 byte[] responseData = (byte[])(result.result);
3906 if(responseData.length > oemResp.length) {
3907 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3908 responseData.length + "bytes. Buffer Size is " +
3909 oemResp.length + "bytes.");
3910 }
3911 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3912 returnValue = responseData.length;
3913 }
3914 } else {
3915 CommandException ex = (CommandException) result.exception;
3916 returnValue = ex.getCommandError().ordinal();
3917 if(returnValue > 0) returnValue *= -1;
3918 }
3919 } catch (RuntimeException e) {
3920 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3921 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3922 if(returnValue > 0) returnValue *= -1;
3923 }
3924
3925 return returnValue;
3926 }
3927
3928 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003929 public void setRadioCapability(RadioAccessFamily[] rafs) {
3930 try {
3931 ProxyController.getInstance().setRadioCapability(rafs);
3932 } catch (RuntimeException e) {
3933 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3934 }
3935 }
3936
3937 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003938 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003939 Phone phone = PhoneFactory.getPhone(phoneId);
3940 if (phone == null) {
3941 return RadioAccessFamily.RAF_UNKNOWN;
3942 }
3943 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003945 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003946 return RadioAccessFamily.RAF_UNKNOWN;
3947 }
3948
Malcolm Chenaabec062018-02-28 15:00:40 -08003949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
3954 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003955 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003956
3957 @Override
3958 public void enableVideoCalling(boolean enable) {
3959 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003960
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003967 }
3968
3969 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003970 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3972 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3973 return false;
3974 }
Svet Ganovb320e182015-04-16 12:30:10 -07003975
Malcolm Chenaabec062018-02-28 15:00:40 -08003976 final long identity = Binder.clearCallingIdentity();
3977 try {
3978 // Check the user preference and the system-level IMS setting. Even if the user has
3979 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3980 // In the long run, we may instead need to check if there exists a connection service
3981 // which can support video calling.
3982 ImsManager imsManager =
3983 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3984 return imsManager.isVtEnabledByPlatform()
3985 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3986 && imsManager.isVtEnabledByUser();
3987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003990 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003991
Andrew Leea1239f22015-03-02 17:44:07 -08003992 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08003993 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
3994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3995 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3996 return false;
3997 }
3998
3999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 CarrierConfigManager configManager =
4002 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4003 return configManager.getConfigForSubId(mPhone.getSubId())
4004 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Andrew Leea1239f22015-03-02 17:44:07 -08004008 }
4009
4010 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004011 public boolean isWorldPhone(int subId, String callingPackage) {
4012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4013 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4014 return false;
4015 }
4016
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 CarrierConfigManager configManager =
4020 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4021 return configManager.getConfigForSubId(mPhone.getSubId())
4022 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
4025 }
Andrew Leea1239f22015-03-02 17:44:07 -08004026 }
4027
Andrew Lee9431b832015-03-09 18:46:45 -07004028 @Override
4029 public boolean isTtyModeSupported() {
4030 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004031 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004032 }
4033
4034 @Override
4035 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
Andrew Lee9431b832015-03-09 18:46:45 -07004042 }
4043
Hall Liu98187582018-01-22 19:15:32 -08004044 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4048 mPhone.getSubId()).getBoolean(
4049 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4050 boolean isDeviceSupported =
4051 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4052 return isCarrierSupported && isDeviceSupported;
4053 } finally {
4054 Binder.restoreCallingIdentity(identity);
4055 }
Hall Liu98187582018-01-22 19:15:32 -08004056 }
4057
Hall Liu3ad5f012018-04-06 16:23:39 -07004058 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 return isRttSupported() && Settings.Secure.getInt(
4062 mPhone.getContext().getContentResolver(),
4063 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004067 }
4068
Sanket Padawe7310cc72015-01-14 09:53:20 -08004069 /**
4070 * Returns the unique device ID of phone, for example, the IMEI for
4071 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4072 *
4073 * <p>Requires Permission:
4074 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4075 */
4076 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004077 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004078 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004079 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004080 return null;
4081 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004082 int subId = phone.getSubId();
4083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4084 mApp, subId, callingPackage, "getDeviceId")) {
4085 return null;
4086 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004087
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 return phone.getDeviceId();
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004094 }
4095
Ping Sunc67b7c22016-03-02 19:16:45 +08004096 /**
4097 * {@hide}
4098 * Returns the IMS Registration Status on a particular subid
4099 *
4100 * @param subId
4101 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004102 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004103 Phone phone = getPhone(subId);
4104 if (phone != null) {
4105 return phone.isImsRegistered();
4106 } else {
4107 return false;
4108 }
4109 }
4110
Santos Cordon7a1885b2015-02-03 11:15:19 -08004111 @Override
4112 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4116 } finally {
4117 Binder.restoreCallingIdentity(identity);
4118 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004119 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004120
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004121 /**
4122 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004123 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004124 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 Phone phone = getPhone(subId);
4128 if (phone != null) {
4129 return phone.isWifiCallingEnabled();
4130 } else {
4131 return false;
4132 }
4133 } finally {
4134 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004135 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004136 }
4137
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004138 /**
4139 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004140 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004141 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 Phone phone = getPhone(subId);
4145 if (phone != null) {
4146 return phone.isVolteEnabled();
4147 } else {
4148 return false;
4149 }
4150 } finally {
4151 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004152 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004153 }
Svet Ganovb320e182015-04-16 12:30:10 -07004154
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004155 /**
4156 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004157 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004158 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 Phone phone = getPhone(subId);
4162 if (phone != null) {
4163 return phone.isVideoEnabled();
4164 } else {
4165 return false;
4166 }
4167 } finally {
4168 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004169 }
4170 }
4171
4172 /**
4173 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4174 * defined in {@link ImsRegistrationImplBase}.
4175 */
4176 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 Phone phone = getPhone(subId);
4180 if (phone != null) {
4181 return phone.getImsRegistrationTech();
4182 } else {
4183 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4184 }
4185 } finally {
4186 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004187 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004188 }
4189
Stuart Scott8eef64f2015-04-08 15:13:54 -07004190 @Override
4191 public void factoryReset(int subId) {
4192 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004193 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4194 return;
4195 }
4196
Svet Ganovcc087f82015-05-12 20:35:54 -07004197 final long identity = Binder.clearCallingIdentity();
4198 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004199 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4200 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004201 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004202 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004203 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4204 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004205 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004206 }
4207 } finally {
4208 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004209 }
4210 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004211
4212 @Override
4213 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004214 final long identity = Binder.clearCallingIdentity();
4215 try {
4216 // We query all subscriptions instead of just the active ones, because
4217 // this might be called early on in the provisioning flow when the
4218 // subscriptions potentially aren't active yet.
4219 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4220 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004221 return null;
4222 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004223
Malcolm Chenaabec062018-02-28 15:00:40 -08004224 // This function may be called very early, say, from the setup wizard, at
4225 // which point we won't have a default subscription set. If that's the case
4226 // we just choose the first, which will be valid in "most cases".
4227 final int defaultSubId = getDefaultSubscription();
4228 SubscriptionInfo info = null;
4229 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4230 info = slist.get(0);
4231 } else {
4232 for (SubscriptionInfo item : slist) {
4233 if (item.getSubscriptionId() == defaultSubId) {
4234 info = item;
4235 break;
4236 }
4237 }
4238
4239 if (info == null) {
4240 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004241 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004242 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004243
Malcolm Chenaabec062018-02-28 15:00:40 -08004244 // Try and fetch the locale from the carrier properties or from the SIM language
4245 // preferences (EF-PL and EF-LI)...
4246 final int mcc = info.getMcc();
4247 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4248 String simLanguage = null;
4249 if (defaultPhone != null) {
4250 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4251 if (localeFromDefaultSim != null) {
4252 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4253 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4254 return localeFromDefaultSim.toLanguageTag();
4255 } else {
4256 simLanguage = localeFromDefaultSim.getLanguage();
4257 }
4258 }
4259 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004260
Malcolm Chenaabec062018-02-28 15:00:40 -08004261 // The SIM language preferences only store a language (e.g. fr = French), not an
4262 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4263 // the SIM and carrier preferences does not include a country we add the country
4264 // determined from the SIM MCC to provide an exact locale.
4265 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4266 simLanguage);
4267 if (mccLocale != null) {
4268 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4269 return mccLocale.toLanguageTag();
4270 }
4271
4272 if (DBG) log("No locale found - returning null");
4273 return null;
4274 } finally {
4275 Binder.restoreCallingIdentity(identity);
4276 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004277 }
4278
4279 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004280 return mSubscriptionController.getAllSubInfoList(
4281 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004282 }
4283
Malcolm Chenaabec062018-02-28 15:00:40 -08004284 /**
4285 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4286 */
4287 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4288 return mSubscriptionController.getActiveSubscriptionInfoList(
4289 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004290 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004291
Chenjie Yu1ba97252018-01-11 18:16:20 -08004292 private final ModemActivityInfo mLastModemActivityInfo =
4293 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4294
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004295 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004296 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4297 * representing the state of the modem.
4298 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004299 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4300 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004301 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004302 */
4303 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004304 public void requestModemActivityInfo(ResultReceiver result) {
4305 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004306 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004307 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004308
Malcolm Chenaabec062018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004311 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004312 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4313 CMD_GET_MODEM_ACTIVITY_INFO,
4314 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004315 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004316 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4317 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4318 mergedTxTimeMs[i] =
4319 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4320 }
4321 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4322 mLastModemActivityInfo.setSleepTimeMillis(
4323 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4324 mLastModemActivityInfo.setIdleTimeMillis(
4325 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4326 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4327 mLastModemActivityInfo.setRxTimeMillis(
4328 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4329 mLastModemActivityInfo.setEnergyUsed(
4330 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004331 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004332 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4333 mLastModemActivityInfo.getSleepTimeMillis(),
4334 mLastModemActivityInfo.getIdleTimeMillis(),
4335 mLastModemActivityInfo.getTxTimeMillis(),
4336 mLastModemActivityInfo.getRxTimeMillis(),
4337 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004338 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004339 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004340 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004341 result.send(0, bundle);
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004344 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004345 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004346
Siddharth Rayc339f892018-06-17 15:02:38 -07004347 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4348 // less than total activity duration.
4349 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4350 if (info == null) {
4351 return false;
4352 }
4353 int activityDurationMs =
4354 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4355 int totalTxTimeMs = 0;
4356 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4357 totalTxTimeMs += info.getTxTimeMillis()[i];
4358 }
4359 return (info.isValid()
4360 && (info.getSleepTimeMillis() <= activityDurationMs)
4361 && (info.getIdleTimeMillis() <= activityDurationMs)
4362 && (info.getRxTimeMillis() <= activityDurationMs)
4363 && (totalTxTimeMs <= activityDurationMs));
4364 }
4365
Jack Yu85bd38a2015-11-09 11:34:32 -08004366 /**
4367 * {@hide}
4368 * Returns the service state information on specified subscription.
4369 */
4370 @Override
4371 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004373 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004374 return null;
4375 }
4376
Malcolm Chenaabec062018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 final Phone phone = getPhone(subId);
4380 if (phone == null) {
4381 return null;
4382 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004383
Malcolm Chenaabec062018-02-28 15:00:40 -08004384 return phone.getServiceState();
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004388 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004389
4390 /**
4391 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4392 *
4393 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4394 * voicemail ringtone.
4395 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4396 * PhoneAccount.
4397 */
4398 @Override
4399 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004400 final long identity = Binder.clearCallingIdentity();
4401 try {
4402 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4403 if (phone == null) {
4404 phone = mPhone;
4405 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004406
Malcolm Chenaabec062018-02-28 15:00:40 -08004407 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004411 }
4412
4413 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004414 * Sets the per-account voicemail ringtone.
4415 *
4416 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4417 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4418 *
4419 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4420 * voicemail ringtone.
4421 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4422 * PhoneAccount.
4423 */
4424 @Override
4425 public void setVoicemailRingtoneUri(String callingPackage,
4426 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4427 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4428 if (!TextUtils.equals(callingPackage,
4429 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4431 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4432 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004433 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004434
4435 final long identity = Binder.clearCallingIdentity();
4436 try {
4437 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4438 if (phone == null) {
4439 phone = mPhone;
4440 }
4441 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4442 } finally {
4443 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004444 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004445 }
4446
4447 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004448 * Returns whether vibration is set for voicemail notification in Phone settings.
4449 *
4450 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4451 * voicemail vibration setting.
4452 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4453 */
4454 @Override
4455 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4459 if (phone == null) {
4460 phone = mPhone;
4461 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004462
Malcolm Chenaabec062018-02-28 15:00:40 -08004463 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004467 }
4468
Youhan Wange64578a2016-05-02 15:32:42 -07004469 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004470 * Sets the per-account voicemail vibration.
4471 *
4472 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4473 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4474 *
4475 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4476 * voicemail vibration setting.
4477 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4478 * specific PhoneAccount.
4479 */
4480 @Override
4481 public void setVoicemailVibrationEnabled(String callingPackage,
4482 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4483 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4484 if (!TextUtils.equals(callingPackage,
4485 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4487 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4488 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004489 }
4490
Malcolm Chenaabec062018-02-28 15:00:40 -08004491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4494 if (phone == null) {
4495 phone = mPhone;
4496 }
4497 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4498 } finally {
4499 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004500 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004501 }
4502
4503 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004504 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4505 *
4506 * @throws SecurityException if the caller does not have the required permission
4507 */
4508 private void enforceReadPrivilegedPermission() {
4509 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4510 null);
4511 }
4512
4513 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004514 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4515 * permission.
4516 *
4517 * @throws SecurityException if the caller does not have the required permission
4518 */
4519 private void enforceSendSmsPermission() {
4520 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4521 }
4522
4523 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004524 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004525 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004526 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004527 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004528 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004529 final long identity = Binder.clearCallingIdentity();
4530 try {
4531 ComponentName componentName =
4532 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4533 if (componentName == null) {
4534 throw new SecurityException(
4535 "Caller not current active visual voicemail package[null]");
4536 }
4537 String vvmPackage = componentName.getPackageName();
4538 if (!callingPackage.equals(vvmPackage)) {
4539 throw new SecurityException("Caller not current active visual voicemail package["
4540 + vvmPackage + "]");
4541 }
4542 } finally {
4543 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004544 }
4545 }
4546
4547 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004548 * Return the application ID for the app type.
4549 *
4550 * @param subId the subscription ID that this request applies to.
4551 * @param appType the uicc app type.
4552 * @return Application ID for specificied app type, or null if no uicc.
4553 */
4554 @Override
4555 public String getAidForAppType(int subId, int appType) {
4556 enforceReadPrivilegedPermission();
4557 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004558
4559 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004560 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004561 if (phone == null) {
4562 return null;
4563 }
4564 String aid = null;
4565 try {
4566 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4567 .getApplicationByType(appType).getAid();
4568 } catch (Exception e) {
4569 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4570 }
4571 return aid;
4572 } finally {
4573 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004574 }
Youhan Wange64578a2016-05-02 15:32:42 -07004575 }
4576
Youhan Wang4001d252016-05-11 10:29:41 -07004577 /**
4578 * Return the Electronic Serial Number.
4579 *
4580 * @param subId the subscription ID that this request applies to.
4581 * @return ESN or null if error.
4582 */
4583 @Override
4584 public String getEsn(int subId) {
4585 enforceReadPrivilegedPermission();
4586 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004587
4588 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004589 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004590 if (phone == null) {
4591 return null;
4592 }
4593 String esn = null;
4594 try {
4595 esn = phone.getEsn();
4596 } catch (Exception e) {
4597 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4598 }
4599 return esn;
4600 } finally {
4601 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004602 }
Youhan Wang4001d252016-05-11 10:29:41 -07004603 }
4604
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004605 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004606 * Return the Preferred Roaming List Version.
4607 *
4608 * @param subId the subscription ID that this request applies to.
4609 * @return PRLVersion or null if error.
4610 */
4611 @Override
4612 public String getCdmaPrlVersion(int subId) {
4613 enforceReadPrivilegedPermission();
4614 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004615
4616 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004617 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004618 if (phone == null) {
4619 return null;
4620 }
4621 String cdmaPrlVersion = null;
4622 try {
4623 cdmaPrlVersion = phone.getCdmaPrlVersion();
4624 } catch (Exception e) {
4625 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4626 }
4627 return cdmaPrlVersion;
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004630 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004631 }
4632
4633 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004634 * Get snapshot of Telephony histograms
4635 * @return List of Telephony histograms
4636 * @hide
4637 */
4638 @Override
4639 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4641 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004642
4643 final long identity = Binder.clearCallingIdentity();
4644 try {
4645 return RIL.getTelephonyRILTimingHistograms();
4646 } finally {
4647 Binder.restoreCallingIdentity(identity);
4648 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004649 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004650
4651 /**
4652 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004653 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004654 * Require system privileges. In the future we may add this to carrier APIs.
4655 *
4656 * @return The number of carriers set successfully, should match length of carriers
4657 */
4658 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004659 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004660 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004661 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004662
Meng Wang9b7c4e92017-02-17 11:41:27 -08004663 if (carriers == null) {
4664 throw new NullPointerException("carriers cannot be null");
4665 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004666
Malcolm Chenaabec062018-02-28 15:00:40 -08004667 final long identity = Binder.clearCallingIdentity();
4668 try {
4669 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004670 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4671 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004672 return retVal[0];
4673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004676 }
4677
4678 /**
4679 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004680 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004681 * Require system privileges. In the future we may add this to carrier APIs.
4682 *
4683 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4684 * means all carriers are allowed.
4685 */
4686 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004687 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004688 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004689 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004690
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004694 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4695 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004699 }
4700
fionaxu59545b42016-05-25 15:53:37 -07004701 /**
4702 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4703 * @param subId the subscription ID that this action applies to.
4704 * @param enabled control enable or disable metered apns.
4705 * {@hide}
4706 */
4707 @Override
4708 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4709 enforceModifyPermission();
4710 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004711
4712 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004713 if (phone == null) {
4714 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4715 return;
4716 }
4717 try {
4718 phone.carrierActionSetMeteredApnsEnabled(enabled);
4719 } catch (Exception e) {
4720 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004721 } finally {
4722 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004723 }
4724 }
4725
4726 /**
4727 * Action set from carrier signalling broadcast receivers to enable/disable radio
4728 * @param subId the subscription ID that this action applies to.
4729 * @param enabled control enable or disable radio.
4730 * {@hide}
4731 */
4732 @Override
4733 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4734 enforceModifyPermission();
4735 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004736
4737 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004738 if (phone == null) {
4739 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4740 return;
4741 }
4742 try {
4743 phone.carrierActionSetRadioEnabled(enabled);
4744 } catch (Exception e) {
4745 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004746 } finally {
4747 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004748 }
4749 }
4750
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004751 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004752 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4753 * network status based on which carrier apps could apply actions accordingly,
4754 * enable/disable default url handler for example.
4755 *
4756 * @param subId the subscription ID that this action applies to.
4757 * @param report control start/stop reporting the default network status.
4758 * {@hide}
4759 */
4760 @Override
4761 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4762 enforceModifyPermission();
4763 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004764
4765 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004766 if (phone == null) {
4767 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4768 return;
4769 }
4770 try {
4771 phone.carrierActionReportDefaultNetworkStatus(report);
4772 } catch (Exception e) {
4773 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004774 } finally {
4775 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004776 }
4777 }
4778
4779 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004780 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4781 * bug report is being generated.
4782 */
4783 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004784 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004785 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4786 != PackageManager.PERMISSION_GRANTED) {
4787 writer.println("Permission Denial: can't dump Phone from pid="
4788 + Binder.getCallingPid()
4789 + ", uid=" + Binder.getCallingUid()
4790 + "without permission "
4791 + android.Manifest.permission.DUMP);
4792 return;
4793 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004794 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004795 }
Jack Yueb89b242016-06-22 13:27:47 -07004796
Brad Ebingerdac2f002018-04-03 15:17:52 -07004797 @Override
4798 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4799 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4800 throws RemoteException {
4801 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4802 }
4803
Jack Yueb89b242016-06-22 13:27:47 -07004804 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004805 * Get aggregated video call data usage since boot.
4806 *
4807 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4808 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004809 * {@hide}
4810 */
4811 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004812 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004813 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4814 null);
4815
Malcolm Chenaabec062018-02-28 15:00:40 -08004816 final long identity = Binder.clearCallingIdentity();
4817 try {
4818 // NetworkStatsService keeps tracking the active network interface and identity. It
4819 // records the delta with the corresponding network identity.
4820 // We just return the total video call data usage snapshot since boot.
4821 Phone phone = getPhone(subId);
4822 if (phone != null) {
4823 return phone.getVtDataUsage(perUidStats);
4824 }
4825 return null;
4826 } finally {
4827 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004828 }
Jack Yueb89b242016-06-22 13:27:47 -07004829 }
Jack Yu75ab2952016-07-08 14:29:33 -07004830
4831 /**
4832 * Policy control of data connection. Usually used when data limit is passed.
4833 * @param enabled True if enabling the data, otherwise disabling.
4834 * @param subId Subscription index
4835 * {@hide}
4836 */
4837 @Override
4838 public void setPolicyDataEnabled(boolean enabled, int subId) {
4839 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004840
4841 final long identity = Binder.clearCallingIdentity();
4842 try {
4843 Phone phone = getPhone(subId);
4844 if (phone != null) {
4845 phone.setPolicyDataEnabled(enabled);
4846 }
4847 } finally {
4848 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004849 }
4850 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004851
4852 /**
4853 * Get Client request stats
4854 * @return List of Client Request Stats
4855 * @hide
4856 */
4857 @Override
4858 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004860 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004861 return null;
4862 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004863 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004864
Malcolm Chenaabec062018-02-28 15:00:40 -08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 if (phone != null) {
4868 return phone.getClientRequestStats();
4869 }
4870
4871 return null;
4872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004875 }
4876
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004877 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004878 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004879 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004880 }
Jack Yueb4124c2017-02-16 15:32:43 -08004881
4882 /**
Grace Chen70990072017-03-24 17:21:30 -07004883 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004884 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004885 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004886 * @param state State of SIM (power down, power up, pass through)
4887 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4888 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4889 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004890 *
4891 **/
4892 @Override
Grace Chen70990072017-03-24 17:21:30 -07004893 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004894 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004895 Phone phone = PhoneFactory.getPhone(slotIndex);
4896
vagdevie435a3e2018-08-15 16:01:53 -07004897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4898
Malcolm Chenaabec062018-02-28 15:00:40 -08004899 final long identity = Binder.clearCallingIdentity();
4900 try {
4901 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07004902 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004903 }
4904 } finally {
4905 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004906 }
4907 }
Shuo Qiandd210312017-04-12 22:11:33 +00004908
Tyler Gunn65d45c22017-06-05 11:22:26 -07004909 private boolean isUssdApiAllowed(int subId) {
4910 CarrierConfigManager configManager =
4911 (CarrierConfigManager) mPhone.getContext().getSystemService(
4912 Context.CARRIER_CONFIG_SERVICE);
4913 if (configManager == null) {
4914 return false;
4915 }
4916 PersistableBundle pb = configManager.getConfigForSubId(subId);
4917 if (pb == null) {
4918 return false;
4919 }
4920 return pb.getBoolean(
4921 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4922 }
4923
Shuo Qiandd210312017-04-12 22:11:33 +00004924 /**
4925 * Check if phone is in emergency callback mode
4926 * @return true if phone is in emergency callback mode
4927 * @param subId sub id
4928 */
goneil9c5f4872017-12-05 14:07:56 -08004929 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004930 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004931 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004932 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004933
4934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 if (phone != null) {
4937 return phone.isInEcm();
4938 } else {
4939 return false;
4940 }
4941 } finally {
4942 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004943 }
4944 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004945
4946 /**
4947 * Get the current signal strength information for the given subscription.
4948 * Because this information is not updated when the device is in a low power state
4949 * it should not be relied-upon to be current.
4950 * @param subId Subscription index
4951 * @return the most recent cached signal strength info from the modem
4952 */
4953 @Override
4954 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004955 final long identity = Binder.clearCallingIdentity();
4956 try {
4957 Phone p = getPhone(subId);
4958 if (p == null) {
4959 return null;
4960 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004961
Malcolm Chenaabec062018-02-28 15:00:40 -08004962 return p.getSignalStrength();
4963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004966 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004967
Pengquan Meng9140aec2018-08-22 14:49:57 -07004968 /**
4969 * Checks if data roaming is enabled on the subscription with id {@code subId}.
4970 *
4971 * <p>Requires one of the following permissions:
4972 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
4973 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
4974 * privileges.
4975 *
4976 * @param subId subscription id
4977 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
4978 * {@code false}.
4979 */
4980 @Override
4981 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07004982 boolean isEnabled = false;
4983 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07004984 try {
4985 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07004986 null /* message */);
4987 Phone phone = getPhone(subId);
4988 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07004989 } catch (Exception e) {
4990 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
4991 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07004994 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07004995 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07004996 }
4997
4998
4999 /**
5000 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5001 *
5002 * <p> Requires permission:
5003 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5004 * privileges.
5005 *
5006 * @param subId subscription id
5007 * @param isEnabled {@code true} means enable, {@code false} means disable.
5008 */
5009 @Override
5010 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005011 final long identity = Binder.clearCallingIdentity();
5012 try {
5013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5014 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005015
Pengquan Meng0c05b502018-09-06 09:59:22 -07005016 Phone phone = getPhone(subId);
5017 if (phone != null) {
5018 phone.setDataRoamingEnabled(isEnabled);
5019 }
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005022 }
5023 }
5024
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005025 @Override
5026 public UiccSlotInfo[] getUiccSlotsInfo() {
5027 enforceReadPrivilegedPermission();
5028
Malcolm Chenaabec062018-02-28 15:00:40 -08005029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005032 if (slots == null) {
5033 Rlog.i(LOG_TAG, "slots is null.");
5034 return null;
5035 }
5036
Malcolm Chenaabec062018-02-28 15:00:40 -08005037 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5038 for (int i = 0; i < slots.length; i++) {
5039 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005040 if (slot == null) {
5041 continue;
5042 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005043
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005044 String cardId;
5045 UiccCard card = slot.getUiccCard();
5046 if (card != null) {
5047 cardId = card.getCardId();
5048 } else {
5049 cardId = slot.getIccId();
5050 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005051
Malcolm Chenaabec062018-02-28 15:00:40 -08005052 int cardState = 0;
5053 switch (slot.getCardState()) {
5054 case CARDSTATE_ABSENT:
5055 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5056 break;
5057 case CARDSTATE_PRESENT:
5058 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5059 break;
5060 case CARDSTATE_ERROR:
5061 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5062 break;
5063 case CARDSTATE_RESTRICTED:
5064 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5065 break;
5066 default:
5067 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005068
Malcolm Chenaabec062018-02-28 15:00:40 -08005069 }
5070
5071 infos[i] = new UiccSlotInfo(
5072 slot.isActive(),
5073 slot.isEuicc(),
5074 cardId,
5075 cardState,
5076 slot.getPhoneId(),
5077 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005078 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005079 return infos;
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005082 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005083 }
5084
5085 @Override
5086 public boolean switchSlots(int[] physicalSlots) {
5087 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005088
5089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
5094 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005095 }
Jack Yu4c988042018-02-27 15:30:01 -08005096
5097 @Override
5098 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5099 enforceModifyPermission();
5100 final Phone phone = getPhone(subId);
5101 if (phone == null) {
5102 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5103 return;
5104 }
5105
Malcolm Chenaabec062018-02-28 15:00:40 -08005106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 phone.setRadioIndicationUpdateMode(filters, mode);
5109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
Jack Yu4c988042018-02-27 15:30:01 -08005112 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005113
5114 /**
goneil47ffb6e2018-04-06 15:40:58 -07005115 * A test API to reload the UICC profile.
5116 *
5117 * <p>Requires that the calling app has permission
5118 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5119 * @hide
5120 */
5121 @Override
5122 public void refreshUiccProfile(int subId) {
5123 enforceModifyPermission();
5124
5125 final long identity = Binder.clearCallingIdentity();
5126 try {
5127 Phone phone = getPhone(subId);
5128 if (phone == null) {
5129 return;
5130 }
5131 UiccCard uiccCard = phone.getUiccCard();
5132 if (uiccCard == null) {
5133 return;
5134 }
5135 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5136 if (uiccProfile == null) {
5137 return;
5138 }
5139 uiccProfile.refresh();
5140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
5143 }
5144
5145 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005146 * Returns false if the mobile data is disabled by default, otherwise return true.
5147 */
5148 private boolean getDefaultDataEnabled() {
5149 return "true".equalsIgnoreCase(
5150 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5151 }
5152
5153 /**
5154 * Returns true if the data roaming is enabled by default, i.e the system property
5155 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5156 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5157 */
5158 private boolean getDefaultDataRoamingEnabled(int subId) {
5159 final CarrierConfigManager configMgr = (CarrierConfigManager)
5160 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5161 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5162 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5163 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5164 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5165 return isDataRoamingEnabled;
5166 }
5167
5168 /**
5169 * Returns the default network type for the given {@code subId}, if the default network type is
5170 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5171 */
5172 private int getDefaultNetworkType(int subId) {
5173 return Integer.parseInt(
5174 TelephonyManager.getTelephonyProperty(
5175 mSubscriptionController.getPhoneId(subId),
5176 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5177 String.valueOf(Phone.PREFERRED_NT_MODE)));
5178 }
fionaxua13278b2018-03-21 00:08:13 -07005179
5180 @Override
5181 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5182 gid1, String gid2, String plmn, String spn) {
5183 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 final Phone phone = getPhone(subId);
5188 if (phone == null) {
5189 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5190 return;
5191 }
5192 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005195 }
fionaxua13278b2018-03-21 00:08:13 -07005196 }
5197
5198 @Override
5199 public int getCarrierIdListVersion(int subId) {
5200 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005201
5202 final long identity = Binder.clearCallingIdentity();
5203 try {
5204 final Phone phone = getPhone(subId);
5205 if (phone == null) {
5206 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5207 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5208 }
5209 return phone.getCarrierIdListVersion();
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005212 }
fionaxua13278b2018-03-21 00:08:13 -07005213 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005214
5215 @Override
5216 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5218 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5219 return -1;
5220 }
5221
5222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
5228 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005229
5230 @Override
5231 public int getCdmaRoamingMode(int subId) {
5232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5233 mApp, subId, "getCdmaRoamingMode");
5234
5235 final long identity = Binder.clearCallingIdentity();
5236 try {
5237 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
5241 }
5242
5243 @Override
5244 public boolean setCdmaRoamingMode(int subId, int mode) {
5245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5246 mApp, subId, "setCdmaRoamingMode");
5247
5248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
5254 }
5255
5256 @Override
5257 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5259 mApp, subId, "setCdmaSubscriptionMode");
5260
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
5267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005268}