blob: 90d79241b8f428cfd51834dfbcd125fb06335233 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070045import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070046import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070048import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070049import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070050import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070052import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080053import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080054import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070055import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070056import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070058import android.telephony.CellInfoGsm;
59import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070060import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070061import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080062import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070063import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080064import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070065import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070066import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070067import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080069import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070070import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080071import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080072import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070073import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000075import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070076import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080078import android.telephony.ims.aidl.IImsConfig;
79import android.telephony.ims.aidl.IImsMmTelFeature;
80import android.telephony.ims.aidl.IImsRcsFeature;
81import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080082import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080085import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080087import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080089
Andrew Lee312e8172014-10-23 17:01:36 -070090import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080091import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070092import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070093import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070094import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070095import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070096import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080099import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700100import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100101import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700102import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700103import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.Phone;
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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150 private static final int CMD_ANSWER_RINGING_CALL = 4;
151 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700152 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
153 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154 private static final int CMD_OPEN_CHANNEL = 9;
155 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
156 private static final int CMD_CLOSE_CHANNEL = 11;
157 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800158 private static final int CMD_NV_READ_ITEM = 13;
159 private static final int EVENT_NV_READ_ITEM_DONE = 14;
160 private static final int CMD_NV_WRITE_ITEM = 15;
161 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
162 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
163 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
164 private static final int CMD_NV_RESET_CONFIG = 19;
165 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800166 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
167 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
168 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
169 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800170 private static final int CMD_SEND_ENVELOPE = 25;
171 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000172 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
173 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700174 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
175 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
176 private static final int CMD_EXCHANGE_SIM_IO = 31;
177 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800178 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
179 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700180 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
181 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700182 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
183 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700184 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
185 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
186 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
187 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700188 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
189 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
190 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
191 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700192 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800193 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
194 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195 private static final int CMD_SWITCH_SLOTS = 50;
196 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800198 // Parameters of select command.
199 private static final int SELECT_COMMAND = 0xA4;
200 private static final int SELECT_P1 = 0x04;
201 private static final int SELECT_P2 = 0;
202 private static final int SELECT_P3 = 0x10;
203
Pengquan Meng85728fb2018-03-12 16:31:21 -0700204 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
205 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
206 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
207
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 /** The singleton instance. */
209 private static PhoneInterfaceManager sInstance;
210
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private PhoneGlobals mApp;
212 private Phone mPhone;
213 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700214 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800215 private AppOpsManager mAppOps;
216 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800217 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800218 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
Derek Tan97ebb422014-09-05 16:55:38 -0700220 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
221 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700223
Derek Tan740e1672017-06-27 14:56:27 -0700224 // The AID of ISD-R.
225 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
226
yinxub1bed742017-04-17 11:45:04 -0700227 private NetworkScanRequestTracker mNetworkScanRequestTracker;
228
David Kelly5e06a7f2018-03-12 14:10:59 +0000229 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
230 private static final int MANUFACTURER_CODE_LENGTH = 8;
231
Derek Tan89e89d42014-07-08 17:00:10 -0700232 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700233 * A request object to use for transmitting data to an ICC.
234 */
235 private static final class IccAPDUArgument {
236 public int channel, cla, command, p1, p2, p3;
237 public String data;
238
239 public IccAPDUArgument(int channel, int cla, int command,
240 int p1, int p2, int p3, String data) {
241 this.channel = channel;
242 this.cla = cla;
243 this.command = command;
244 this.p1 = p1;
245 this.p2 = p2;
246 this.p3 = p3;
247 this.data = data;
248 }
249 }
250
251 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700252 * A request object to use for transmitting data to an ICC.
253 */
254 private static final class ManualNetworkSelectionArgument {
255 public OperatorInfo operatorInfo;
256 public boolean persistSelection;
257
258 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
259 this.operatorInfo = operatorInfo;
260 this.persistSelection = persistSelection;
261 }
262 }
263
264 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
266 * request after sending. The main thread will notify the request when it is complete.
267 */
268 private static final class MainThreadRequest {
269 /** The argument to use for the request */
270 public Object argument;
271 /** The result of the request that is run on the main thread */
272 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800273 // The subscriber id that this request applies to. Defaults to
274 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
275 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276
277 public MainThreadRequest(Object argument) {
278 this.argument = argument;
279 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280
281 public MainThreadRequest(Object argument, Integer subId) {
282 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800283 if (subId != null) {
284 this.subId = subId;
285 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 }
288
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800289 private static final class IncomingThirdPartyCallArgs {
290 public final ComponentName component;
291 public final String callId;
292 public final String callerDisplayName;
293
294 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
295 String callerDisplayName) {
296 this.component = component;
297 this.callId = callId;
298 this.callerDisplayName = callerDisplayName;
299 }
300 }
301
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 /**
303 * A handler that processes messages on the main thread in the phone process. Since many
304 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
305 * inbound binder threads to the main thread in the phone process. The Binder thread
306 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
307 * on, which will be notified when the operation completes and will contain the result of the
308 * request.
309 *
310 * <p>If a MainThreadRequest object is provided in the msg.obj field,
311 * note that request.result must be set to something non-null for the calling thread to
312 * unblock.
313 */
314 private final class MainThreadHandler extends Handler {
315 @Override
316 public void handleMessage(Message msg) {
317 MainThreadRequest request;
318 Message onCompleted;
319 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800320 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700321 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322
323 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700324 case CMD_HANDLE_USSD_REQUEST: {
325 request = (MainThreadRequest) msg.obj;
326 final Phone phone = getPhoneFromRequest(request);
327 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
328 String ussdRequest = ussdObject.first;
329 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700330
331 if (!isUssdApiAllowed(request.subId)) {
332 // Carrier does not support use of this API, return failure.
333 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
334 UssdResponse response = new UssdResponse(ussdRequest, null);
335 Bundle returnData = new Bundle();
336 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
337 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
338
339 request.result = true;
340 synchronized (request) {
341 request.notifyAll();
342 }
343 return;
344 }
345
Tyler Gunn52dcf772017-04-26 11:30:31 -0700346 try {
347 request.result = phone != null ?
348 phone.handleUssdRequest(ussdRequest, wrappedCallback)
349 : false;
350 } catch (CallStateException cse) {
351 request.result = false;
352 }
pkanwar32d516d2016-10-14 19:37:38 -0700353 // Wake up the requesting thread
354 synchronized (request) {
355 request.notifyAll();
356 }
357 break;
358 }
359
Yorke Lee716f67e2015-06-17 15:39:16 -0700360 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700362 final Phone phone = getPhoneFromRequest(request);
363 request.result = phone != null ?
364 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
365 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 // Wake up the requesting thread
367 synchronized (request) {
368 request.notifyAll();
369 }
370 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700374 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800375 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700376 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800377 request.result = ""; // dummy result for notifying the waiting thread
378 // Wake up the requesting thread
379 synchronized (request) {
380 request.notifyAll();
381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 break;
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 case CMD_END_CALL:
385 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800386 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700387 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700388 Phone phone = getPhone(end_subId);
389 if (phone == null) {
390 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
391 break;
392 }
393 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
395 // CDMA: If the user presses the Power button we treat it as
396 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700397 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
399 // GSM: End the call as per the Phone state
400 hungUp = PhoneUtils.hangup(mCM);
401 } else {
402 throw new IllegalStateException("Unexpected phone type: " + phoneType);
403 }
404 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
405 request.result = hungUp;
406 // Wake up the requesting thread
407 synchronized (request) {
408 request.notifyAll();
409 }
410 break;
411
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700413 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 if (uiccCard == null) {
417 loge("iccTransmitApduLogicalChannel: No UICC");
418 request.result = new IccIoResult(0x6F, 0, (byte[])null);
419 synchronized (request) {
420 request.notifyAll();
421 }
422 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
424 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 iccArgument.channel, iccArgument.cla, iccArgument.command,
427 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 break;
431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 ar = (AsyncResult) msg.obj;
434 request = (MainThreadRequest) ar.userObj;
435 if (ar.exception == null && ar.result != null) {
436 request.result = ar.result;
437 } else {
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
439 if (ar.result == null) {
440 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800441 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800443 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 } else {
445 loge("iccTransmitApduLogicalChannel: Unknown exception");
446 }
447 }
448 synchronized (request) {
449 request.notifyAll();
450 }
451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
454 request = (MainThreadRequest) msg.obj;
455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduBasicChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
460 synchronized (request) {
461 request.notifyAll();
462 }
463 } else {
464 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
465 request);
466 uiccCard.iccTransmitApduBasicChannel(
467 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
468 iccArgument.p3, iccArgument.data, onCompleted);
469 }
470 break;
471
472 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
473 ar = (AsyncResult) msg.obj;
474 request = (MainThreadRequest) ar.userObj;
475 if (ar.exception == null && ar.result != null) {
476 request.result = ar.result;
477 } else {
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 if (ar.result == null) {
480 loge("iccTransmitApduBasicChannel: Empty response");
481 } else if (ar.exception instanceof CommandException) {
482 loge("iccTransmitApduBasicChannel: CommandException: " +
483 ar.exception);
484 } else {
485 loge("iccTransmitApduBasicChannel: Unknown exception");
486 }
487 }
488 synchronized (request) {
489 request.notifyAll();
490 }
491 break;
492
493 case CMD_EXCHANGE_SIM_IO:
494 request = (MainThreadRequest) msg.obj;
495 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800496 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 if (uiccCard == null) {
498 loge("iccExchangeSimIO: No UICC");
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
500 synchronized (request) {
501 request.notifyAll();
502 }
503 } else {
504 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
505 request);
506 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
507 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
508 iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_EXCHANGE_SIM_IO_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6f, 0, (byte[])null);
519 }
520 synchronized (request) {
521 request.notifyAll();
522 }
523 break;
524
Derek Tan4d5e5c12014-02-04 11:54:58 -0800525 case CMD_SEND_ENVELOPE:
526 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 if (uiccCard == null) {
529 loge("sendEnvelopeWithStatus: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
531 synchronized (request) {
532 request.notifyAll();
533 }
534 } else {
535 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
536 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
537 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 break;
539
540 case EVENT_SEND_ENVELOPE_DONE:
541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("sendEnvelopeWithStatus: Empty response");
549 } else if (ar.exception instanceof CommandException) {
550 loge("sendEnvelopeWithStatus: CommandException: " +
551 ar.exception);
552 } else {
553 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
554 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 }
556 synchronized (request) {
557 request.notifyAll();
558 }
559 break;
560
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 case CMD_OPEN_CHANNEL:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800564 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800567 request.result = new IccOpenLogicalChannelResponse(-1,
568 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 synchronized (request) {
570 request.notifyAll();
571 }
572 } else {
573 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
575 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 break;
578
579 case EVENT_OPEN_CHANNEL_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 int[] result = (int[]) ar.result;
585 int channelId = result[0];
586 byte[] selectResponse = null;
587 if (result.length > 1) {
588 selectResponse = new byte[result.length - 1];
589 for (int i = 1; i < result.length; ++i) {
590 selectResponse[i - 1] = (byte) result[i];
591 }
592 }
593 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 if (ar.result == null) {
597 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 if (ar.exception != null) {
600 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
601 }
602
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700603 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700604 if (ar.exception instanceof CommandException) {
605 CommandException.Error error =
606 ((CommandException) (ar.exception)).getCommandError();
607 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700609 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 }
612 }
613 openChannelResp = new IccOpenLogicalChannelResponse(
614 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700616 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 synchronized (request) {
618 request.notifyAll();
619 }
620 break;
621
622 case CMD_CLOSE_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 if (uiccCard == null) {
626 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900627 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 synchronized (request) {
629 request.notifyAll();
630 }
631 } else {
632 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
633 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
637 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800638 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
639 break;
640
641 case CMD_NV_READ_ITEM:
642 request = (MainThreadRequest) msg.obj;
643 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
644 mPhone.nvReadItem((Integer) request.argument, onCompleted);
645 break;
646
647 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 ar = (AsyncResult) msg.obj;
649 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800650 if (ar.exception == null && ar.result != null) {
651 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800653 request.result = "";
654 if (ar.result == null) {
655 loge("nvReadItem: Empty response");
656 } else if (ar.exception instanceof CommandException) {
657 loge("nvReadItem: CommandException: " +
658 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800660 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 }
662 }
663 synchronized (request) {
664 request.notifyAll();
665 }
666 break;
667
Jake Hambye994d462014-02-03 13:10:13 -0800668 case CMD_NV_WRITE_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
671 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
672 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
673 break;
674
675 case EVENT_NV_WRITE_ITEM_DONE:
676 handleNullReturnEvent(msg, "nvWriteItem");
677 break;
678
679 case CMD_NV_WRITE_CDMA_PRL:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
682 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
683 break;
684
685 case EVENT_NV_WRITE_CDMA_PRL_DONE:
686 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
687 break;
688
689 case CMD_NV_RESET_CONFIG:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
692 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
693 break;
694
695 case EVENT_NV_RESET_CONFIG_DONE:
696 handleNullReturnEvent(msg, "nvResetConfig");
697 break;
698
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 case CMD_GET_PREFERRED_NETWORK_TYPE:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700702 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 break;
704
705 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result; // Integer
710 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800711 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 if (ar.result == null) {
713 loge("getPreferredNetworkType: Empty response");
714 } else if (ar.exception instanceof CommandException) {
715 loge("getPreferredNetworkType: CommandException: " +
716 ar.exception);
717 } else {
718 loge("getPreferredNetworkType: Unknown exception");
719 }
720 }
721 synchronized (request) {
722 request.notifyAll();
723 }
724 break;
725
726 case CMD_SET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
729 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
734 handleNullReturnEvent(msg, "setPreferredNetworkType");
735 break;
736
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000737 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
738 request = (MainThreadRequest)msg.obj;
739 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
740 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
741 break;
742
743 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
744 ar = (AsyncResult)msg.obj;
745 request = (MainThreadRequest)ar.userObj;
746 request.result = ar;
747 synchronized (request) {
748 request.notifyAll();
749 }
750 break;
751
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800752 case CMD_SET_VOICEMAIL_NUMBER:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
755 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800756 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
757 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800758 break;
759
760 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
761 handleNullReturnEvent(msg, "setVoicemailNumber");
762 break;
763
Stuart Scott54788802015-03-30 13:18:01 -0700764 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
767 request);
768 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
769 break;
770
771 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
772 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
773 break;
774
Shishir Agrawal302c8692015-06-19 13:49:39 -0700775 case CMD_PERFORM_NETWORK_SCAN:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
778 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
779 break;
780
781 case EVENT_PERFORM_NETWORK_SCAN_DONE:
782 ar = (AsyncResult) msg.obj;
783 request = (MainThreadRequest) ar.userObj;
784 CellNetworkScanResult cellScanResult;
785 if (ar.exception == null && ar.result != null) {
786 cellScanResult = new CellNetworkScanResult(
787 CellNetworkScanResult.STATUS_SUCCESS,
788 (List<OperatorInfo>) ar.result);
789 } else {
790 if (ar.result == null) {
791 loge("getCellNetworkScanResults: Empty response");
792 }
793 if (ar.exception != null) {
794 loge("getCellNetworkScanResults: Exception: " + ar.exception);
795 }
796 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
797 if (ar.exception instanceof CommandException) {
798 CommandException.Error error =
799 ((CommandException) (ar.exception)).getCommandError();
800 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
801 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
802 } else if (error == CommandException.Error.GENERIC_FAILURE) {
803 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
804 }
805 }
806 cellScanResult = new CellNetworkScanResult(errorCode, null);
807 }
808 request.result = cellScanResult;
809 synchronized (request) {
810 request.notifyAll();
811 }
812 break;
813
814 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
815 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700816 ManualNetworkSelectionArgument selArg =
817 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
819 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700820 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
821 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700822 break;
823
824 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
825 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
826 break;
827
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700828 case CMD_GET_MODEM_ACTIVITY_INFO:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700831 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700832 break;
833
834 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 if (ar.result == null) {
841 loge("queryModemActivityInfo: Empty response");
842 } else if (ar.exception instanceof CommandException) {
843 loge("queryModemActivityInfo: CommandException: " +
844 ar.exception);
845 } else {
846 loge("queryModemActivityInfo: Unknown exception");
847 }
848 }
Amit Mahajand4766222016-01-28 15:28:28 -0800849 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
850 if (request.result == null) {
851 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
852 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700853 synchronized (request) {
854 request.notifyAll();
855 }
856 break;
857
Meng Wang1a7c35a2016-05-05 20:56:15 -0700858 case CMD_SET_ALLOWED_CARRIERS:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
861 mPhone.setAllowedCarriers(
862 (List<CarrierIdentifier>) request.argument,
863 onCompleted);
864 break;
865
866 case EVENT_SET_ALLOWED_CARRIERS_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
872 if (ar.result == null) {
873 loge("setAllowedCarriers: Empty response");
874 } else if (ar.exception instanceof CommandException) {
875 loge("setAllowedCarriers: CommandException: " +
876 ar.exception);
877 } else {
878 loge("setAllowedCarriers: Unknown exception");
879 }
880 }
881 // Result cannot be null. Return -1 on error.
882 if (request.result == null) {
883 request.result = new int[]{-1};
884 }
885 synchronized (request) {
886 request.notifyAll();
887 }
888 break;
889
890 case CMD_GET_ALLOWED_CARRIERS:
891 request = (MainThreadRequest) msg.obj;
892 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
893 mPhone.getAllowedCarriers(onCompleted);
894 break;
895
896 case EVENT_GET_ALLOWED_CARRIERS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
902 if (ar.result == null) {
903 loge("getAllowedCarriers: Empty response");
904 } else if (ar.exception instanceof CommandException) {
905 loge("getAllowedCarriers: CommandException: " +
906 ar.exception);
907 } else {
908 loge("getAllowedCarriers: Unknown exception");
909 }
910 }
911 // Result cannot be null. Return empty list of CarrierIdentifier.
912 if (request.result == null) {
913 request.result = new ArrayList<CarrierIdentifier>(0);
914 }
915 synchronized (request) {
916 request.notifyAll();
917 }
918 break;
919
Nathan Haroldb3014052017-01-25 15:57:32 -0800920 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
921 ar = (AsyncResult) msg.obj;
922 request = (MainThreadRequest) ar.userObj;
923 if (ar.exception == null && ar.result != null) {
924 request.result = ar.result;
925 } else {
926 request.result = new IllegalArgumentException(
927 "Failed to retrieve Forbidden Plmns");
928 if (ar.result == null) {
929 loge("getForbiddenPlmns: Empty response");
930 } else {
931 loge("getForbiddenPlmns: Unknown exception");
932 }
933 }
934 synchronized (request) {
935 request.notifyAll();
936 }
937 break;
938
939 case CMD_GET_FORBIDDEN_PLMNS:
940 request = (MainThreadRequest) msg.obj;
941 uiccCard = getUiccCardFromRequest(request);
942 if (uiccCard == null) {
943 loge("getForbiddenPlmns() UiccCard is null");
944 request.result = new IllegalArgumentException(
945 "getForbiddenPlmns() UiccCard is null");
946 synchronized (request) {
947 request.notifyAll();
948 }
949 break;
950 }
951 Integer appType = (Integer) request.argument;
952 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
953 if (uiccApp == null) {
954 loge("getForbiddenPlmns() no app with specified type -- "
955 + appType);
956 request.result = new IllegalArgumentException("Failed to get UICC App");
957 synchronized (request) {
958 request.notifyAll();
959 }
960 break;
961 } else {
962 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
963 + " specified type -- " + appType);
964 }
965 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
966 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
967 onCompleted);
968 break;
969
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000970 case CMD_SWITCH_SLOTS:
971 request = (MainThreadRequest) msg.obj;
972 int[] physicalSlots = (int[]) request.argument;
973 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
974 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
975 break;
976
977 case EVENT_SWITCH_SLOTS_DONE:
978 ar = (AsyncResult) msg.obj;
979 request = (MainThreadRequest) ar.userObj;
980 request.result = (ar.exception == null);
981 synchronized (request) {
982 request.notifyAll();
983 }
984 break;
985
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700986 default:
987 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
988 break;
989 }
990 }
Jake Hambye994d462014-02-03 13:10:13 -0800991
992 private void handleNullReturnEvent(Message msg, String command) {
993 AsyncResult ar = (AsyncResult) msg.obj;
994 MainThreadRequest request = (MainThreadRequest) ar.userObj;
995 if (ar.exception == null) {
996 request.result = true;
997 } else {
998 request.result = false;
999 if (ar.exception instanceof CommandException) {
1000 loge(command + ": CommandException: " + ar.exception);
1001 } else {
1002 loge(command + ": Unknown exception");
1003 }
1004 }
1005 synchronized (request) {
1006 request.notifyAll();
1007 }
1008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001009 }
1010
1011 /**
1012 * Posts the specified command to be executed on the main thread,
1013 * waits for the request to complete, and returns the result.
1014 * @see #sendRequestAsync
1015 */
1016 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001017 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001018 }
1019
1020 /**
1021 * Posts the specified command to be executed on the main thread,
1022 * waits for the request to complete, and returns the result.
1023 * @see #sendRequestAsync
1024 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001025 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1027 throw new RuntimeException("This method will deadlock if called from the main thread.");
1028 }
1029
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001030 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001031 Message msg = mMainThreadHandler.obtainMessage(command, request);
1032 msg.sendToTarget();
1033
1034 // Wait for the request to complete
1035 synchronized (request) {
1036 while (request.result == null) {
1037 try {
1038 request.wait();
1039 } catch (InterruptedException e) {
1040 // Do nothing, go back and wait until the request is complete
1041 }
1042 }
1043 }
1044 return request.result;
1045 }
1046
1047 /**
1048 * Asynchronous ("fire and forget") version of sendRequest():
1049 * Posts the specified command to be executed on the main thread, and
1050 * returns immediately.
1051 * @see #sendRequest
1052 */
1053 private void sendRequestAsync(int command) {
1054 mMainThreadHandler.sendEmptyMessage(command);
1055 }
1056
1057 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001058 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1059 * @see {@link #sendRequest(int,Object)}
1060 */
1061 private void sendRequestAsync(int command, Object argument) {
1062 MainThreadRequest request = new MainThreadRequest(argument);
1063 Message msg = mMainThreadHandler.obtainMessage(command, request);
1064 msg.sendToTarget();
1065 }
1066
1067 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068 * Initialize the singleton PhoneInterfaceManager instance.
1069 * This is only done once, at startup, from PhoneApp.onCreate().
1070 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001071 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001072 synchronized (PhoneInterfaceManager.class) {
1073 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001074 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001075 } else {
1076 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1077 }
1078 return sInstance;
1079 }
1080 }
1081
1082 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001083 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 mApp = app;
1085 mPhone = phone;
1086 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001087 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001088 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1089 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001090 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001091 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001092 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001093 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001094
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 publish();
1096 }
1097
1098 private void publish() {
1099 if (DBG) log("publish: " + this);
1100
1101 ServiceManager.addService("phone", this);
1102 }
1103
Stuart Scott584921c2015-01-15 17:10:34 -08001104 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001105 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1106 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001107 }
1108
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001109 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1110 Phone phone = getPhoneFromRequest(request);
1111 return phone == null ? null :
1112 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1113 }
1114
Wink Saville36469e72014-06-11 15:17:00 -07001115 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001116 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001117 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001119 //
1120 // Implementation of the ITelephony interface.
1121 //
1122
1123 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001124 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001125 }
1126
Wink Savilleb564aae2014-10-23 10:18:09 -07001127 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001128 if (DBG) log("dial: " + number);
1129 // No permission check needed here: This is just a wrapper around the
1130 // ACTION_DIAL intent, which is available to any app since it puts up
1131 // the UI before it does anything.
1132
Malcolm Chenaabec062018-02-28 15:00:40 -08001133 final long identity = Binder.clearCallingIdentity();
1134 try {
1135 String url = createTelUrl(number);
1136 if (url == null) {
1137 return;
1138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139
Malcolm Chenaabec062018-02-28 15:00:40 -08001140 // PENDING: should we just silently fail if phone is offhook or ringing?
1141 PhoneConstants.State state = mCM.getState(subId);
1142 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1143 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1144 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1145 mApp.startActivity(intent);
1146 }
1147 } finally {
1148 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001149 }
1150 }
1151
1152 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001153 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001154 }
1155
Wink Savilleb564aae2014-10-23 10:18:09 -07001156 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001157 if (DBG) log("call: " + number);
1158
1159 // This is just a wrapper around the ACTION_CALL intent, but we still
1160 // need to do a permission check since we're calling startActivity()
1161 // from the context of the phone app.
1162 enforceCallPermission();
1163
1164 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1165 != AppOpsManager.MODE_ALLOWED) {
1166 return;
1167 }
1168
Malcolm Chenaabec062018-02-28 15:00:40 -08001169 final long identity = Binder.clearCallingIdentity();
1170 try {
1171 String url = createTelUrl(number);
1172 if (url == null) {
1173 return;
1174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175
Malcolm Chenaabec062018-02-28 15:00:40 -08001176 boolean isValid = false;
1177 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1178 if (slist != null) {
1179 for (SubscriptionInfo subInfoRecord : slist) {
1180 if (subInfoRecord.getSubscriptionId() == subId) {
1181 isValid = true;
1182 break;
1183 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001184 }
Wink Saville08874612014-08-31 19:19:58 -07001185 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001186 if (!isValid) {
1187 return;
1188 }
Wink Saville08874612014-08-31 19:19:58 -07001189
Malcolm Chenaabec062018-02-28 15:00:40 -08001190 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1191 intent.putExtra(SUBSCRIPTION_KEY, subId);
1192 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1193 mApp.startActivity(intent);
1194 } finally {
1195 Binder.restoreCallingIdentity(identity);
1196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 }
1198
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 /**
1200 * End a call based on call state
1201 * @return true is a call was ended
1202 */
1203 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001204 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001205 }
1206
1207 /**
1208 * End a call based on the call state of the subId
1209 * @return true is a call was ended
1210 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001211 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001212 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1213 != PackageManager.PERMISSION_GRANTED) {
1214 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1215 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1216 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1217 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001218 final long identity = Binder.clearCallingIdentity();
1219 try {
1220 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1221 } finally {
1222 Binder.restoreCallingIdentity(identity);
1223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001224 }
1225
1226 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001227 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001228 }
1229
Wink Savilleb564aae2014-10-23 10:18:09 -07001230 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 if (DBG) log("answerRingingCall...");
1232 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1233 // but that can probably wait till the big TelephonyManager API overhaul.
1234 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1235 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001236
1237 final long identity = Binder.clearCallingIdentity();
1238 try {
1239 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1240 } finally {
1241 Binder.restoreCallingIdentity(identity);
1242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 }
1244
1245 /**
1246 * Make the actual telephony calls to implement answerRingingCall().
1247 * This should only be called from the main thread of the Phone app.
1248 * @see #answerRingingCall
1249 *
1250 * TODO: it would be nice to return true if we answered the call, or
1251 * false if there wasn't actually a ringing incoming call, or some
1252 * other error occurred. (In other words, pass back the return value
1253 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1254 * But that would require calling this method via sendRequest() rather
1255 * than sendRequestAsync(), and right now we don't actually *need* that
1256 * return value, so let's just return void for now.
1257 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001258 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001259 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001261 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1262 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 if (hasActiveCall && hasHoldingCall) {
1264 // Both lines are in use!
1265 // TODO: provide a flag to let the caller specify what
1266 // policy to use if both lines are in use. (The current
1267 // behavior is hardwired to "answer incoming, end ongoing",
1268 // which is how the CALL button is specced to behave.)
1269 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1270 return;
1271 } else {
1272 // answerCall() will automatically hold the current active
1273 // call, if there is one.
1274 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1275 return;
1276 }
1277 } else {
1278 // No call was ringing.
1279 return;
1280 }
1281 }
1282
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001284 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001286 public void silenceRinger() {
1287 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 }
1289
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001290 @Override
1291 public boolean isOffhook(String callingPackage) {
1292 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001293 }
1294
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001295 @Override
1296 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001298 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001299 return false;
1300 }
1301
Malcolm Chenaabec062018-02-28 15:00:40 -08001302 final long identity = Binder.clearCallingIdentity();
1303 try {
1304 final Phone phone = getPhone(subId);
1305 if (phone != null) {
1306 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1307 } else {
1308 return false;
1309 }
1310 } finally {
1311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 }
1314
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001315 @Override
1316 public boolean isRinging(String callingPackage) {
1317 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001318 }
1319
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001320 @Override
1321 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001323 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001324 return false;
1325 }
1326
Malcolm Chenaabec062018-02-28 15:00:40 -08001327 final long identity = Binder.clearCallingIdentity();
1328 try {
1329 final Phone phone = getPhone(subId);
1330 if (phone != null) {
1331 return (phone.getState() == PhoneConstants.State.RINGING);
1332 } else {
1333 return false;
1334 }
1335 } finally {
1336 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 }
1339
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001340 @Override
1341 public boolean isIdle(String callingPackage) {
1342 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001343 }
1344
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001345 @Override
1346 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001348 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001349 return false;
1350 }
1351
Malcolm Chenaabec062018-02-28 15:00:40 -08001352 final long identity = Binder.clearCallingIdentity();
1353 try {
1354 final Phone phone = getPhone(subId);
1355 if (phone != null) {
1356 return (phone.getState() == PhoneConstants.State.IDLE);
1357 } else {
1358 return false;
1359 }
1360 } finally {
1361 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 }
1364
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001366 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001367 }
1368
Wink Savilleb564aae2014-10-23 10:18:09 -07001369 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001371 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1372 }
1373
1374 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001379 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001380 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1381 }
1382
1383 /** {@hide} */
1384 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001385 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001386 }
1387
Wink Savilleb564aae2014-10-23 10:18:09 -07001388 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001390
1391 final long identity = Binder.clearCallingIdentity();
1392 try {
1393 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1394 checkSimPin.start();
1395 return checkSimPin.unlockSim(null, pin);
1396 } finally {
1397 Binder.restoreCallingIdentity(identity);
1398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400
Wink Saville9de0f752013-10-22 19:04:03 -07001401 /** {@hide} */
1402 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001404 }
1405
Wink Savilleb564aae2014-10-23 10:18:09 -07001406 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001408
1409 final long identity = Binder.clearCallingIdentity();
1410 try {
1411 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1412 checkSimPuk.start();
1413 return checkSimPuk.unlockSim(puk, pin);
1414 } finally {
1415 Binder.restoreCallingIdentity(identity);
1416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 }
1418
1419 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001420 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421 * a synchronous one.
1422 */
1423 private static class UnlockSim extends Thread {
1424
1425 private final IccCard mSimCard;
1426
1427 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001428 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1429 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430
1431 // For replies from SimCard interface
1432 private Handler mHandler;
1433
1434 // For async handler to identify request type
1435 private static final int SUPPLY_PIN_COMPLETE = 100;
1436
1437 public UnlockSim(IccCard simCard) {
1438 mSimCard = simCard;
1439 }
1440
1441 @Override
1442 public void run() {
1443 Looper.prepare();
1444 synchronized (UnlockSim.this) {
1445 mHandler = new Handler() {
1446 @Override
1447 public void handleMessage(Message msg) {
1448 AsyncResult ar = (AsyncResult) msg.obj;
1449 switch (msg.what) {
1450 case SUPPLY_PIN_COMPLETE:
1451 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1452 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001453 mRetryCount = msg.arg1;
1454 if (ar.exception != null) {
1455 if (ar.exception instanceof CommandException &&
1456 ((CommandException)(ar.exception)).getCommandError()
1457 == CommandException.Error.PASSWORD_INCORRECT) {
1458 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1459 } else {
1460 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1461 }
1462 } else {
1463 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 mDone = true;
1466 UnlockSim.this.notifyAll();
1467 }
1468 break;
1469 }
1470 }
1471 };
1472 UnlockSim.this.notifyAll();
1473 }
1474 Looper.loop();
1475 }
1476
1477 /*
1478 * Use PIN or PUK to unlock SIM card
1479 *
1480 * If PUK is null, unlock SIM card with PIN
1481 *
1482 * If PUK is not null, unlock SIM card with PUK and set PIN code
1483 */
Wink Saville9de0f752013-10-22 19:04:03 -07001484 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485
1486 while (mHandler == null) {
1487 try {
1488 wait();
1489 } catch (InterruptedException e) {
1490 Thread.currentThread().interrupt();
1491 }
1492 }
1493 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1494
1495 if (puk == null) {
1496 mSimCard.supplyPin(pin, callback);
1497 } else {
1498 mSimCard.supplyPuk(puk, pin, callback);
1499 }
1500
1501 while (!mDone) {
1502 try {
1503 Log.d(LOG_TAG, "wait for done");
1504 wait();
1505 } catch (InterruptedException e) {
1506 // Restore the interrupted status
1507 Thread.currentThread().interrupt();
1508 }
1509 }
1510 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001511 int[] resultArray = new int[2];
1512 resultArray[0] = mResult;
1513 resultArray[1] = mRetryCount;
1514 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 }
1516 }
1517
1518 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001519 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001520
1521 }
1522
Wink Savilleb564aae2014-10-23 10:18:09 -07001523 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 // No permission check needed here: this call is harmless, and it's
1525 // needed for the ServiceState.requestStateUpdate() call (which is
1526 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001527 final long identity = Binder.clearCallingIdentity();
1528 try {
1529 final Phone phone = getPhone(subId);
1530 if (phone != null) {
1531 phone.updateServiceLocation();
1532 }
1533 } finally {
1534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001538 @Override
1539 public boolean isRadioOn(String callingPackage) {
1540 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001543 @Override
1544 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001546 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001547 return false;
1548 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001549
1550 final long identity = Binder.clearCallingIdentity();
1551 try {
1552 return isRadioOnForSubscriber(subId);
1553 } finally {
1554 Binder.restoreCallingIdentity(identity);
1555 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001556 }
1557
1558 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final Phone phone = getPhone(subId);
1562 if (phone != null) {
1563 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1564 } else {
1565 return false;
1566 }
1567 } finally {
1568 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
1572 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001573 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 }
Wink Saville36469e72014-06-11 15:17:00 -07001575
Wink Savilleb564aae2014-10-23 10:18:09 -07001576 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001578
1579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 final Phone phone = getPhone(subId);
1582 if (phone != null) {
1583 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1584 }
1585 } finally {
1586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 }
Wink Saville36469e72014-06-11 15:17:00 -07001588 }
1589
1590 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001591 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001592 }
1593
Wink Savilleb564aae2014-10-23 10:18:09 -07001594 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001595 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001596
1597 final long identity = Binder.clearCallingIdentity();
1598 try {
1599 final Phone phone = getPhone(subId);
1600 if (phone == null) {
1601 return false;
1602 }
1603 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1604 toggleRadioOnOffForSubscriber(subId);
1605 }
1606 return true;
1607 } finally {
1608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
Wink Saville36469e72014-06-11 15:17:00 -07001611
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001612 public boolean needMobileRadioShutdown() {
1613 /*
1614 * If any of the Radios are available, it will need to be
1615 * shutdown. So return true if any Radio is available.
1616 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001617 final long identity = Binder.clearCallingIdentity();
1618 try {
1619 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1620 Phone phone = PhoneFactory.getPhone(i);
1621 if (phone != null && phone.isRadioAvailable()) return true;
1622 }
1623 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1624 return false;
1625 } finally {
1626 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001628 }
1629
Malcolm Chenaabec062018-02-28 15:00:40 -08001630 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001632 enforceModifyPermission();
1633
1634 final long identity = Binder.clearCallingIdentity();
1635 try {
1636 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1637 logv("Shutting down Phone " + i);
1638 shutdownRadioUsingPhoneId(i);
1639 }
1640 } finally {
1641 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001642 }
1643 }
1644
1645 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001646 Phone phone = PhoneFactory.getPhone(phoneId);
1647 if (phone != null && phone.isRadioAvailable()) {
1648 phone.shutdownRadio();
1649 }
1650 }
1651
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001653 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001654
1655 final long identity = Binder.clearCallingIdentity();
1656 try {
1657 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1658 if (defaultPhone != null) {
1659 defaultPhone.setRadioPower(turnOn);
1660 return true;
1661 } else {
1662 loge("There's no default phone.");
1663 return false;
1664 }
1665 } finally {
1666 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001667 }
Wink Saville36469e72014-06-11 15:17:00 -07001668 }
1669
Wink Savilleb564aae2014-10-23 10:18:09 -07001670 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001672
1673 final long identity = Binder.clearCallingIdentity();
1674 try {
1675 final Phone phone = getPhone(subId);
1676 if (phone != null) {
1677 phone.setRadioPower(turnOn);
1678 return true;
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
Wink Saville36469e72014-06-11 15:17:00 -07001687 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 public boolean enableDataConnectivity() {
1690 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001691
1692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 int subId = mSubscriptionController.getDefaultDataSubId();
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.setUserDataEnabled(true);
1698 return true;
1699 } else {
1700 return false;
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
Wink Saville36469e72014-06-11 15:17:00 -07001707 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 public boolean disableDataConnectivity() {
1710 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 int subId = mSubscriptionController.getDefaultDataSubId();
1715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 phone.setUserDataEnabled(false);
1718 return true;
1719 } else {
1720 return false;
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001728 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 final Phone phone = getPhone(subId);
1732 if (phone != null) {
1733 return phone.isDataAllowed();
1734 } else {
1735 return false;
1736 }
1737 } finally {
1738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741
1742 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001743 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001744 }
1745
pkanwarae03a6b2016-11-06 20:37:09 -08001746 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001747 enforceCallPermission();
1748
1749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1752 return;
1753 }
1754 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1755 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
1758 }
pkanwar32d516d2016-10-14 19:37:38 -07001759 };
1760
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001763
1764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1767 return false;
1768 }
1769 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001776 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001777 }
1778
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001779 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001780 final long identity = Binder.clearCallingIdentity();
1781 try {
1782 Phone phone = PhoneFactory.getPhone(slotIndex);
1783 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1784 PhoneConstantConversions.convertCallState(phone.getState());
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
1787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
Sanket Padawe356d7632015-06-22 14:03:32 -07001790 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1795 if (phone != null) {
1796 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1797 } else {
1798 return PhoneConstantConversions.convertDataState(
1799 PhoneConstants.DataState.DISCONNECTED);
1800 }
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 }
1805
Sanket Padawe356d7632015-06-22 14:03:32 -07001806 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1811 if (phone != null) {
1812 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1813 } else {
1814 return TelephonyManager.DATA_ACTIVITY_NONE;
1815 }
1816 } finally {
1817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 }
1820
1821 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001822 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001823 mPhone.getContext().getSystemService(AppOpsManager.class)
1824 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001825 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001826 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001827 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001830 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 if (DBG_LOC) log("getCellLocation: is active user");
1834 Bundle data = new Bundle();
1835 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1836 if (phone == null) {
1837 return null;
1838 }
1839
1840 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1841 return data;
1842 } finally {
1843 Binder.restoreCallingIdentity(identity);
1844 }
Svetoslav64fad262015-04-14 14:35:21 -07001845 }
1846
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001848 public String getNetworkCountryIsoForPhone(int phoneId) {
1849 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1850 // registered cell info, so return a NULL country instead.
1851 final long identity = Binder.clearCallingIdentity();
1852 try {
1853 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001854 // Todo: fix this when we can get the actual cellular network info when the device
1855 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001856 if (TelephonyManager.NETWORK_TYPE_IWLAN
1857 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1858 return "";
1859 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001860 Phone phone = PhoneFactory.getPhone(phoneId);
1861 if (phone != null) {
1862 ServiceStateTracker sst = phone.getServiceStateTracker();
1863 if (sst != null) {
1864 LocaleTracker lt = sst.getLocaleTracker();
1865 if (lt != null) {
1866 return lt.getCurrentCountry();
1867 }
1868 }
1869 }
1870 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001871 } finally {
1872 Binder.restoreCallingIdentity(identity);
1873 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001874 }
1875
1876 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001878 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001879 }
1880
Sanket Padawe356d7632015-06-22 14:03:32 -07001881 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001882 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 mApp.enforceCallingOrSelfPermission(
1884 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001885
1886 final long identity = Binder.clearCallingIdentity();
1887 try {
1888 final Phone phone = getPhone(subId);
1889 if (phone != null) {
1890 phone.enableLocationUpdates();
1891 }
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 }
1896
1897 @Override
1898 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001899 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001903 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 mApp.enforceCallingOrSelfPermission(
1905 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001906
1907 final long identity = Binder.clearCallingIdentity();
1908 try {
1909 final Phone phone = getPhone(subId);
1910 if (phone != null) {
1911 phone.disableLocationUpdates();
1912 }
1913 } finally {
1914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
1918 @Override
1919 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001920 public List<NeighboringCellInfo>
1921 getNeighboringCellInfo(String callingPackage, int targetSdk) {
1922 // FIXME: use the P constant when available
1923 if (targetSdk > android.os.Build.VERSION_CODES.O_MR1 + 1) return null;
1924
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1926 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1927 return null;
1928 }
Svetoslav64fad262015-04-14 14:35:21 -07001929
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001930 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931
Nathan Haroldf180aac2018-06-01 18:43:55 -07001932 List<CellInfo> info = getAllCellInfo(callingPackage);
1933 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934
Nathan Haroldf180aac2018-06-01 18:43:55 -07001935 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1936 for (CellInfo ci : info) {
1937 if (ci instanceof CellInfoGsm) {
1938 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1939 } else if (ci instanceof CellInfoWcdma) {
1940 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001943 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 }
1945
1946
1947 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001948 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001949 mPhone.getContext().getSystemService(AppOpsManager.class)
1950 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001951 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001952 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001953 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001956 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001957 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001958 final long identity = Binder.clearCallingIdentity();
1959 try {
1960 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1961 for (Phone phone : PhoneFactory.getPhones()) {
1962 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1963 if (info != null) cellInfos.addAll(info);
1964 }
1965 return cellInfos;
1966 } finally {
1967 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969 }
1970
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001971 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001973 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001975
1976 final long identity = Binder.clearCallingIdentity();
1977 try {
1978 mPhone.setCellInfoListRate(rateInMillis, workSource);
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
1981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
Shishir Agrawala9f32182016-04-12 12:00:16 -07001984 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001985 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001986 Phone phone = PhoneFactory.getPhone(slotIndex);
1987 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001988 return null;
1989 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001990 int subId = phone.getSubId();
1991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1992 mApp, subId, callingPackage, "getImeiForSlot")) {
1993 return null;
1994 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001995
1996 final long identity = Binder.clearCallingIdentity();
1997 try {
1998 return phone.getImei();
1999 } finally {
2000 Binder.restoreCallingIdentity(identity);
2001 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002002 }
2003
2004 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002005 public String getTypeAllocationCodeForSlot(int slotIndex) {
2006 Phone phone = PhoneFactory.getPhone(slotIndex);
2007 String tac = null;
2008 if (phone != null) {
2009 String imei = phone.getImei();
2010 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2011 }
2012 return tac;
2013 }
2014
2015 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002016 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002017 Phone phone = PhoneFactory.getPhone(slotIndex);
2018 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002019 return null;
2020 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002021 int subId = phone.getSubId();
2022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2023 mApp, subId, callingPackage, "getMeidForSlot")) {
2024 return null;
2025 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002026
2027 final long identity = Binder.clearCallingIdentity();
2028 try {
2029 return phone.getMeid();
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
2032 }
Jack Yu2af8d712017-03-15 17:14:14 -07002033 }
2034
2035 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002036 public String getManufacturerCodeForSlot(int slotIndex) {
2037 Phone phone = PhoneFactory.getPhone(slotIndex);
2038 String manufacturerCode = null;
2039 if (phone != null) {
2040 String meid = phone.getMeid();
2041 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2042 }
2043 return manufacturerCode;
2044 }
2045
2046 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002047 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002048 Phone phone = PhoneFactory.getPhone(slotIndex);
2049 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002050 return null;
2051 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002052 int subId = phone.getSubId();
2053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2054 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2055 return null;
2056 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002057
2058 final long identity = Binder.clearCallingIdentity();
2059 try {
2060 return phone.getDeviceSvn();
2061 } finally {
2062 Binder.restoreCallingIdentity(identity);
2063 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002064 }
2065
fionaxu43304da2017-11-27 22:51:16 -08002066 @Override
2067 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002068 final long identity = Binder.clearCallingIdentity();
2069 try {
2070 final Phone phone = getPhone(subId);
2071 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2072 } finally {
2073 Binder.restoreCallingIdentity(identity);
2074 }
fionaxu43304da2017-11-27 22:51:16 -08002075 }
2076
2077 @Override
2078 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002079 final long identity = Binder.clearCallingIdentity();
2080 try {
2081 final Phone phone = getPhone(subId);
2082 return phone == null ? null : phone.getCarrierName();
2083 } finally {
2084 Binder.restoreCallingIdentity(identity);
2085 }
fionaxu43304da2017-11-27 22:51:16 -08002086 }
2087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 //
2089 // Internal helper methods.
2090 //
2091
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002092 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2094 *
2095 * @throws SecurityException if the caller does not have the required permission
2096 */
2097 private void enforceModifyPermission() {
2098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2099 }
2100
2101 /**
2102 * Make sure the caller has the CALL_PHONE permission.
2103 *
2104 * @throws SecurityException if the caller does not have the required permission
2105 */
2106 private void enforceCallPermission() {
2107 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2108 }
2109
Stuart Scott8eef64f2015-04-08 15:13:54 -07002110 private void enforceConnectivityInternalPermission() {
2111 mApp.enforceCallingOrSelfPermission(
2112 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2113 "ConnectivityService");
2114 }
2115
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 private String createTelUrl(String number) {
2117 if (TextUtils.isEmpty(number)) {
2118 return null;
2119 }
2120
Jake Hambye994d462014-02-03 13:10:13 -08002121 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 }
2123
Ihab Awadf9e92732013-12-05 18:02:52 -08002124 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2126 }
2127
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002128 private static void logv(String msg) {
2129 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2130 }
2131
Ihab Awadf9e92732013-12-05 18:02:52 -08002132 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2134 }
2135
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002136 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002138 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002139 }
2140
Sanket Padawe356d7632015-06-22 14:03:32 -07002141 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002142 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002143 final long identity = Binder.clearCallingIdentity();
2144 try {
2145 final Phone phone = PhoneFactory.getPhone(slotIndex);
2146 if (phone == null) {
2147 return PhoneConstants.PHONE_TYPE_NONE;
2148 } else {
2149 return phone.getPhoneType();
2150 }
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 }
2155
2156 /**
2157 * Returns the CDMA ERI icon index to display
2158 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002159 @Override
2160 public int getCdmaEriIconIndex(String callingPackage) {
2161 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002162 }
2163
Sanket Padawe356d7632015-06-22 14:03:32 -07002164 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002165 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002167 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002168 return -1;
2169 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002170
2171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
2175 return phone.getCdmaEriIconIndex();
2176 } else {
2177 return -1;
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
2184 /**
2185 * Returns the CDMA ERI icon mode,
2186 * 0 - ON
2187 * 1 - FLASHING
2188 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002189 @Override
2190 public int getCdmaEriIconMode(String callingPackage) {
2191 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
Sanket Padawe356d7632015-06-22 14:03:32 -07002194 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002195 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002197 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002198 return -1;
2199 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002200
2201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
2205 return phone.getCdmaEriIconMode();
2206 } else {
2207 return -1;
2208 }
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 }
2213
2214 /**
2215 * Returns the CDMA ERI text,
2216 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002217 @Override
2218 public String getCdmaEriText(String callingPackage) {
2219 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002220 }
2221
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002223 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002225 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002226 return null;
2227 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002228
2229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 final Phone phone = getPhone(subId);
2232 if (phone != null) {
2233 return phone.getCdmaEriText();
2234 } else {
2235 return null;
2236 }
2237 } finally {
2238 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
2242 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002243 * Returns the CDMA MDN.
2244 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002245 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002246 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2248 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002249
2250 final long identity = Binder.clearCallingIdentity();
2251 try {
2252 final Phone phone = getPhone(subId);
2253 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2254 return phone.getLine1Number();
2255 } else {
2256 return null;
2257 }
2258 } finally {
2259 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002260 }
2261 }
2262
2263 /**
2264 * Returns the CDMA MIN.
2265 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002267 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2269 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002270
2271 final long identity = Binder.clearCallingIdentity();
2272 try {
2273 final Phone phone = getPhone(subId);
2274 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2275 return phone.getCdmaMin();
2276 } else {
2277 return null;
2278 }
2279 } finally {
2280 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002281 }
2282 }
2283
2284 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 * Returns true if CDMA provisioning needs to run.
2286 */
2287 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 return mPhone.needsOtaServiceProvisioning();
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002297 * Sets the voice mail number of a given subId.
2298 */
2299 @Override
2300 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002301 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002302
2303 final long identity = Binder.clearCallingIdentity();
2304 try {
2305 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2306 new Pair<String, String>(alphaTag, number), new Integer(subId));
2307 return success;
2308 } finally {
2309 Binder.restoreCallingIdentity(identity);
2310 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002311 }
2312
Ta-wei Yen87c49842016-05-13 21:19:52 -07002313 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002314 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2315 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2316 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2317 if (!TextUtils.equals(callingPackage, systemDialer)) {
2318 throw new SecurityException("caller must be system dialer");
2319 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002320
2321 final long identity = Binder.clearCallingIdentity();
2322 try {
2323 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2324 if (phoneAccountHandle == null) {
2325 return null;
2326 }
2327 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002330 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002331 }
2332
2333 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002334 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002335 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002337 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002338 return null;
2339 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002340
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 return RemoteVvmTaskManager
2344 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
2347 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002348 }
2349
2350 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002351 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2352 VisualVoicemailSmsFilterSettings settings) {
2353 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002354
2355 final long identity = Binder.clearCallingIdentity();
2356 try {
2357 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2358 mPhone.getContext(), callingPackage, subId, settings);
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
2361 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002362 }
2363
2364 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002365 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2366 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002367
2368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2371 mPhone.getContext(), callingPackage, subId);
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002375 }
2376
2377 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002378 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2379 String callingPackage, int subId) {
2380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002381
2382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2385 mPhone.getContext(), callingPackage, subId);
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002389 }
2390
2391 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002392 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002393 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002394
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2398 mPhone.getContext(), subId);
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
2401 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002402 }
2403
2404 @Override
2405 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2406 String number, int port, String text, PendingIntent sentIntent) {
2407 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002408 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002409 enforceSendSmsPermission();
2410 // Make the calls as the phone process.
2411 final long identity = Binder.clearCallingIdentity();
2412 try {
2413 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2414 if (port == 0) {
2415 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2416 sentIntent, null, false);
2417 } else {
2418 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2419 smsManager.sendDataMessageWithSelfPermissions(number, null,
2420 (short) port, data, sentIntent, null);
2421 }
2422 } finally {
2423 Binder.restoreCallingIdentity(identity);
2424 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002425 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002426 /**
fionaxu0152e512016-11-14 13:36:14 -08002427 * Sets the voice activation state of a given subId.
2428 */
2429 @Override
2430 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2432 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002433
2434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 final Phone phone = getPhone(subId);
2437 if (phone != null) {
2438 phone.setVoiceActivationState(activationState);
2439 } else {
2440 loge("setVoiceActivationState fails with invalid subId: " + subId);
2441 }
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002444 }
2445 }
2446
2447 /**
2448 * Sets the data activation state of a given subId.
2449 */
2450 @Override
2451 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2453 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002454
2455 final long identity = Binder.clearCallingIdentity();
2456 try {
2457 final Phone phone = getPhone(subId);
2458 if (phone != null) {
2459 phone.setDataActivationState(activationState);
2460 } else {
2461 loge("setVoiceActivationState fails with invalid subId: " + subId);
2462 }
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002465 }
2466 }
2467
2468 /**
2469 * Returns the voice activation state of a given subId.
2470 */
2471 @Override
2472 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002473 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002474
fionaxu0152e512016-11-14 13:36:14 -08002475 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 if (phone != null) {
2479 return phone.getVoiceActivationState();
2480 } else {
2481 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2482 }
2483 } finally {
2484 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002485 }
2486 }
2487
2488 /**
2489 * Returns the data activation state of a given subId.
2490 */
2491 @Override
2492 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002493 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002494
fionaxu0152e512016-11-14 13:36:14 -08002495 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002496 final long identity = Binder.clearCallingIdentity();
2497 try {
2498 if (phone != null) {
2499 return phone.getDataActivationState();
2500 } else {
2501 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2502 }
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002505 }
2506 }
2507
2508 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 * Returns the unread count of voicemails
2510 */
2511 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002512 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002513 }
2514
2515 /**
2516 * Returns the unread count of voicemails for a subId
2517 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002519 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone != null) {
2524 return phone.getVoiceMessageCount();
2525 } else {
2526 return 0;
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
2533 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002534 * returns true, if the device is in a state where both voice and data
2535 * are supported simultaneously. This can change based on location or network condition.
2536 */
2537 @Override
2538 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 final Phone phone = getPhone(subId);
2542 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002546 }
2547
2548 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002549 * Send the dialer code if called from the current default dialer or the caller has
2550 * carrier privilege.
2551 * @param inputCode The dialer code to send
2552 */
2553 @Override
2554 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2556 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2557 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002558 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2559 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002560 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002561
2562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 mPhone.sendDialerSpecialCode(inputCode);
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
fionaxu235cc5e2017-03-06 22:25:57 -08002568 }
2569
2570 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002571 * Returns the data network type.
2572 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 *
2574 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2575 */
2576 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002577 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 final Phone phone = getPhone(getDefaultSubscription());
2581 if (phone != null) {
2582 return phone.getServiceState().getDataNetworkType();
2583 } else {
2584 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2585 }
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002588 }
Wink Saville36469e72014-06-11 15:17:00 -07002589 }
2590
2591 /**
2592 * Returns the network type for a subId
2593 */
2594 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002595 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002597 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002598 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2599 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002600
Malcolm Chenaabec062018-02-28 15:00:40 -08002601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 final Phone phone = getPhone(subId);
2604 if (phone != null) {
2605 return phone.getServiceState().getDataNetworkType();
2606 } else {
2607 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613
2614 /**
2615 * Returns the data network type
2616 */
2617 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002618 public int getDataNetworkType(String callingPackage) {
2619 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002620 }
2621
2622 /**
2623 * Returns the data network type for a subId
2624 */
2625 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002626 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002628 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002629 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2630 }
2631
Malcolm Chenaabec062018-02-28 15:00:40 -08002632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 final Phone phone = getPhone(subId);
2635 if (phone != null) {
2636 return phone.getServiceState().getDataNetworkType();
2637 } else {
2638 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2639 }
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 }
2644
2645 /**
Wink Saville36469e72014-06-11 15:17:00 -07002646 * Returns the Voice network type for a subId
2647 */
2648 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002649 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002651 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002652 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2653 }
2654
Malcolm Chenaabec062018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 if (phone != null) {
2659 return phone.getServiceState().getVoiceNetworkType();
2660 } else {
2661 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
2668 /**
2669 * @return true if a ICC card is present
2670 */
2671 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002672 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002673 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2674 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002675 }
2676
2677 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002678 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002679 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002680 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002681 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = PhoneFactory.getPhone(slotIndex);
2685 if (phone != null) {
2686 return phone.getIccCard().hasIccCard();
2687 } else {
2688 return false;
2689 }
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694
2695 /**
2696 * Return if the current radio is LTE on CDMA. This
2697 * is a tri-state return value as for a period of time
2698 * the mode may be unknown.
2699 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002700 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002702 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002704 @Override
2705 public int getLteOnCdmaMode(String callingPackage) {
2706 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
Sanket Padawe356d7632015-06-22 14:03:32 -07002709 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002710 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002712 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002713 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2714 }
2715
Malcolm Chenaabec062018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 final Phone phone = getPhone(subId);
2719 if (phone == null) {
2720 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2721 } else {
2722 return phone.getLteOnCdmaMode();
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 }
Wink Saville36469e72014-06-11 15:17:00 -07002727 }
2728
2729 public void setPhone(Phone phone) {
2730 mPhone = phone;
2731 }
2732
2733 /**
2734 * {@hide}
2735 * Returns Default subId, 0 in the case of single standby.
2736 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002737 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002738 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002739 }
2740
Shishir Agrawala9f32182016-04-12 12:00:16 -07002741 private int getSlotForDefaultSubscription() {
2742 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2743 }
2744
Wink Savilleb564aae2014-10-23 10:18:09 -07002745 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002746 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002748
2749 /**
2750 * @see android.telephony.TelephonyManager.WifiCallingChoices
2751 */
2752 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2756 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2757 getWhenToMakeWifiCallsDefaultPreference());
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002761 }
2762
2763 /**
2764 * @see android.telephony.TelephonyManager.WifiCallingChoices
2765 */
2766 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2770 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2771 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
2774 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002775 }
2776
Sailesh Nepald1e68152013-12-12 19:08:02 -08002777 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002778 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002779 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002780 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002781
Shishir Agrawal566b7612013-10-28 14:41:00 -07002782 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002783 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2784 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2786 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002787 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002788
Malcolm Chenaabec062018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 if (TextUtils.equals(ISDR_AID, aid)) {
2792 // Only allows LPA to open logical channel to ISD-R.
2793 ComponentInfo bestComponent =
2794 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2795 if (bestComponent == null
2796 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2797 loge("The calling package is not allowed to access ISD-R.");
2798 throw new SecurityException(
2799 "The calling package is not allowed to access ISD-R.");
2800 }
Derek Tan740e1672017-06-27 14:56:27 -07002801 }
Derek Tan740e1672017-06-27 14:56:27 -07002802
Malcolm Chenaabec062018-02-28 15:00:40 -08002803 if (DBG) {
2804 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2805 }
2806 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2807 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2808 if (DBG) log("iccOpenLogicalChannel: " + response);
2809 return response;
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002813 }
2814
2815 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002816 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2818 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002819
Malcolm Chenaabec062018-02-28 15:00:40 -08002820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2823 if (channel < 0) {
2824 return false;
2825 }
2826 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2827 if (DBG) log("iccCloseLogicalChannel: " + success);
2828 return success;
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002832 }
2833
2834 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002835 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002836 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2838 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002839
Malcolm Chenaabec062018-02-28 15:00:40 -08002840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 if (DBG) {
2843 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2844 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2845 + p3 + " data=" + data);
2846 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002847
Malcolm Chenaabec062018-02-28 15:00:40 -08002848 if (channel < 0) {
2849 return "";
2850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851
Malcolm Chenaabec062018-02-28 15:00:40 -08002852 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2853 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2854 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002855
Malcolm Chenaabec062018-02-28 15:00:40 -08002856 // Append the returned status code to the end of the response payload.
2857 String s = Integer.toHexString(
2858 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2859 if (response.payload != null) {
2860 s = IccUtils.bytesToHexString(response.payload) + s;
2861 }
2862 return s;
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002865 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002866 }
Jake Hambye994d462014-02-03 13:10:13 -08002867
Evan Charltonc66da362014-05-16 14:06:40 -07002868 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002869 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2870 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2872 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002873 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002874
Malcolm Chenaabec062018-02-28 15:00:40 -08002875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2878 && TextUtils.equals(ISDR_AID, data)) {
2879 // Only allows LPA to select ISD-R.
2880 ComponentInfo bestComponent =
2881 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2882 if (bestComponent == null
2883 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2884 loge("The calling package is not allowed to select ISD-R.");
2885 throw new SecurityException(
2886 "The calling package is not allowed to select ISD-R.");
2887 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002888 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002889
Malcolm Chenaabec062018-02-28 15:00:40 -08002890 if (DBG) {
2891 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2892 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2893 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002894
Malcolm Chenaabec062018-02-28 15:00:40 -08002895 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2896 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2897 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002898
Malcolm Chenaabec062018-02-28 15:00:40 -08002899 // Append the returned status code to the end of the response payload.
2900 String s = Integer.toHexString(
2901 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2902 if (response.payload != null) {
2903 s = IccUtils.bytesToHexString(response.payload) + s;
2904 }
2905 return s;
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002908 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002909 }
2910
2911 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002912 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002913 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2915 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002916
Malcolm Chenaabec062018-02-28 15:00:40 -08002917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 if (DBG) {
2920 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2921 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2922 }
2923
2924 IccIoResult response =
2925 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2926 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2927 subId);
2928
2929 if (DBG) {
2930 log("Exchange SIM_IO [R]" + response);
2931 }
2932
2933 byte[] result = null;
2934 int length = 2;
2935 if (response.payload != null) {
2936 length = 2 + response.payload.length;
2937 result = new byte[length];
2938 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2939 } else {
2940 result = new byte[length];
2941 }
2942
2943 result[length - 1] = (byte) response.sw2;
2944 result[length - 2] = (byte) response.sw1;
2945 return result;
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002948 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002949 }
2950
Nathan Haroldb3014052017-01-25 15:57:32 -08002951 /**
2952 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2953 * on a particular subscription
2954 */
sqianb6e41952018-03-12 14:54:01 -07002955 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2957 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2958 return null;
2959 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002960 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2961 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2962 return null;
2963 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002964
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2968 if (response instanceof String[]) {
2969 return (String[]) response;
2970 }
2971 // Response is an Exception of some kind,
2972 // which is signalled to the user as a NULL retval
2973 return null;
2974 } finally {
2975 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002976 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002977 }
2978
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002979 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002980 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2982 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002983
Malcolm Chenaabec062018-02-28 15:00:40 -08002984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2987 if (response.payload == null) {
2988 return "";
2989 }
Evan Charltonc66da362014-05-16 14:06:40 -07002990
Malcolm Chenaabec062018-02-28 15:00:40 -08002991 // Append the returned status code to the end of the response payload.
2992 String s = Integer.toHexString(
2993 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2994 s = IccUtils.bytesToHexString(response.payload) + s;
2995 return s;
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
Evan Charltonc66da362014-05-16 14:06:40 -07002999 }
3000
Jake Hambye994d462014-02-03 13:10:13 -08003001 /**
3002 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3003 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3004 *
3005 * @param itemID the ID of the item to read
3006 * @return the NV item as a String, or null on error.
3007 */
3008 @Override
3009 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3011 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003012
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 if (DBG) log("nvReadItem: item " + itemID);
3016 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3017 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3018 return value;
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
Jake Hambye994d462014-02-03 13:10:13 -08003022 }
3023
3024 /**
3025 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3026 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3027 *
3028 * @param itemID the ID of the item to read
3029 * @param itemValue the value to write, as a String
3030 * @return true on success; false on any failure
3031 */
3032 @Override
3033 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3035 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003036
3037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3040 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3041 new Pair<Integer, String>(itemID, itemValue));
3042 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3043 return success;
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
Jake Hambye994d462014-02-03 13:10:13 -08003047 }
3048
3049 /**
3050 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3051 * Used for device configuration by some CDMA operators.
3052 *
3053 * @param preferredRoamingList byte array containing the new PRL
3054 * @return true on success; false on any failure
3055 */
3056 @Override
3057 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3059 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3064 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3065 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3066 return success;
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
Jake Hambye994d462014-02-03 13:10:13 -08003070 }
3071
3072 /**
3073 * Perform the specified type of NV config reset.
3074 * Used for device configuration by some CDMA operators.
3075 *
3076 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3077 * @return true on success; false on any failure
3078 */
3079 @Override
3080 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3082 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003083
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 if (DBG) log("nvResetConfig: type " + resetType);
3087 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3088 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3089 return success;
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
Jake Hambye994d462014-02-03 13:10:13 -08003093 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003094
Svet Ganovb320e182015-04-16 12:30:10 -07003095 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003097 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003098 return new String[0];
3099 }
3100
Malcolm Chenaabec062018-02-28 15:00:40 -08003101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 return mPhone.getPcscfAddress(apnType);
3104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
Wink Saville36469e72014-06-11 15:17:00 -07003107 }
3108
Brad Ebinger51f743a2017-01-23 13:50:20 -08003109 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003110 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3111 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003112 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003113 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003114 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003115
3116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 PhoneFactory.getImsResolver().enableIms(slotId);
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003122 }
3123
3124 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003125 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3126 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003127 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003128 public void disableIms(int slotId) {
3129 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003130
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 PhoneFactory.getImsResolver().disableIms(slotId);
3134 } finally {
3135 Binder.restoreCallingIdentity(identity);
3136 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003137 }
3138
3139 /**
3140 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3141 * feature or {@link null} if the service is not available. If the feature is available, the
3142 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3143 */
3144 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003145 IImsServiceFeatureCallback callback) {
3146 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003147
3148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003154 }
3155
3156 /**
3157 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3158 * feature during emergency calling or {@link null} if the service is not available. If the
3159 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3160 * listener for feature updates.
3161 */
3162 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3163 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003171 }
3172
Brad Ebinger5f64b052017-12-14 14:26:15 -08003173 /**
3174 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3175 * specified.
3176 */
3177 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3178 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003179
3180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003186 }
3187
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003188 /**
3189 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3190 * specified.
3191 */
3192 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3193 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003194
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003201 }
3202
Brad Ebinger884c07b2018-02-15 16:17:40 -08003203 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003204 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3205 * available, false if the IMS resolver is idle.
3206 */
3207 public boolean isResolvingImsBinding() {
3208 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003209
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 return PhoneFactory.getImsResolver().isResolvingBinding();
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Brad Ebinger67801702018-03-02 13:43:36 -08003216 }
3217
Brad Ebingerdac2f002018-04-03 15:17:52 -07003218 /**
3219 * Sets the ImsService Package Name that Telephony will bind to.
3220 *
3221 * @param slotId the slot ID that the ImsService should bind for.
3222 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3223 * ImsService is the device default ImsService.
3224 * @param packageName The package name of the application that contains the ImsService to bind
3225 * to.
3226 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3227 * @hide
3228 */
3229 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003230 int[] subIds = SubscriptionManager.getSubId(slotId);
3231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3232 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3233 "setImsService");
3234
Malcolm Chenaabec062018-02-28 15:00:40 -08003235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3238 isCarrierImsService, packageName);
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003242 }
3243
3244 /**
3245 * Return the ImsService configuration.
3246 *
3247 * @param slotId The slot that the ImsService is associated with.
3248 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3249 * the device default.
3250 * @return the package name of the ImsService configuration.
3251 */
3252 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003253 int[] subIds = SubscriptionManager.getSubId(slotId);
3254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3255 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3256 "getImsService");
3257
Malcolm Chenaabec062018-02-28 15:00:40 -08003258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3261 isCarrierImsService);
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
3264 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003265 }
3266
Wink Saville36469e72014-06-11 15:17:00 -07003267 public void setImsRegistrationState(boolean registered) {
3268 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003269
3270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 mPhone.setImsRegistrationState(registered);
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
Wink Saville36469e72014-06-11 15:17:00 -07003276 }
3277
3278 /**
Stuart Scott54788802015-03-30 13:18:01 -07003279 * Set the network selection mode to automatic.
3280 *
3281 */
3282 @Override
3283 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3285 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003286
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3290 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
Stuart Scott54788802015-03-30 13:18:01 -07003294 }
3295
3296 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003297 * Set the network selection mode to manual with the selected carrier.
3298 */
3299 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003300 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003301 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3303 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003304
3305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003308 /* operatorAlphaLong */ "",
3309 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003310 operatorNumeric);
3311 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3312 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3313 persistSelection);
3314 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003318 }
3319
3320 /**
3321 * Scans for available networks.
3322 */
3323 @Override
3324 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3326 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003327
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3331 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3332 CMD_PERFORM_NETWORK_SCAN, null, subId);
3333 return result;
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003337 }
3338
3339 /**
yinxub1bed742017-04-17 11:45:04 -07003340 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003341 *
yinxub1bed742017-04-17 11:45:04 -07003342 * @param subId id of the subscription
3343 * @param request contains the radio access networks with bands/channels to scan
3344 * @param messenger callback messenger for scan results or errors
3345 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003346 * @return the id of the requested scan which can be used to stop the scan.
3347 */
3348 @Override
3349 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3350 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3352 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 return mNetworkScanRequestTracker.startNetworkScan(
3357 request, messenger, binder, getPhone(subId));
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
yinxu504e1392017-04-12 16:03:22 -07003361 }
3362
3363 /**
3364 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003365 *
3366 * @param subId id of the subscription
3367 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003368 */
3369 @Override
3370 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3372 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
yinxu504e1392017-04-12 16:03:22 -07003380 }
3381
3382 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003383 * Get the calculated preferred network type.
3384 * Used for debugging incorrect network type.
3385 *
3386 * @return the preferred network type, defined in RILConstants.java.
3387 */
3388 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003389 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003391 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003392 return RILConstants.PREFERRED_NETWORK_MODE;
3393 }
3394
Malcolm Chenaabec062018-02-28 15:00:40 -08003395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 // FIXME: need to get SubId from somewhere.
3398 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Junda Liu84d15a22014-07-02 11:21:04 -07003402 }
3403
3404 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003405 * Get the preferred network type.
3406 * Used for device configuration by some CDMA operators.
3407 *
3408 * @return the preferred network type, defined in RILConstants.java.
3409 */
3410 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003411 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3413 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003414
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 if (DBG) log("getPreferredNetworkType");
3418 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3419 int networkType = (result != null ? result[0] : -1);
3420 if (DBG) log("getPreferredNetworkType: " + networkType);
3421 return networkType;
3422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003425 }
3426
3427 /**
3428 * Set the preferred network type.
3429 * Used for device configuration by some CDMA operators.
3430 *
3431 * @param networkType the preferred network type, defined in RILConstants.java.
3432 * @return true on success; false on any failure.
3433 */
3434 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003435 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3437 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003438
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3442 Boolean success = (Boolean) sendRequest(
3443 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3444 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3445 if (success) {
3446 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3447 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3448 }
3449 return success;
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003452 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003453 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003454
3455 /**
Junda Liu475951f2014-11-07 16:45:03 -08003456 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3457 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3458 * tethering.
3459 *
3460 * @return 0: Not required. 1: required. 2: Not set.
3461 * @hide
3462 */
3463 @Override
3464 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003465 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003466
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3470 Settings.Global.TETHER_DUN_REQUIRED, 2);
3471 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3472 // config_tether_apndata.
3473 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3474 dunRequired = 1;
3475 }
3476 return dunRequired;
3477 } finally {
3478 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003479 }
Junda Liu475951f2014-11-07 16:45:03 -08003480 }
3481
3482 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003483 * Set mobile data enabled
3484 * Used by the user through settings etc to turn on/off mobile data
3485 *
3486 * @param enable {@code true} turn turn data on, else {@code false}
3487 */
3488 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003489 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3491 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 int phoneId = mSubscriptionController.getPhoneId(subId);
3496 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3497 Phone phone = PhoneFactory.getPhone(phoneId);
3498 if (phone != null) {
3499 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3500 phone.setUserDataEnabled(enable);
3501 } else {
3502 loge("setUserDataEnabled: no phone for subId=" + subId);
3503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003506 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003507 }
3508
3509 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003510 * Get the user enabled state of Mobile Data.
3511 *
3512 * TODO: remove and use isUserDataEnabled.
3513 * This can't be removed now because some vendor codes
3514 * calls through ITelephony directly while they should
3515 * use TelephonyManager.
3516 *
3517 * @return true on enabled
3518 */
3519 @Override
3520 public boolean getDataEnabled(int subId) {
3521 return isUserDataEnabled(subId);
3522 }
3523
3524 /**
3525 * Get whether mobile data is enabled per user setting.
3526 *
3527 * There are other factors deciding whether mobile data is actually enabled, but they are
3528 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003529 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003530 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003531 *
3532 * @return {@code true} if data is enabled else {@code false}
3533 */
3534 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003535 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003536 try {
3537 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3538 null);
3539 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3541 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003542 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 int phoneId = mSubscriptionController.getPhoneId(subId);
3547 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3548 Phone phone = PhoneFactory.getPhone(phoneId);
3549 if (phone != null) {
3550 boolean retVal = phone.isUserDataEnabled();
3551 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3552 return retVal;
3553 } else {
3554 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3555 return false;
3556 }
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003559 }
3560 }
3561
3562 /**
3563 * Get whether mobile data is enabled.
3564 *
3565 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3566 * whether mobile data is actually enabled.
3567 *
3568 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3569 *
3570 * @return {@code true} if data is enabled else {@code false}
3571 */
3572 @Override
3573 public boolean isDataEnabled(int subId) {
3574 try {
3575 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3576 null);
3577 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3579 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003580 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003581
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 int phoneId = mSubscriptionController.getPhoneId(subId);
3585 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3586 Phone phone = PhoneFactory.getPhone(phoneId);
3587 if (phone != null) {
3588 boolean retVal = phone.isDataEnabled();
3589 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3590 return retVal;
3591 } else {
3592 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3593 return false;
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003597 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003598 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003599
3600 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003601 public int getCarrierPrivilegeStatus(int subId) {
3602 final Phone phone = getPhone(subId);
3603 if (phone == null) {
3604 loge("getCarrierPrivilegeStatus: Invalid subId");
3605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3606 }
3607 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003608 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003609 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3611 }
3612 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003613 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003614 }
Junda Liu29340342014-07-10 15:23:27 -07003615
3616 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3618 final Phone phone = getPhone(subId);
3619 if (phone == null) {
3620 loge("getCarrierPrivilegeStatus: Invalid subId");
3621 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3622 }
3623 UiccProfile profile =
3624 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3625 if (profile == null) {
3626 loge("getCarrierPrivilegeStatus: No UICC");
3627 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3628 }
3629 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3630 }
3631
3632 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003633 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003634 if (TextUtils.isEmpty(pkgName))
3635 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003636 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003637 if (card == null) {
3638 loge("checkCarrierPrivilegesForPackage: No UICC");
3639 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3640 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003641 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3642 }
3643
3644 @Override
3645 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003646 if (TextUtils.isEmpty(pkgName))
3647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003648 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3649 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3650 UiccCard card = UiccController.getInstance().getUiccCard(i);
3651 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003652 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003653 continue;
3654 }
3655
3656 result = card.getCarrierPrivilegeStatus(
3657 mPhone.getContext().getPackageManager(), pkgName);
3658 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3659 break;
3660 }
3661 }
3662
3663 return result;
Junda Liu29340342014-07-10 15:23:27 -07003664 }
Derek Tan89e89d42014-07-08 17:00:10 -07003665
3666 @Override
Junda Liue64de782015-04-16 17:19:16 -07003667 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3668 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3669 loge("phoneId " + phoneId + " is not valid.");
3670 return null;
3671 }
3672 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003673 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003674 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003675 return null ;
3676 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003677 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003678 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003679 }
3680
Amith Yamasani6e118872016-02-19 12:53:51 -08003681 @Override
3682 public List<String> getPackagesWithCarrierPrivileges() {
3683 PackageManager pm = mPhone.getContext().getPackageManager();
3684 List<String> privilegedPackages = new ArrayList<>();
3685 List<PackageInfo> packages = null;
3686 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3687 UiccCard card = UiccController.getInstance().getUiccCard(i);
3688 if (card == null) {
3689 // No UICC in that slot.
3690 continue;
3691 }
3692 if (card.hasCarrierPrivilegeRules()) {
3693 if (packages == null) {
3694 // Only check packages in user 0 for now
3695 packages = pm.getInstalledPackagesAsUser(
3696 PackageManager.MATCH_DISABLED_COMPONENTS
3697 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3698 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3699 }
3700 for (int p = packages.size() - 1; p >= 0; p--) {
3701 PackageInfo pkgInfo = packages.get(p);
3702 if (pkgInfo != null && pkgInfo.packageName != null
3703 && card.getCarrierPrivilegeStatus(pkgInfo)
3704 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3705 privilegedPackages.add(pkgInfo.packageName);
3706 }
3707 }
3708 }
3709 }
3710 return privilegedPackages;
3711 }
3712
Wink Savilleb564aae2014-10-23 10:18:09 -07003713 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003714 final Phone phone = getPhone(subId);
3715 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003716 if (card == null) {
3717 loge("getIccId: No UICC");
3718 return null;
3719 }
3720 String iccId = card.getIccId();
3721 if (TextUtils.isEmpty(iccId)) {
3722 loge("getIccId: ICC ID is null or empty.");
3723 return null;
3724 }
3725 return iccId;
3726 }
3727
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003728 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003729 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3730 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003731 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3732 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003733
Malcolm Chenaabec062018-02-28 15:00:40 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 final String iccId = getIccId(subId);
3737 final Phone phone = getPhone(subId);
3738 if (phone == null) {
3739 return false;
3740 }
3741 final String subscriberId = phone.getSubscriberId();
3742
3743 if (DBG_MERGE) {
3744 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3745 + subscriberId + " to " + number);
3746 }
3747
3748 if (TextUtils.isEmpty(iccId)) {
3749 return false;
3750 }
3751
3752 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3753
3754 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3755 if (alphaTag == null) {
3756 editor.remove(alphaTagPrefKey);
3757 } else {
3758 editor.putString(alphaTagPrefKey, alphaTag);
3759 }
3760
3761 // Record both the line number and IMSI for this ICCID, since we need to
3762 // track all merged IMSIs based on line number
3763 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3764 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3765 if (number == null) {
3766 editor.remove(numberPrefKey);
3767 editor.remove(subscriberPrefKey);
3768 } else {
3769 editor.putString(numberPrefKey, number);
3770 editor.putString(subscriberPrefKey, subscriberId);
3771 }
3772
3773 editor.commit();
3774 return true;
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003777 }
Derek Tan7226c842014-07-02 17:42:23 -07003778 }
3779
3780 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003781 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003782 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003784 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003785 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003786 return null;
3787 }
Derek Tan97ebb422014-09-05 16:55:38 -07003788
Malcolm Chenaabec062018-02-28 15:00:40 -08003789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 String iccId = getIccId(subId);
3792 if (iccId != null) {
3793 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3794 if (DBG_MERGE) {
3795 log("getLine1NumberForDisplay returning "
3796 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3797 }
3798 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003799 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003800 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3801 return null;
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003804 }
Derek Tan7226c842014-07-02 17:42:23 -07003805 }
3806
3807 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003808 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003810 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003811 return null;
3812 }
Derek Tan97ebb422014-09-05 16:55:38 -07003813
Malcolm Chenaabec062018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 String iccId = getIccId(subId);
3817 if (iccId != null) {
3818 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3819 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3820 }
3821 return null;
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003824 }
Derek Tan7226c842014-07-02 17:42:23 -07003825 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003826
3827 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003828 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003829 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3830 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003832 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3833 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003834 return null;
3835 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003836
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003837 final long identity = Binder.clearCallingIdentity();
3838 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003839 final Context context = mPhone.getContext();
3840 final TelephonyManager tele = TelephonyManager.from(context);
3841 final SubscriptionManager sub = SubscriptionManager.from(context);
3842
3843 // Figure out what subscribers are currently active
3844 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3845 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3846 // the process, where TelephonyManager was instantiated.
3847 // Otherwise AppOps check will fail.
3848
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003849 final int[] subIds = sub.getActiveSubscriptionIdList();
3850 for (int subId : subIds) {
3851 activeSubscriberIds.add(tele.getSubscriberId(subId));
3852 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003853
3854 // First pass, find a number override for an active subscriber
3855 String mergeNumber = null;
3856 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3857 for (String key : prefs.keySet()) {
3858 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3859 final String subscriberId = (String) prefs.get(key);
3860 if (activeSubscriberIds.contains(subscriberId)) {
3861 final String iccId = key.substring(
3862 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3863 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3864 mergeNumber = (String) prefs.get(numberKey);
3865 if (DBG_MERGE) {
3866 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3867 + " for active subscriber " + subscriberId);
3868 }
3869 if (!TextUtils.isEmpty(mergeNumber)) {
3870 break;
3871 }
3872 }
3873 }
3874 }
3875
3876 // Shortcut when no active merged subscribers
3877 if (TextUtils.isEmpty(mergeNumber)) {
3878 return null;
3879 }
3880
3881 // Second pass, find all subscribers under that line override
3882 final ArraySet<String> result = new ArraySet<>();
3883 for (String key : prefs.keySet()) {
3884 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3885 final String number = (String) prefs.get(key);
3886 if (mergeNumber.equals(number)) {
3887 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3888 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3889 final String subscriberId = (String) prefs.get(subscriberKey);
3890 if (!TextUtils.isEmpty(subscriberId)) {
3891 result.add(subscriberId);
3892 }
3893 }
3894 }
3895 }
3896
3897 final String[] resultArray = result.toArray(new String[result.size()]);
3898 Arrays.sort(resultArray);
3899 if (DBG_MERGE) {
3900 Slog.d(LOG_TAG,
3901 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3902 }
3903 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003906 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003907 }
3908
3909 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003910 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003911 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3912 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003913
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 final Phone phone = getPhone(subId);
3917 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003921 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003922
3923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003924 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003925 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3926 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003928
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 final Phone phone = getPhone(subId);
3932 if (phone == null) {
3933 return false;
3934 }
3935 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3936 cdmaNonRoamingList);
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003939 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003940 }
3941
3942 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003943 @Deprecated
3944 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3945 enforceModifyPermission();
3946
3947 int returnValue = 0;
3948 try {
3949 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3950 if(result.exception == null) {
3951 if (result.result != null) {
3952 byte[] responseData = (byte[])(result.result);
3953 if(responseData.length > oemResp.length) {
3954 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3955 responseData.length + "bytes. Buffer Size is " +
3956 oemResp.length + "bytes.");
3957 }
3958 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3959 returnValue = responseData.length;
3960 }
3961 } else {
3962 CommandException ex = (CommandException) result.exception;
3963 returnValue = ex.getCommandError().ordinal();
3964 if(returnValue > 0) returnValue *= -1;
3965 }
3966 } catch (RuntimeException e) {
3967 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3968 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3969 if(returnValue > 0) returnValue *= -1;
3970 }
3971
3972 return returnValue;
3973 }
3974
3975 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003976 public void setRadioCapability(RadioAccessFamily[] rafs) {
3977 try {
3978 ProxyController.getInstance().setRadioCapability(rafs);
3979 } catch (RuntimeException e) {
3980 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3981 }
3982 }
3983
3984 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003985 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003986 Phone phone = PhoneFactory.getPhone(phoneId);
3987 if (phone == null) {
3988 return RadioAccessFamily.RAF_UNKNOWN;
3989 }
3990 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003992 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003993 return RadioAccessFamily.RAF_UNKNOWN;
3994 }
3995
Malcolm Chenaabec062018-02-28 15:00:40 -08003996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004002 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004003
4004 @Override
4005 public void enableVideoCalling(boolean enable) {
4006 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004007
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004014 }
4015
4016 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004017 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4019 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4020 return false;
4021 }
Svet Ganovb320e182015-04-16 12:30:10 -07004022
Malcolm Chenaabec062018-02-28 15:00:40 -08004023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 // Check the user preference and the system-level IMS setting. Even if the user has
4026 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4027 // In the long run, we may instead need to check if there exists a connection service
4028 // which can support video calling.
4029 ImsManager imsManager =
4030 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4031 return imsManager.isVtEnabledByPlatform()
4032 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4033 && imsManager.isVtEnabledByUser();
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004037 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004038
Andrew Leea1239f22015-03-02 17:44:07 -08004039 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004040 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4042 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4043 return false;
4044 }
4045
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 CarrierConfigManager configManager =
4049 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4050 return configManager.getConfigForSubId(mPhone.getSubId())
4051 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
Andrew Leea1239f22015-03-02 17:44:07 -08004055 }
4056
4057 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004058 public boolean isWorldPhone(int subId, String callingPackage) {
4059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4060 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4061 return false;
4062 }
4063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 CarrierConfigManager configManager =
4067 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4068 return configManager.getConfigForSubId(mPhone.getSubId())
4069 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Andrew Leea1239f22015-03-02 17:44:07 -08004073 }
4074
Andrew Lee9431b832015-03-09 18:46:45 -07004075 @Override
4076 public boolean isTtyModeSupported() {
4077 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004078 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004079 }
4080
4081 @Override
4082 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
Andrew Lee9431b832015-03-09 18:46:45 -07004089 }
4090
Hall Liu98187582018-01-22 19:15:32 -08004091 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4095 mPhone.getSubId()).getBoolean(
4096 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4097 boolean isDeviceSupported =
4098 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4099 return isCarrierSupported && isDeviceSupported;
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Hall Liu98187582018-01-22 19:15:32 -08004103 }
4104
Hall Liu3ad5f012018-04-06 16:23:39 -07004105 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 return isRttSupported() && Settings.Secure.getInt(
4109 mPhone.getContext().getContentResolver(),
4110 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004114 }
4115
Sanket Padawe7310cc72015-01-14 09:53:20 -08004116 /**
4117 * Returns the unique device ID of phone, for example, the IMEI for
4118 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4119 *
4120 * <p>Requires Permission:
4121 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4122 */
4123 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004124 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004125 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004126 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004127 return null;
4128 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004129 int subId = phone.getSubId();
4130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4131 mApp, subId, callingPackage, "getDeviceId")) {
4132 return null;
4133 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004134
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 return phone.getDeviceId();
4138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004141 }
4142
Ping Sunc67b7c22016-03-02 19:16:45 +08004143 /**
4144 * {@hide}
4145 * Returns the IMS Registration Status on a particular subid
4146 *
4147 * @param subId
4148 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004149 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004150 Phone phone = getPhone(subId);
4151 if (phone != null) {
4152 return phone.isImsRegistered();
4153 } else {
4154 return false;
4155 }
4156 }
4157
Santos Cordon7a1885b2015-02-03 11:15:19 -08004158 @Override
4159 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004166 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004167
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004168 /**
4169 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004170 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004171 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004172 final long identity = Binder.clearCallingIdentity();
4173 try {
4174 Phone phone = getPhone(subId);
4175 if (phone != null) {
4176 return phone.isWifiCallingEnabled();
4177 } else {
4178 return false;
4179 }
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004182 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004183 }
4184
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004185 /**
4186 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004187 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004188 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004189 final long identity = Binder.clearCallingIdentity();
4190 try {
4191 Phone phone = getPhone(subId);
4192 if (phone != null) {
4193 return phone.isVolteEnabled();
4194 } else {
4195 return false;
4196 }
4197 } finally {
4198 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004199 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004200 }
Svet Ganovb320e182015-04-16 12:30:10 -07004201
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004202 /**
4203 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004204 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004205 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004206 final long identity = Binder.clearCallingIdentity();
4207 try {
4208 Phone phone = getPhone(subId);
4209 if (phone != null) {
4210 return phone.isVideoEnabled();
4211 } else {
4212 return false;
4213 }
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004216 }
4217 }
4218
4219 /**
4220 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4221 * defined in {@link ImsRegistrationImplBase}.
4222 */
4223 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 Phone phone = getPhone(subId);
4227 if (phone != null) {
4228 return phone.getImsRegistrationTech();
4229 } else {
4230 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4231 }
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004234 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004235 }
4236
Stuart Scott8eef64f2015-04-08 15:13:54 -07004237 @Override
4238 public void factoryReset(int subId) {
4239 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004240 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4241 return;
4242 }
4243
Svet Ganovcc087f82015-05-12 20:35:54 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004246 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4247 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004248 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004249 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004250 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4251 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004252 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004253 }
4254 } finally {
4255 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004256 }
4257 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004258
4259 @Override
4260 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 // We query all subscriptions instead of just the active ones, because
4264 // this might be called early on in the provisioning flow when the
4265 // subscriptions potentially aren't active yet.
4266 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4267 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004268 return null;
4269 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004270
Malcolm Chenaabec062018-02-28 15:00:40 -08004271 // This function may be called very early, say, from the setup wizard, at
4272 // which point we won't have a default subscription set. If that's the case
4273 // we just choose the first, which will be valid in "most cases".
4274 final int defaultSubId = getDefaultSubscription();
4275 SubscriptionInfo info = null;
4276 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4277 info = slist.get(0);
4278 } else {
4279 for (SubscriptionInfo item : slist) {
4280 if (item.getSubscriptionId() == defaultSubId) {
4281 info = item;
4282 break;
4283 }
4284 }
4285
4286 if (info == null) {
4287 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004288 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004289 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004290
Malcolm Chenaabec062018-02-28 15:00:40 -08004291 // Try and fetch the locale from the carrier properties or from the SIM language
4292 // preferences (EF-PL and EF-LI)...
4293 final int mcc = info.getMcc();
4294 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4295 String simLanguage = null;
4296 if (defaultPhone != null) {
4297 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4298 if (localeFromDefaultSim != null) {
4299 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4300 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4301 return localeFromDefaultSim.toLanguageTag();
4302 } else {
4303 simLanguage = localeFromDefaultSim.getLanguage();
4304 }
4305 }
4306 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004307
Malcolm Chenaabec062018-02-28 15:00:40 -08004308 // The SIM language preferences only store a language (e.g. fr = French), not an
4309 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4310 // the SIM and carrier preferences does not include a country we add the country
4311 // determined from the SIM MCC to provide an exact locale.
4312 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4313 simLanguage);
4314 if (mccLocale != null) {
4315 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4316 return mccLocale.toLanguageTag();
4317 }
4318
4319 if (DBG) log("No locale found - returning null");
4320 return null;
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004324 }
4325
4326 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004327 return mSubscriptionController.getAllSubInfoList(
4328 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004329 }
4330
Malcolm Chenaabec062018-02-28 15:00:40 -08004331 /**
4332 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4333 */
4334 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4335 return mSubscriptionController.getActiveSubscriptionInfoList(
4336 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004337 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004338
Chenjie Yu1ba97252018-01-11 18:16:20 -08004339 private final ModemActivityInfo mLastModemActivityInfo =
4340 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4341
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004342 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004343 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4344 * representing the state of the modem.
4345 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004346 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4347 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004348 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004349 */
4350 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004351 public void requestModemActivityInfo(ResultReceiver result) {
4352 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004353 ModemActivityInfo ret = null;
Adam Lesinski903a54c2016-04-11 14:49:52 -07004354
Malcolm Chenaabec062018-02-28 15:00:40 -08004355 final long identity = Binder.clearCallingIdentity();
4356 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004357 synchronized (mLastModemActivityInfo) {
4358 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
4359 null);
4360 if (info != null) {
4361 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4362 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4363 mergedTxTimeMs[i] =
4364 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4365 }
4366 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4367 mLastModemActivityInfo.setSleepTimeMillis(
4368 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4369 mLastModemActivityInfo.setIdleTimeMillis(
4370 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4371 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4372 mLastModemActivityInfo.setRxTimeMillis(
4373 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4374 mLastModemActivityInfo.setEnergyUsed(
4375 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004376 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004377 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4378 mLastModemActivityInfo.getSleepTimeMillis(),
4379 mLastModemActivityInfo.getIdleTimeMillis(),
4380 mLastModemActivityInfo.getTxTimeMillis(),
4381 mLastModemActivityInfo.getRxTimeMillis(),
4382 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004383 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004384 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004385 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004386 result.send(0, bundle);
4387 } finally {
4388 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004389 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004390 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004391
4392 /**
4393 * {@hide}
4394 * Returns the service state information on specified subscription.
4395 */
4396 @Override
4397 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004399 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004400 return null;
4401 }
4402
Malcolm Chenaabec062018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 final Phone phone = getPhone(subId);
4406 if (phone == null) {
4407 return null;
4408 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004409
Malcolm Chenaabec062018-02-28 15:00:40 -08004410 return phone.getServiceState();
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004414 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004415
4416 /**
4417 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4418 *
4419 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4420 * voicemail ringtone.
4421 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4422 * PhoneAccount.
4423 */
4424 @Override
4425 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004426 final long identity = Binder.clearCallingIdentity();
4427 try {
4428 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4429 if (phone == null) {
4430 phone = mPhone;
4431 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004432
Malcolm Chenaabec062018-02-28 15:00:40 -08004433 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004437 }
4438
4439 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004440 * Sets the per-account voicemail ringtone.
4441 *
4442 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4443 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4444 *
4445 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4446 * voicemail ringtone.
4447 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4448 * PhoneAccount.
4449 */
4450 @Override
4451 public void setVoicemailRingtoneUri(String callingPackage,
4452 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4453 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4454 if (!TextUtils.equals(callingPackage,
4455 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4457 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4458 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004459 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004460
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
4463 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4464 if (phone == null) {
4465 phone = mPhone;
4466 }
4467 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4468 } finally {
4469 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004470 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004471 }
4472
4473 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004474 * Returns whether vibration is set for voicemail notification in Phone settings.
4475 *
4476 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4477 * voicemail vibration setting.
4478 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4479 */
4480 @Override
4481 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4485 if (phone == null) {
4486 phone = mPhone;
4487 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004488
Malcolm Chenaabec062018-02-28 15:00:40 -08004489 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004493 }
4494
Youhan Wange64578a2016-05-02 15:32:42 -07004495 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004496 * Sets the per-account voicemail vibration.
4497 *
4498 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4499 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4500 *
4501 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4502 * voicemail vibration setting.
4503 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4504 * specific PhoneAccount.
4505 */
4506 @Override
4507 public void setVoicemailVibrationEnabled(String callingPackage,
4508 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4510 if (!TextUtils.equals(callingPackage,
4511 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4513 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4514 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004515 }
4516
Malcolm Chenaabec062018-02-28 15:00:40 -08004517 final long identity = Binder.clearCallingIdentity();
4518 try {
4519 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4520 if (phone == null) {
4521 phone = mPhone;
4522 }
4523 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004526 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004527 }
4528
4529 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004530 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4531 *
4532 * @throws SecurityException if the caller does not have the required permission
4533 */
4534 private void enforceReadPrivilegedPermission() {
4535 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4536 null);
4537 }
4538
4539 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004540 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4541 * permission.
4542 *
4543 * @throws SecurityException if the caller does not have the required permission
4544 */
4545 private void enforceSendSmsPermission() {
4546 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4547 }
4548
4549 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004550 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004551 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004552 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004553 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004554 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004555 final long identity = Binder.clearCallingIdentity();
4556 try {
4557 ComponentName componentName =
4558 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4559 if (componentName == null) {
4560 throw new SecurityException(
4561 "Caller not current active visual voicemail package[null]");
4562 }
4563 String vvmPackage = componentName.getPackageName();
4564 if (!callingPackage.equals(vvmPackage)) {
4565 throw new SecurityException("Caller not current active visual voicemail package["
4566 + vvmPackage + "]");
4567 }
4568 } finally {
4569 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004570 }
4571 }
4572
4573 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004574 * Return the application ID for the app type.
4575 *
4576 * @param subId the subscription ID that this request applies to.
4577 * @param appType the uicc app type.
4578 * @return Application ID for specificied app type, or null if no uicc.
4579 */
4580 @Override
4581 public String getAidForAppType(int subId, int appType) {
4582 enforceReadPrivilegedPermission();
4583 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004584
4585 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004586 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004587 if (phone == null) {
4588 return null;
4589 }
4590 String aid = null;
4591 try {
4592 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4593 .getApplicationByType(appType).getAid();
4594 } catch (Exception e) {
4595 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4596 }
4597 return aid;
4598 } finally {
4599 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004600 }
Youhan Wange64578a2016-05-02 15:32:42 -07004601 }
4602
Youhan Wang4001d252016-05-11 10:29:41 -07004603 /**
4604 * Return the Electronic Serial Number.
4605 *
4606 * @param subId the subscription ID that this request applies to.
4607 * @return ESN or null if error.
4608 */
4609 @Override
4610 public String getEsn(int subId) {
4611 enforceReadPrivilegedPermission();
4612 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004613
4614 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004615 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004616 if (phone == null) {
4617 return null;
4618 }
4619 String esn = null;
4620 try {
4621 esn = phone.getEsn();
4622 } catch (Exception e) {
4623 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4624 }
4625 return esn;
4626 } finally {
4627 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004628 }
Youhan Wang4001d252016-05-11 10:29:41 -07004629 }
4630
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004631 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004632 * Return the Preferred Roaming List Version.
4633 *
4634 * @param subId the subscription ID that this request applies to.
4635 * @return PRLVersion or null if error.
4636 */
4637 @Override
4638 public String getCdmaPrlVersion(int subId) {
4639 enforceReadPrivilegedPermission();
4640 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004641
4642 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004643 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004644 if (phone == null) {
4645 return null;
4646 }
4647 String cdmaPrlVersion = null;
4648 try {
4649 cdmaPrlVersion = phone.getCdmaPrlVersion();
4650 } catch (Exception e) {
4651 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4652 }
4653 return cdmaPrlVersion;
4654 } finally {
4655 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004656 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004657 }
4658
4659 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004660 * Get snapshot of Telephony histograms
4661 * @return List of Telephony histograms
4662 * @hide
4663 */
4664 @Override
4665 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4667 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004668
4669 final long identity = Binder.clearCallingIdentity();
4670 try {
4671 return RIL.getTelephonyRILTimingHistograms();
4672 } finally {
4673 Binder.restoreCallingIdentity(identity);
4674 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004675 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004676
4677 /**
4678 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004679 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004680 * Require system privileges. In the future we may add this to carrier APIs.
4681 *
4682 * @return The number of carriers set successfully, should match length of carriers
4683 */
4684 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004685 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004686 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004687
Meng Wang9b7c4e92017-02-17 11:41:27 -08004688 if (carriers == null) {
4689 throw new NullPointerException("carriers cannot be null");
4690 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004691
Malcolm Chenaabec062018-02-28 15:00:40 -08004692 final long identity = Binder.clearCallingIdentity();
4693 try {
4694 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4695 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4696 return retVal[0];
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004700 }
4701
4702 /**
4703 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004704 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004705 * Require system privileges. In the future we may add this to carrier APIs.
4706 *
4707 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4708 * means all carriers are allowed.
4709 */
4710 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004711 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004712 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004713
4714 final long identity = Binder.clearCallingIdentity();
4715 try {
4716 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4717 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004721 }
4722
fionaxu59545b42016-05-25 15:53:37 -07004723 /**
4724 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4725 * @param subId the subscription ID that this action applies to.
4726 * @param enabled control enable or disable metered apns.
4727 * {@hide}
4728 */
4729 @Override
4730 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4731 enforceModifyPermission();
4732 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004733
4734 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004735 if (phone == null) {
4736 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4737 return;
4738 }
4739 try {
4740 phone.carrierActionSetMeteredApnsEnabled(enabled);
4741 } catch (Exception e) {
4742 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004743 } finally {
4744 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004745 }
4746 }
4747
4748 /**
4749 * Action set from carrier signalling broadcast receivers to enable/disable radio
4750 * @param subId the subscription ID that this action applies to.
4751 * @param enabled control enable or disable radio.
4752 * {@hide}
4753 */
4754 @Override
4755 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4756 enforceModifyPermission();
4757 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004758
4759 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004760 if (phone == null) {
4761 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4762 return;
4763 }
4764 try {
4765 phone.carrierActionSetRadioEnabled(enabled);
4766 } catch (Exception e) {
4767 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004768 } finally {
4769 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004770 }
4771 }
4772
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004773 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004774 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4775 * network status based on which carrier apps could apply actions accordingly,
4776 * enable/disable default url handler for example.
4777 *
4778 * @param subId the subscription ID that this action applies to.
4779 * @param report control start/stop reporting the default network status.
4780 * {@hide}
4781 */
4782 @Override
4783 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4784 enforceModifyPermission();
4785 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004786
4787 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004788 if (phone == null) {
4789 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4790 return;
4791 }
4792 try {
4793 phone.carrierActionReportDefaultNetworkStatus(report);
4794 } catch (Exception e) {
4795 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004796 } finally {
4797 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004798 }
4799 }
4800
4801 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004802 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4803 * bug report is being generated.
4804 */
4805 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004806 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004807 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4808 != PackageManager.PERMISSION_GRANTED) {
4809 writer.println("Permission Denial: can't dump Phone from pid="
4810 + Binder.getCallingPid()
4811 + ", uid=" + Binder.getCallingUid()
4812 + "without permission "
4813 + android.Manifest.permission.DUMP);
4814 return;
4815 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004816 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004817 }
Jack Yueb89b242016-06-22 13:27:47 -07004818
Brad Ebingerdac2f002018-04-03 15:17:52 -07004819 @Override
4820 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4821 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4822 throws RemoteException {
4823 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4824 }
4825
Jack Yueb89b242016-06-22 13:27:47 -07004826 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004827 * Get aggregated video call data usage since boot.
4828 *
4829 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4830 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004831 * {@hide}
4832 */
4833 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004834 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004835 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4836 null);
4837
Malcolm Chenaabec062018-02-28 15:00:40 -08004838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 // NetworkStatsService keeps tracking the active network interface and identity. It
4841 // records the delta with the corresponding network identity.
4842 // We just return the total video call data usage snapshot since boot.
4843 Phone phone = getPhone(subId);
4844 if (phone != null) {
4845 return phone.getVtDataUsage(perUidStats);
4846 }
4847 return null;
4848 } finally {
4849 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004850 }
Jack Yueb89b242016-06-22 13:27:47 -07004851 }
Jack Yu75ab2952016-07-08 14:29:33 -07004852
4853 /**
4854 * Policy control of data connection. Usually used when data limit is passed.
4855 * @param enabled True if enabling the data, otherwise disabling.
4856 * @param subId Subscription index
4857 * {@hide}
4858 */
4859 @Override
4860 public void setPolicyDataEnabled(boolean enabled, int subId) {
4861 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004862
4863 final long identity = Binder.clearCallingIdentity();
4864 try {
4865 Phone phone = getPhone(subId);
4866 if (phone != null) {
4867 phone.setPolicyDataEnabled(enabled);
4868 }
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004871 }
4872 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004873
4874 /**
4875 * Get Client request stats
4876 * @return List of Client Request Stats
4877 * @hide
4878 */
4879 @Override
4880 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004882 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004883 return null;
4884 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004885 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004886
Malcolm Chenaabec062018-02-28 15:00:40 -08004887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 if (phone != null) {
4890 return phone.getClientRequestStats();
4891 }
4892
4893 return null;
4894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004897 }
4898
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004899 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004900 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004901 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004902 }
Jack Yueb4124c2017-02-16 15:32:43 -08004903
4904 /**
Grace Chen70990072017-03-24 17:21:30 -07004905 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004906 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004907 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004908 * @param state State of SIM (power down, power up, pass through)
4909 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4910 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4911 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004912 *
4913 **/
4914 @Override
Grace Chen70990072017-03-24 17:21:30 -07004915 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004916 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004917 Phone phone = PhoneFactory.getPhone(slotIndex);
4918
Malcolm Chenaabec062018-02-28 15:00:40 -08004919 final long identity = Binder.clearCallingIdentity();
4920 try {
4921 if (phone != null) {
4922 phone.setSimPowerState(state);
4923 }
4924 } finally {
4925 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004926 }
4927 }
Shuo Qiandd210312017-04-12 22:11:33 +00004928
Tyler Gunn65d45c22017-06-05 11:22:26 -07004929 private boolean isUssdApiAllowed(int subId) {
4930 CarrierConfigManager configManager =
4931 (CarrierConfigManager) mPhone.getContext().getSystemService(
4932 Context.CARRIER_CONFIG_SERVICE);
4933 if (configManager == null) {
4934 return false;
4935 }
4936 PersistableBundle pb = configManager.getConfigForSubId(subId);
4937 if (pb == null) {
4938 return false;
4939 }
4940 return pb.getBoolean(
4941 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4942 }
4943
Shuo Qiandd210312017-04-12 22:11:33 +00004944 /**
4945 * Check if phone is in emergency callback mode
4946 * @return true if phone is in emergency callback mode
4947 * @param subId sub id
4948 */
goneil9c5f4872017-12-05 14:07:56 -08004949 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004950 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004951 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004952 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004953
4954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 if (phone != null) {
4957 return phone.isInEcm();
4958 } else {
4959 return false;
4960 }
4961 } finally {
4962 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004963 }
4964 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004965
4966 /**
4967 * Get the current signal strength information for the given subscription.
4968 * Because this information is not updated when the device is in a low power state
4969 * it should not be relied-upon to be current.
4970 * @param subId Subscription index
4971 * @return the most recent cached signal strength info from the modem
4972 */
4973 @Override
4974 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004975 final long identity = Binder.clearCallingIdentity();
4976 try {
4977 Phone p = getPhone(subId);
4978 if (p == null) {
4979 return null;
4980 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004981
Malcolm Chenaabec062018-02-28 15:00:40 -08004982 return p.getSignalStrength();
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004986 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004987
4988 @Override
4989 public UiccSlotInfo[] getUiccSlotsInfo() {
4990 enforceReadPrivilegedPermission();
4991
Malcolm Chenaabec062018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004995 if (slots == null) {
4996 Rlog.i(LOG_TAG, "slots is null.");
4997 return null;
4998 }
4999
Malcolm Chenaabec062018-02-28 15:00:40 -08005000 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5001 for (int i = 0; i < slots.length; i++) {
5002 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005003 if (slot == null) {
5004 continue;
5005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005006
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005007 String cardId;
5008 UiccCard card = slot.getUiccCard();
5009 if (card != null) {
5010 cardId = card.getCardId();
5011 } else {
5012 cardId = slot.getIccId();
5013 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005014
Malcolm Chenaabec062018-02-28 15:00:40 -08005015 int cardState = 0;
5016 switch (slot.getCardState()) {
5017 case CARDSTATE_ABSENT:
5018 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5019 break;
5020 case CARDSTATE_PRESENT:
5021 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5022 break;
5023 case CARDSTATE_ERROR:
5024 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5025 break;
5026 case CARDSTATE_RESTRICTED:
5027 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5028 break;
5029 default:
5030 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005031
Malcolm Chenaabec062018-02-28 15:00:40 -08005032 }
5033
5034 infos[i] = new UiccSlotInfo(
5035 slot.isActive(),
5036 slot.isEuicc(),
5037 cardId,
5038 cardState,
5039 slot.getPhoneId(),
5040 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005041 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005042 return infos;
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005045 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005046 }
5047
5048 @Override
5049 public boolean switchSlots(int[] physicalSlots) {
5050 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005051
5052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005058 }
Jack Yu4c988042018-02-27 15:30:01 -08005059
5060 @Override
5061 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5062 enforceModifyPermission();
5063 final Phone phone = getPhone(subId);
5064 if (phone == null) {
5065 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5066 return;
5067 }
5068
Malcolm Chenaabec062018-02-28 15:00:40 -08005069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 phone.setRadioIndicationUpdateMode(filters, mode);
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
Jack Yu4c988042018-02-27 15:30:01 -08005075 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005076
5077 /**
goneil47ffb6e2018-04-06 15:40:58 -07005078 * A test API to reload the UICC profile.
5079 *
5080 * <p>Requires that the calling app has permission
5081 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5082 * @hide
5083 */
5084 @Override
5085 public void refreshUiccProfile(int subId) {
5086 enforceModifyPermission();
5087
5088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 Phone phone = getPhone(subId);
5091 if (phone == null) {
5092 return;
5093 }
5094 UiccCard uiccCard = phone.getUiccCard();
5095 if (uiccCard == null) {
5096 return;
5097 }
5098 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5099 if (uiccProfile == null) {
5100 return;
5101 }
5102 uiccProfile.refresh();
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
5106 }
5107
5108 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005109 * Returns false if the mobile data is disabled by default, otherwise return true.
5110 */
5111 private boolean getDefaultDataEnabled() {
5112 return "true".equalsIgnoreCase(
5113 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5114 }
5115
5116 /**
5117 * Returns true if the data roaming is enabled by default, i.e the system property
5118 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5119 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5120 */
5121 private boolean getDefaultDataRoamingEnabled(int subId) {
5122 final CarrierConfigManager configMgr = (CarrierConfigManager)
5123 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5124 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5125 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5126 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5127 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5128 return isDataRoamingEnabled;
5129 }
5130
5131 /**
5132 * Returns the default network type for the given {@code subId}, if the default network type is
5133 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5134 */
5135 private int getDefaultNetworkType(int subId) {
5136 return Integer.parseInt(
5137 TelephonyManager.getTelephonyProperty(
5138 mSubscriptionController.getPhoneId(subId),
5139 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5140 String.valueOf(Phone.PREFERRED_NT_MODE)));
5141 }
fionaxua13278b2018-03-21 00:08:13 -07005142
5143 @Override
5144 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5145 gid1, String gid2, String plmn, String spn) {
5146 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005147
5148 final long identity = Binder.clearCallingIdentity();
5149 try {
5150 final Phone phone = getPhone(subId);
5151 if (phone == null) {
5152 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5153 return;
5154 }
5155 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005158 }
fionaxua13278b2018-03-21 00:08:13 -07005159 }
5160
5161 @Override
5162 public int getCarrierIdListVersion(int subId) {
5163 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005164
5165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 final Phone phone = getPhone(subId);
5168 if (phone == null) {
5169 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5170 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5171 }
5172 return phone.getCarrierIdListVersion();
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005175 }
fionaxua13278b2018-03-21 00:08:13 -07005176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005177}