blob: 2df3bbece2225cc3eca68ced3176cf5865b1bd5d [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) {
Nathan Harold54a07f92018-08-09 16:20:42 -07001922 if (targetSdk > android.os.Build.VERSION_CODES.P) return null;
Nathan Haroldb4d55612018-07-20 13:13:08 -07001923
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1925 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1926 return null;
1927 }
Svetoslav64fad262015-04-14 14:35:21 -07001928
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001929 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930
Nathan Haroldf180aac2018-06-01 18:43:55 -07001931 List<CellInfo> info = getAllCellInfo(callingPackage);
1932 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933
Nathan Haroldf180aac2018-06-01 18:43:55 -07001934 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1935 for (CellInfo ci : info) {
1936 if (ci instanceof CellInfoGsm) {
1937 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1938 } else if (ci instanceof CellInfoWcdma) {
1939 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001942 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
1945
1946 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001947 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001948 mPhone.getContext().getSystemService(AppOpsManager.class)
1949 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001950 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001951 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001952 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001955 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001956 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001957 final long identity = Binder.clearCallingIdentity();
1958 try {
1959 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1960 for (Phone phone : PhoneFactory.getPhones()) {
1961 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1962 if (info != null) cellInfos.addAll(info);
1963 }
1964 return cellInfos;
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968 }
1969
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001970 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001972 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001974
1975 final long identity = Binder.clearCallingIdentity();
1976 try {
1977 mPhone.setCellInfoListRate(rateInMillis, workSource);
1978 } finally {
1979 Binder.restoreCallingIdentity(identity);
1980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
1982
Shishir Agrawala9f32182016-04-12 12:00:16 -07001983 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001984 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001985 Phone phone = PhoneFactory.getPhone(slotIndex);
1986 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001987 return null;
1988 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001989 int subId = phone.getSubId();
1990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1991 mApp, subId, callingPackage, "getImeiForSlot")) {
1992 return null;
1993 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001994
1995 final long identity = Binder.clearCallingIdentity();
1996 try {
1997 return phone.getImei();
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
2000 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002001 }
2002
2003 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002004 public String getTypeAllocationCodeForSlot(int slotIndex) {
2005 Phone phone = PhoneFactory.getPhone(slotIndex);
2006 String tac = null;
2007 if (phone != null) {
2008 String imei = phone.getImei();
2009 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2010 }
2011 return tac;
2012 }
2013
2014 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002015 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002016 Phone phone = PhoneFactory.getPhone(slotIndex);
2017 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002018 return null;
2019 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002020 int subId = phone.getSubId();
2021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2022 mApp, subId, callingPackage, "getMeidForSlot")) {
2023 return null;
2024 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002025
2026 final long identity = Binder.clearCallingIdentity();
2027 try {
2028 return phone.getMeid();
2029 } finally {
2030 Binder.restoreCallingIdentity(identity);
2031 }
Jack Yu2af8d712017-03-15 17:14:14 -07002032 }
2033
2034 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002035 public String getManufacturerCodeForSlot(int slotIndex) {
2036 Phone phone = PhoneFactory.getPhone(slotIndex);
2037 String manufacturerCode = null;
2038 if (phone != null) {
2039 String meid = phone.getMeid();
2040 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2041 }
2042 return manufacturerCode;
2043 }
2044
2045 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002046 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002047 Phone phone = PhoneFactory.getPhone(slotIndex);
2048 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002049 return null;
2050 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002051 int subId = phone.getSubId();
2052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2053 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2054 return null;
2055 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002056
2057 final long identity = Binder.clearCallingIdentity();
2058 try {
2059 return phone.getDeviceSvn();
2060 } finally {
2061 Binder.restoreCallingIdentity(identity);
2062 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002063 }
2064
fionaxu43304da2017-11-27 22:51:16 -08002065 @Override
2066 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002067 final long identity = Binder.clearCallingIdentity();
2068 try {
2069 final Phone phone = getPhone(subId);
2070 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2071 } finally {
2072 Binder.restoreCallingIdentity(identity);
2073 }
fionaxu43304da2017-11-27 22:51:16 -08002074 }
2075
2076 @Override
2077 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 final Phone phone = getPhone(subId);
2081 return phone == null ? null : phone.getCarrierName();
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
2084 }
fionaxu43304da2017-11-27 22:51:16 -08002085 }
2086
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 //
2088 // Internal helper methods.
2089 //
2090
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002091 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2093 *
2094 * @throws SecurityException if the caller does not have the required permission
2095 */
2096 private void enforceModifyPermission() {
2097 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2098 }
2099
2100 /**
2101 * Make sure the caller has the CALL_PHONE permission.
2102 *
2103 * @throws SecurityException if the caller does not have the required permission
2104 */
2105 private void enforceCallPermission() {
2106 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2107 }
2108
Stuart Scott8eef64f2015-04-08 15:13:54 -07002109 private void enforceConnectivityInternalPermission() {
2110 mApp.enforceCallingOrSelfPermission(
2111 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2112 "ConnectivityService");
2113 }
2114
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 private String createTelUrl(String number) {
2116 if (TextUtils.isEmpty(number)) {
2117 return null;
2118 }
2119
Jake Hambye994d462014-02-03 13:10:13 -08002120 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 }
2122
Ihab Awadf9e92732013-12-05 18:02:52 -08002123 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2125 }
2126
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002127 private static void logv(String msg) {
2128 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2129 }
2130
Ihab Awadf9e92732013-12-05 18:02:52 -08002131 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2133 }
2134
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002135 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002137 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002138 }
2139
Sanket Padawe356d7632015-06-22 14:03:32 -07002140 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002141 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002142 final long identity = Binder.clearCallingIdentity();
2143 try {
2144 final Phone phone = PhoneFactory.getPhone(slotIndex);
2145 if (phone == null) {
2146 return PhoneConstants.PHONE_TYPE_NONE;
2147 } else {
2148 return phone.getPhoneType();
2149 }
2150 } finally {
2151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 }
2154
2155 /**
2156 * Returns the CDMA ERI icon index to display
2157 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002158 @Override
2159 public int getCdmaEriIconIndex(String callingPackage) {
2160 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002161 }
2162
Sanket Padawe356d7632015-06-22 14:03:32 -07002163 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002164 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002166 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002167 return -1;
2168 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002169
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = getPhone(subId);
2173 if (phone != null) {
2174 return phone.getCdmaEriIconIndex();
2175 } else {
2176 return -1;
2177 }
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
2183 /**
2184 * Returns the CDMA ERI icon mode,
2185 * 0 - ON
2186 * 1 - FLASHING
2187 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002188 @Override
2189 public int getCdmaEriIconMode(String callingPackage) {
2190 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002191 }
2192
Sanket Padawe356d7632015-06-22 14:03:32 -07002193 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002194 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002196 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002197 return -1;
2198 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002199
2200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 final Phone phone = getPhone(subId);
2203 if (phone != null) {
2204 return phone.getCdmaEriIconMode();
2205 } else {
2206 return -1;
2207 }
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212
2213 /**
2214 * Returns the CDMA ERI text,
2215 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002216 @Override
2217 public String getCdmaEriText(String callingPackage) {
2218 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002222 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002224 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002225 return null;
2226 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002227
2228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 final Phone phone = getPhone(subId);
2231 if (phone != null) {
2232 return phone.getCdmaEriText();
2233 } else {
2234 return null;
2235 }
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002242 * Returns the CDMA MDN.
2243 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2247 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002248
2249 final long identity = Binder.clearCallingIdentity();
2250 try {
2251 final Phone phone = getPhone(subId);
2252 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2253 return phone.getLine1Number();
2254 } else {
2255 return null;
2256 }
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002259 }
2260 }
2261
2262 /**
2263 * Returns the CDMA MIN.
2264 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002266 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2268 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002269
2270 final long identity = Binder.clearCallingIdentity();
2271 try {
2272 final Phone phone = getPhone(subId);
2273 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2274 return phone.getCdmaMin();
2275 } else {
2276 return null;
2277 }
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002280 }
2281 }
2282
2283 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 * Returns true if CDMA provisioning needs to run.
2285 */
2286 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 return mPhone.needsOtaServiceProvisioning();
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
2295 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002296 * Sets the voice mail number of a given subId.
2297 */
2298 @Override
2299 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002300 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002301
2302 final long identity = Binder.clearCallingIdentity();
2303 try {
2304 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2305 new Pair<String, String>(alphaTag, number), new Integer(subId));
2306 return success;
2307 } finally {
2308 Binder.restoreCallingIdentity(identity);
2309 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002310 }
2311
Ta-wei Yen87c49842016-05-13 21:19:52 -07002312 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002313 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2315 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2316 if (!TextUtils.equals(callingPackage, systemDialer)) {
2317 throw new SecurityException("caller must be system dialer");
2318 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002319
2320 final long identity = Binder.clearCallingIdentity();
2321 try {
2322 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2323 if (phoneAccountHandle == null) {
2324 return null;
2325 }
2326 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002329 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002330 }
2331
2332 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002333 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002334 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002336 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002337 return null;
2338 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002339
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 return RemoteVvmTaskManager
2343 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
2346 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002347 }
2348
2349 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002350 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2351 VisualVoicemailSmsFilterSettings settings) {
2352 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002353
2354 final long identity = Binder.clearCallingIdentity();
2355 try {
2356 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2357 mPhone.getContext(), callingPackage, subId, settings);
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
2360 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002361 }
2362
2363 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002364 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2365 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002366
2367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2370 mPhone.getContext(), callingPackage, subId);
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
2373 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002374 }
2375
2376 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002377 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2378 String callingPackage, int subId) {
2379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002380
2381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2384 mPhone.getContext(), callingPackage, subId);
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002388 }
2389
2390 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002391 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002392 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2397 mPhone.getContext(), subId);
2398 } finally {
2399 Binder.restoreCallingIdentity(identity);
2400 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002401 }
2402
2403 @Override
2404 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2405 String number, int port, String text, PendingIntent sentIntent) {
2406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002407 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002408 enforceSendSmsPermission();
2409 // Make the calls as the phone process.
2410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2413 if (port == 0) {
2414 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2415 sentIntent, null, false);
2416 } else {
2417 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2418 smsManager.sendDataMessageWithSelfPermissions(number, null,
2419 (short) port, data, sentIntent, null);
2420 }
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002424 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002425 /**
fionaxu0152e512016-11-14 13:36:14 -08002426 * Sets the voice activation state of a given subId.
2427 */
2428 @Override
2429 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2431 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 final Phone phone = getPhone(subId);
2436 if (phone != null) {
2437 phone.setVoiceActivationState(activationState);
2438 } else {
2439 loge("setVoiceActivationState fails with invalid subId: " + subId);
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002443 }
2444 }
2445
2446 /**
2447 * Sets the data activation state of a given subId.
2448 */
2449 @Override
2450 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2452 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 final Phone phone = getPhone(subId);
2457 if (phone != null) {
2458 phone.setDataActivationState(activationState);
2459 } else {
2460 loge("setVoiceActivationState fails with invalid subId: " + subId);
2461 }
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002464 }
2465 }
2466
2467 /**
2468 * Returns the voice activation state of a given subId.
2469 */
2470 @Override
2471 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002472 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002473
fionaxu0152e512016-11-14 13:36:14 -08002474 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 if (phone != null) {
2478 return phone.getVoiceActivationState();
2479 } else {
2480 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002484 }
2485 }
2486
2487 /**
2488 * Returns the data activation state of a given subId.
2489 */
2490 @Override
2491 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002492 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002493
fionaxu0152e512016-11-14 13:36:14 -08002494 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002495 final long identity = Binder.clearCallingIdentity();
2496 try {
2497 if (phone != null) {
2498 return phone.getDataActivationState();
2499 } else {
2500 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2501 }
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002504 }
2505 }
2506
2507 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 * Returns the unread count of voicemails
2509 */
2510 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002511 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002512 }
2513
2514 /**
2515 * Returns the unread count of voicemails for a subId
2516 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002518 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 final Phone phone = getPhone(subId);
2522 if (phone != null) {
2523 return phone.getVoiceMessageCount();
2524 } else {
2525 return 0;
2526 }
2527 } finally {
2528 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 }
2531
2532 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002533 * returns true, if the device is in a state where both voice and data
2534 * are supported simultaneously. This can change based on location or network condition.
2535 */
2536 @Override
2537 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 final Phone phone = getPhone(subId);
2541 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002545 }
2546
2547 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002548 * Send the dialer code if called from the current default dialer or the caller has
2549 * carrier privilege.
2550 * @param inputCode The dialer code to send
2551 */
2552 @Override
2553 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2554 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2555 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2556 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2558 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002559 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002560
2561 final long identity = Binder.clearCallingIdentity();
2562 try {
2563 mPhone.sendDialerSpecialCode(inputCode);
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
2566 }
fionaxu235cc5e2017-03-06 22:25:57 -08002567 }
2568
2569 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002570 * Returns the data network type.
2571 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 *
2573 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2574 */
2575 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002576 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(getDefaultSubscription());
2580 if (phone != null) {
2581 return phone.getServiceState().getDataNetworkType();
2582 } else {
2583 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002587 }
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
2590 /**
2591 * Returns the network type for a subId
2592 */
2593 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002594 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002596 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002597 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2598 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002599
Malcolm Chenaabec062018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone phone = getPhone(subId);
2603 if (phone != null) {
2604 return phone.getServiceState().getDataNetworkType();
2605 } else {
2606 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
2612
2613 /**
2614 * Returns the data network type
2615 */
2616 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002617 public int getDataNetworkType(String callingPackage) {
2618 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002619 }
2620
2621 /**
2622 * Returns the data network type for a subId
2623 */
2624 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002627 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2629 }
2630
Malcolm Chenaabec062018-02-28 15:00:40 -08002631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 final Phone phone = getPhone(subId);
2634 if (phone != null) {
2635 return phone.getServiceState().getDataNetworkType();
2636 } else {
2637 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 }
2643
2644 /**
Wink Saville36469e72014-06-11 15:17:00 -07002645 * Returns the Voice network type for a subId
2646 */
2647 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002648 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002650 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002651 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2652 }
2653
Malcolm Chenaabec062018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone phone = getPhone(subId);
2657 if (phone != null) {
2658 return phone.getServiceState().getVoiceNetworkType();
2659 } else {
2660 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
2667 /**
2668 * @return true if a ICC card is present
2669 */
2670 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002671 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002672 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2673 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002674 }
2675
2676 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002677 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002678 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002680 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 final Phone phone = PhoneFactory.getPhone(slotIndex);
2684 if (phone != null) {
2685 return phone.getIccCard().hasIccCard();
2686 } else {
2687 return false;
2688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693
2694 /**
2695 * Return if the current radio is LTE on CDMA. This
2696 * is a tri-state return value as for a period of time
2697 * the mode may be unknown.
2698 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002699 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002701 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002703 @Override
2704 public int getLteOnCdmaMode(String callingPackage) {
2705 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002706 }
2707
Sanket Padawe356d7632015-06-22 14:03:32 -07002708 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002709 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002711 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002712 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2713 }
2714
Malcolm Chenaabec062018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 final Phone phone = getPhone(subId);
2718 if (phone == null) {
2719 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2720 } else {
2721 return phone.getLteOnCdmaMode();
2722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 }
Wink Saville36469e72014-06-11 15:17:00 -07002726 }
2727
2728 public void setPhone(Phone phone) {
2729 mPhone = phone;
2730 }
2731
2732 /**
2733 * {@hide}
2734 * Returns Default subId, 0 in the case of single standby.
2735 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002736 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002737 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002738 }
2739
Shishir Agrawala9f32182016-04-12 12:00:16 -07002740 private int getSlotForDefaultSubscription() {
2741 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2742 }
2743
Wink Savilleb564aae2014-10-23 10:18:09 -07002744 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002745 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002747
2748 /**
2749 * @see android.telephony.TelephonyManager.WifiCallingChoices
2750 */
2751 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2755 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2756 getWhenToMakeWifiCallsDefaultPreference());
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
2759 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002760 }
2761
2762 /**
2763 * @see android.telephony.TelephonyManager.WifiCallingChoices
2764 */
2765 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2769 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2770 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
2773 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002774 }
2775
Sailesh Nepald1e68152013-12-12 19:08:02 -08002776 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002777 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002778 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002779 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002780
Shishir Agrawal566b7612013-10-28 14:41:00 -07002781 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002782 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2783 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2785 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002787
Malcolm Chenaabec062018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 if (TextUtils.equals(ISDR_AID, aid)) {
2791 // Only allows LPA to open logical channel to ISD-R.
2792 ComponentInfo bestComponent =
2793 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2794 if (bestComponent == null
2795 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2796 loge("The calling package is not allowed to access ISD-R.");
2797 throw new SecurityException(
2798 "The calling package is not allowed to access ISD-R.");
2799 }
Derek Tan740e1672017-06-27 14:56:27 -07002800 }
Derek Tan740e1672017-06-27 14:56:27 -07002801
Malcolm Chenaabec062018-02-28 15:00:40 -08002802 if (DBG) {
2803 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2804 }
2805 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2806 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2807 if (DBG) log("iccOpenLogicalChannel: " + response);
2808 return response;
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002812 }
2813
2814 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002815 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2817 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002818
Malcolm Chenaabec062018-02-28 15:00:40 -08002819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2822 if (channel < 0) {
2823 return false;
2824 }
2825 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2826 if (DBG) log("iccCloseLogicalChannel: " + success);
2827 return success;
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002831 }
2832
2833 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002834 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002835 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2837 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002838
Malcolm Chenaabec062018-02-28 15:00:40 -08002839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 if (DBG) {
2842 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2843 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2844 + p3 + " data=" + data);
2845 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846
Malcolm Chenaabec062018-02-28 15:00:40 -08002847 if (channel < 0) {
2848 return "";
2849 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002850
Malcolm Chenaabec062018-02-28 15:00:40 -08002851 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2852 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2853 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002854
Malcolm Chenaabec062018-02-28 15:00:40 -08002855 // Append the returned status code to the end of the response payload.
2856 String s = Integer.toHexString(
2857 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2858 if (response.payload != null) {
2859 s = IccUtils.bytesToHexString(response.payload) + s;
2860 }
2861 return s;
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002864 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002865 }
Jake Hambye994d462014-02-03 13:10:13 -08002866
Evan Charltonc66da362014-05-16 14:06:40 -07002867 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002868 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2869 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2871 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002872 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002873
Malcolm Chenaabec062018-02-28 15:00:40 -08002874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2877 && TextUtils.equals(ISDR_AID, data)) {
2878 // Only allows LPA to select ISD-R.
2879 ComponentInfo bestComponent =
2880 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2881 if (bestComponent == null
2882 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2883 loge("The calling package is not allowed to select ISD-R.");
2884 throw new SecurityException(
2885 "The calling package is not allowed to select ISD-R.");
2886 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002887 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002888
Malcolm Chenaabec062018-02-28 15:00:40 -08002889 if (DBG) {
2890 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2891 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2892 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002893
Malcolm Chenaabec062018-02-28 15:00:40 -08002894 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2895 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2896 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002897
Malcolm Chenaabec062018-02-28 15:00:40 -08002898 // Append the returned status code to the end of the response payload.
2899 String s = Integer.toHexString(
2900 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2901 if (response.payload != null) {
2902 s = IccUtils.bytesToHexString(response.payload) + s;
2903 }
2904 return s;
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002907 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002908 }
2909
2910 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002911 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002912 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2914 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002915
Malcolm Chenaabec062018-02-28 15:00:40 -08002916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 if (DBG) {
2919 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2920 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2921 }
2922
2923 IccIoResult response =
2924 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2925 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2926 subId);
2927
2928 if (DBG) {
2929 log("Exchange SIM_IO [R]" + response);
2930 }
2931
2932 byte[] result = null;
2933 int length = 2;
2934 if (response.payload != null) {
2935 length = 2 + response.payload.length;
2936 result = new byte[length];
2937 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2938 } else {
2939 result = new byte[length];
2940 }
2941
2942 result[length - 1] = (byte) response.sw2;
2943 result[length - 2] = (byte) response.sw1;
2944 return result;
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002947 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002948 }
2949
Nathan Haroldb3014052017-01-25 15:57:32 -08002950 /**
2951 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2952 * on a particular subscription
2953 */
sqianb6e41952018-03-12 14:54:01 -07002954 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2956 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2957 return null;
2958 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002959 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2960 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2961 return null;
2962 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002963
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2967 if (response instanceof String[]) {
2968 return (String[]) response;
2969 }
2970 // Response is an Exception of some kind,
2971 // which is signalled to the user as a NULL retval
2972 return null;
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002975 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002976 }
2977
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002978 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002979 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2981 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002982
Malcolm Chenaabec062018-02-28 15:00:40 -08002983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2986 if (response.payload == null) {
2987 return "";
2988 }
Evan Charltonc66da362014-05-16 14:06:40 -07002989
Malcolm Chenaabec062018-02-28 15:00:40 -08002990 // Append the returned status code to the end of the response payload.
2991 String s = Integer.toHexString(
2992 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2993 s = IccUtils.bytesToHexString(response.payload) + s;
2994 return s;
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
Evan Charltonc66da362014-05-16 14:06:40 -07002998 }
2999
Jake Hambye994d462014-02-03 13:10:13 -08003000 /**
3001 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3002 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3003 *
3004 * @param itemID the ID of the item to read
3005 * @return the NV item as a String, or null on error.
3006 */
3007 @Override
3008 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3010 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003011
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 if (DBG) log("nvReadItem: item " + itemID);
3015 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3016 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3017 return value;
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
Jake Hambye994d462014-02-03 13:10:13 -08003021 }
3022
3023 /**
3024 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3025 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3026 *
3027 * @param itemID the ID of the item to read
3028 * @param itemValue the value to write, as a String
3029 * @return true on success; false on any failure
3030 */
3031 @Override
3032 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3034 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003035
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3039 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3040 new Pair<Integer, String>(itemID, itemValue));
3041 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3042 return success;
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
Jake Hambye994d462014-02-03 13:10:13 -08003046 }
3047
3048 /**
3049 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3050 * Used for device configuration by some CDMA operators.
3051 *
3052 * @param preferredRoamingList byte array containing the new PRL
3053 * @return true on success; false on any failure
3054 */
3055 @Override
3056 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3058 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003059
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3063 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3064 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3065 return success;
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Jake Hambye994d462014-02-03 13:10:13 -08003069 }
3070
3071 /**
3072 * Perform the specified type of NV config reset.
3073 * Used for device configuration by some CDMA operators.
3074 *
3075 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3076 * @return true on success; false on any failure
3077 */
3078 @Override
3079 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3081 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003082
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 if (DBG) log("nvResetConfig: type " + resetType);
3086 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3087 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3088 return success;
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
Jake Hambye994d462014-02-03 13:10:13 -08003092 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003093
Svet Ganovb320e182015-04-16 12:30:10 -07003094 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003095 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003096 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003097 return new String[0];
3098 }
3099
Malcolm Chenaabec062018-02-28 15:00:40 -08003100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 return mPhone.getPcscfAddress(apnType);
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
Wink Saville36469e72014-06-11 15:17:00 -07003106 }
3107
Brad Ebinger51f743a2017-01-23 13:50:20 -08003108 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003109 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3110 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003111 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003112 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003113 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003114
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 PhoneFactory.getImsResolver().enableIms(slotId);
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003121 }
3122
3123 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003124 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3125 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003126 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003127 public void disableIms(int slotId) {
3128 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003129
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 PhoneFactory.getImsResolver().disableIms(slotId);
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003136 }
3137
3138 /**
3139 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3140 * feature or {@link null} if the service is not available. If the feature is available, the
3141 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3142 */
3143 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003144 IImsServiceFeatureCallback callback) {
3145 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003146
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003153 }
3154
3155 /**
3156 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3157 * feature during emergency calling or {@link null} if the service is not available. If the
3158 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3159 * listener for feature updates.
3160 */
3161 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3162 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003163
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3167 } finally {
3168 Binder.restoreCallingIdentity(identity);
3169 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003170 }
3171
Brad Ebinger5f64b052017-12-14 14:26:15 -08003172 /**
3173 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3174 * specified.
3175 */
3176 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3177 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003178
3179 final long identity = Binder.clearCallingIdentity();
3180 try {
3181 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003185 }
3186
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003187 /**
3188 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3189 * specified.
3190 */
3191 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3192 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003193
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003200 }
3201
Brad Ebinger884c07b2018-02-15 16:17:40 -08003202 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003203 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3204 * available, false if the IMS resolver is idle.
3205 */
3206 public boolean isResolvingImsBinding() {
3207 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003208
3209 final long identity = Binder.clearCallingIdentity();
3210 try {
3211 return PhoneFactory.getImsResolver().isResolvingBinding();
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
Brad Ebinger67801702018-03-02 13:43:36 -08003215 }
3216
Brad Ebingerdac2f002018-04-03 15:17:52 -07003217 /**
3218 * Sets the ImsService Package Name that Telephony will bind to.
3219 *
3220 * @param slotId the slot ID that the ImsService should bind for.
3221 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3222 * ImsService is the device default ImsService.
3223 * @param packageName The package name of the application that contains the ImsService to bind
3224 * to.
3225 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3226 * @hide
3227 */
3228 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003229 int[] subIds = SubscriptionManager.getSubId(slotId);
3230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3231 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3232 "setImsService");
3233
Malcolm Chenaabec062018-02-28 15:00:40 -08003234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3237 isCarrierImsService, packageName);
3238 } finally {
3239 Binder.restoreCallingIdentity(identity);
3240 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003241 }
3242
3243 /**
3244 * Return the ImsService configuration.
3245 *
3246 * @param slotId The slot that the ImsService is associated with.
3247 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3248 * the device default.
3249 * @return the package name of the ImsService configuration.
3250 */
3251 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003252 int[] subIds = SubscriptionManager.getSubId(slotId);
3253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3254 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3255 "getImsService");
3256
Malcolm Chenaabec062018-02-28 15:00:40 -08003257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3260 isCarrierImsService);
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003264 }
3265
Wink Saville36469e72014-06-11 15:17:00 -07003266 public void setImsRegistrationState(boolean registered) {
3267 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003268
3269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 mPhone.setImsRegistrationState(registered);
3272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
Wink Saville36469e72014-06-11 15:17:00 -07003275 }
3276
3277 /**
Stuart Scott54788802015-03-30 13:18:01 -07003278 * Set the network selection mode to automatic.
3279 *
3280 */
3281 @Override
3282 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3284 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003285
3286 final long identity = Binder.clearCallingIdentity();
3287 try {
3288 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3289 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
Stuart Scott54788802015-03-30 13:18:01 -07003293 }
3294
3295 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003296 * Set the network selection mode to manual with the selected carrier.
3297 */
3298 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003299 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003300 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3302 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003303
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003307 /* operatorAlphaLong */ "",
3308 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003309 operatorNumeric);
3310 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3311 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3312 persistSelection);
3313 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003317 }
3318
3319 /**
3320 * Scans for available networks.
3321 */
3322 @Override
3323 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3325 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3330 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3331 CMD_PERFORM_NETWORK_SCAN, null, subId);
3332 return result;
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003336 }
3337
3338 /**
yinxub1bed742017-04-17 11:45:04 -07003339 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003340 *
yinxub1bed742017-04-17 11:45:04 -07003341 * @param subId id of the subscription
3342 * @param request contains the radio access networks with bands/channels to scan
3343 * @param messenger callback messenger for scan results or errors
3344 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003345 * @return the id of the requested scan which can be used to stop the scan.
3346 */
3347 @Override
3348 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3349 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3351 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003352
3353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 return mNetworkScanRequestTracker.startNetworkScan(
3356 request, messenger, binder, getPhone(subId));
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
yinxu504e1392017-04-12 16:03:22 -07003360 }
3361
3362 /**
3363 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003364 *
3365 * @param subId id of the subscription
3366 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003367 */
3368 @Override
3369 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3371 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003372
3373 final long identity = Binder.clearCallingIdentity();
3374 try {
3375 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
yinxu504e1392017-04-12 16:03:22 -07003379 }
3380
3381 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003382 * Get the calculated preferred network type.
3383 * Used for debugging incorrect network type.
3384 *
3385 * @return the preferred network type, defined in RILConstants.java.
3386 */
3387 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003388 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003390 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003391 return RILConstants.PREFERRED_NETWORK_MODE;
3392 }
3393
Malcolm Chenaabec062018-02-28 15:00:40 -08003394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 // FIXME: need to get SubId from somewhere.
3397 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
Junda Liu84d15a22014-07-02 11:21:04 -07003401 }
3402
3403 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003404 * Get the preferred network type.
3405 * Used for device configuration by some CDMA operators.
3406 *
3407 * @return the preferred network type, defined in RILConstants.java.
3408 */
3409 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003410 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3412 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003413
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 if (DBG) log("getPreferredNetworkType");
3417 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3418 int networkType = (result != null ? result[0] : -1);
3419 if (DBG) log("getPreferredNetworkType: " + networkType);
3420 return networkType;
3421 } finally {
3422 Binder.restoreCallingIdentity(identity);
3423 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003424 }
3425
3426 /**
3427 * Set the preferred network type.
3428 * Used for device configuration by some CDMA operators.
3429 *
3430 * @param networkType the preferred network type, defined in RILConstants.java.
3431 * @return true on success; false on any failure.
3432 */
3433 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003434 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3436 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003437
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3441 Boolean success = (Boolean) sendRequest(
3442 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3443 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3444 if (success) {
3445 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3446 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3447 }
3448 return success;
3449 } finally {
3450 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003451 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003452 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003453
3454 /**
Junda Liu475951f2014-11-07 16:45:03 -08003455 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3456 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3457 * tethering.
3458 *
3459 * @return 0: Not required. 1: required. 2: Not set.
3460 * @hide
3461 */
3462 @Override
3463 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003464 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003465
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3469 Settings.Global.TETHER_DUN_REQUIRED, 2);
3470 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3471 // config_tether_apndata.
3472 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3473 dunRequired = 1;
3474 }
3475 return dunRequired;
3476 } finally {
3477 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003478 }
Junda Liu475951f2014-11-07 16:45:03 -08003479 }
3480
3481 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003482 * Set mobile data enabled
3483 * Used by the user through settings etc to turn on/off mobile data
3484 *
3485 * @param enable {@code true} turn turn data on, else {@code false}
3486 */
3487 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003488 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3490 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 int phoneId = mSubscriptionController.getPhoneId(subId);
3495 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3496 Phone phone = PhoneFactory.getPhone(phoneId);
3497 if (phone != null) {
3498 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3499 phone.setUserDataEnabled(enable);
3500 } else {
3501 loge("setUserDataEnabled: no phone for subId=" + subId);
3502 }
3503 } finally {
3504 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003505 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003506 }
3507
3508 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003509 * Get the user enabled state of Mobile Data.
3510 *
3511 * TODO: remove and use isUserDataEnabled.
3512 * This can't be removed now because some vendor codes
3513 * calls through ITelephony directly while they should
3514 * use TelephonyManager.
3515 *
3516 * @return true on enabled
3517 */
3518 @Override
3519 public boolean getDataEnabled(int subId) {
3520 return isUserDataEnabled(subId);
3521 }
3522
3523 /**
3524 * Get whether mobile data is enabled per user setting.
3525 *
3526 * There are other factors deciding whether mobile data is actually enabled, but they are
3527 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003528 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003529 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003530 *
3531 * @return {@code true} if data is enabled else {@code false}
3532 */
3533 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003534 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003535 try {
3536 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3537 null);
3538 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3540 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003541 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003542
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 int phoneId = mSubscriptionController.getPhoneId(subId);
3546 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3547 Phone phone = PhoneFactory.getPhone(phoneId);
3548 if (phone != null) {
3549 boolean retVal = phone.isUserDataEnabled();
3550 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3551 return retVal;
3552 } else {
3553 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3554 return false;
3555 }
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003558 }
3559 }
3560
3561 /**
3562 * Get whether mobile data is enabled.
3563 *
3564 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3565 * whether mobile data is actually enabled.
3566 *
3567 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3568 *
3569 * @return {@code true} if data is enabled else {@code false}
3570 */
3571 @Override
3572 public boolean isDataEnabled(int subId) {
3573 try {
3574 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3575 null);
3576 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3578 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003579 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003580
3581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 int phoneId = mSubscriptionController.getPhoneId(subId);
3584 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3585 Phone phone = PhoneFactory.getPhone(phoneId);
3586 if (phone != null) {
3587 boolean retVal = phone.isDataEnabled();
3588 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3589 return retVal;
3590 } else {
3591 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3592 return false;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003596 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003597 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003598
3599 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003600 public int getCarrierPrivilegeStatus(int subId) {
3601 final Phone phone = getPhone(subId);
3602 if (phone == null) {
3603 loge("getCarrierPrivilegeStatus: Invalid subId");
3604 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3605 }
3606 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003607 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003608 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003609 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3610 }
3611 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003612 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003613 }
Junda Liu29340342014-07-10 15:23:27 -07003614
3615 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003616 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3617 final Phone phone = getPhone(subId);
3618 if (phone == null) {
3619 loge("getCarrierPrivilegeStatus: Invalid subId");
3620 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3621 }
3622 UiccProfile profile =
3623 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3624 if (profile == null) {
3625 loge("getCarrierPrivilegeStatus: No UICC");
3626 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3627 }
3628 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3629 }
3630
3631 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003632 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003633 if (TextUtils.isEmpty(pkgName))
3634 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003635 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003636 if (card == null) {
3637 loge("checkCarrierPrivilegesForPackage: No UICC");
3638 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3639 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003640 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3641 }
3642
3643 @Override
3644 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003645 if (TextUtils.isEmpty(pkgName))
3646 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003647 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3648 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3649 UiccCard card = UiccController.getInstance().getUiccCard(i);
3650 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003651 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003652 continue;
3653 }
3654
3655 result = card.getCarrierPrivilegeStatus(
3656 mPhone.getContext().getPackageManager(), pkgName);
3657 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3658 break;
3659 }
3660 }
3661
3662 return result;
Junda Liu29340342014-07-10 15:23:27 -07003663 }
Derek Tan89e89d42014-07-08 17:00:10 -07003664
3665 @Override
Junda Liue64de782015-04-16 17:19:16 -07003666 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3667 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3668 loge("phoneId " + phoneId + " is not valid.");
3669 return null;
3670 }
3671 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003672 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003673 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003674 return null ;
3675 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003676 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003677 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003678 }
3679
Amith Yamasani6e118872016-02-19 12:53:51 -08003680 @Override
3681 public List<String> getPackagesWithCarrierPrivileges() {
3682 PackageManager pm = mPhone.getContext().getPackageManager();
3683 List<String> privilegedPackages = new ArrayList<>();
3684 List<PackageInfo> packages = null;
3685 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3686 UiccCard card = UiccController.getInstance().getUiccCard(i);
3687 if (card == null) {
3688 // No UICC in that slot.
3689 continue;
3690 }
3691 if (card.hasCarrierPrivilegeRules()) {
3692 if (packages == null) {
3693 // Only check packages in user 0 for now
3694 packages = pm.getInstalledPackagesAsUser(
3695 PackageManager.MATCH_DISABLED_COMPONENTS
3696 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3697 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3698 }
3699 for (int p = packages.size() - 1; p >= 0; p--) {
3700 PackageInfo pkgInfo = packages.get(p);
3701 if (pkgInfo != null && pkgInfo.packageName != null
3702 && card.getCarrierPrivilegeStatus(pkgInfo)
3703 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3704 privilegedPackages.add(pkgInfo.packageName);
3705 }
3706 }
3707 }
3708 }
3709 return privilegedPackages;
3710 }
3711
Wink Savilleb564aae2014-10-23 10:18:09 -07003712 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003713 final Phone phone = getPhone(subId);
3714 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003715 if (card == null) {
3716 loge("getIccId: No UICC");
3717 return null;
3718 }
3719 String iccId = card.getIccId();
3720 if (TextUtils.isEmpty(iccId)) {
3721 loge("getIccId: ICC ID is null or empty.");
3722 return null;
3723 }
3724 return iccId;
3725 }
3726
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003727 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003728 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3729 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003730 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3731 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003732
Malcolm Chenaabec062018-02-28 15:00:40 -08003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 final String iccId = getIccId(subId);
3736 final Phone phone = getPhone(subId);
3737 if (phone == null) {
3738 return false;
3739 }
3740 final String subscriberId = phone.getSubscriberId();
3741
3742 if (DBG_MERGE) {
3743 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3744 + subscriberId + " to " + number);
3745 }
3746
3747 if (TextUtils.isEmpty(iccId)) {
3748 return false;
3749 }
3750
3751 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3752
3753 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3754 if (alphaTag == null) {
3755 editor.remove(alphaTagPrefKey);
3756 } else {
3757 editor.putString(alphaTagPrefKey, alphaTag);
3758 }
3759
3760 // Record both the line number and IMSI for this ICCID, since we need to
3761 // track all merged IMSIs based on line number
3762 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3763 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3764 if (number == null) {
3765 editor.remove(numberPrefKey);
3766 editor.remove(subscriberPrefKey);
3767 } else {
3768 editor.putString(numberPrefKey, number);
3769 editor.putString(subscriberPrefKey, subscriberId);
3770 }
3771
3772 editor.commit();
3773 return true;
3774 } finally {
3775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003776 }
Derek Tan7226c842014-07-02 17:42:23 -07003777 }
3778
3779 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003780 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003781 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003783 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003784 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003785 return null;
3786 }
Derek Tan97ebb422014-09-05 16:55:38 -07003787
Malcolm Chenaabec062018-02-28 15:00:40 -08003788 final long identity = Binder.clearCallingIdentity();
3789 try {
3790 String iccId = getIccId(subId);
3791 if (iccId != null) {
3792 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3793 if (DBG_MERGE) {
3794 log("getLine1NumberForDisplay returning "
3795 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3796 }
3797 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003798 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003799 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3800 return null;
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003803 }
Derek Tan7226c842014-07-02 17:42:23 -07003804 }
3805
3806 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003807 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003809 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003810 return null;
3811 }
Derek Tan97ebb422014-09-05 16:55:38 -07003812
Malcolm Chenaabec062018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 String iccId = getIccId(subId);
3816 if (iccId != null) {
3817 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3818 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3819 }
3820 return null;
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003823 }
Derek Tan7226c842014-07-02 17:42:23 -07003824 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003825
3826 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003827 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003828 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3829 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003831 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3832 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003833 return null;
3834 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003835
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003836 final long identity = Binder.clearCallingIdentity();
3837 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003838 final Context context = mPhone.getContext();
3839 final TelephonyManager tele = TelephonyManager.from(context);
3840 final SubscriptionManager sub = SubscriptionManager.from(context);
3841
3842 // Figure out what subscribers are currently active
3843 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3844 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3845 // the process, where TelephonyManager was instantiated.
3846 // Otherwise AppOps check will fail.
3847
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003848 final int[] subIds = sub.getActiveSubscriptionIdList();
3849 for (int subId : subIds) {
3850 activeSubscriberIds.add(tele.getSubscriberId(subId));
3851 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003852
3853 // First pass, find a number override for an active subscriber
3854 String mergeNumber = null;
3855 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3856 for (String key : prefs.keySet()) {
3857 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3858 final String subscriberId = (String) prefs.get(key);
3859 if (activeSubscriberIds.contains(subscriberId)) {
3860 final String iccId = key.substring(
3861 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3862 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3863 mergeNumber = (String) prefs.get(numberKey);
3864 if (DBG_MERGE) {
3865 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3866 + " for active subscriber " + subscriberId);
3867 }
3868 if (!TextUtils.isEmpty(mergeNumber)) {
3869 break;
3870 }
3871 }
3872 }
3873 }
3874
3875 // Shortcut when no active merged subscribers
3876 if (TextUtils.isEmpty(mergeNumber)) {
3877 return null;
3878 }
3879
3880 // Second pass, find all subscribers under that line override
3881 final ArraySet<String> result = new ArraySet<>();
3882 for (String key : prefs.keySet()) {
3883 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3884 final String number = (String) prefs.get(key);
3885 if (mergeNumber.equals(number)) {
3886 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3887 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3888 final String subscriberId = (String) prefs.get(subscriberKey);
3889 if (!TextUtils.isEmpty(subscriberId)) {
3890 result.add(subscriberId);
3891 }
3892 }
3893 }
3894 }
3895
3896 final String[] resultArray = result.toArray(new String[result.size()]);
3897 Arrays.sort(resultArray);
3898 if (DBG_MERGE) {
3899 Slog.d(LOG_TAG,
3900 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3901 }
3902 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003903 } finally {
3904 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003905 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003906 }
3907
3908 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003909 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3911 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003912
3913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 final Phone phone = getPhone(subId);
3916 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003920 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003921
3922 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003923 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003924 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3925 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003926 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 final Phone phone = getPhone(subId);
3931 if (phone == null) {
3932 return false;
3933 }
3934 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3935 cdmaNonRoamingList);
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003938 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003939 }
3940
3941 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003942 @Deprecated
3943 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3944 enforceModifyPermission();
3945
3946 int returnValue = 0;
3947 try {
3948 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3949 if(result.exception == null) {
3950 if (result.result != null) {
3951 byte[] responseData = (byte[])(result.result);
3952 if(responseData.length > oemResp.length) {
3953 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3954 responseData.length + "bytes. Buffer Size is " +
3955 oemResp.length + "bytes.");
3956 }
3957 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3958 returnValue = responseData.length;
3959 }
3960 } else {
3961 CommandException ex = (CommandException) result.exception;
3962 returnValue = ex.getCommandError().ordinal();
3963 if(returnValue > 0) returnValue *= -1;
3964 }
3965 } catch (RuntimeException e) {
3966 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3967 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3968 if(returnValue > 0) returnValue *= -1;
3969 }
3970
3971 return returnValue;
3972 }
3973
3974 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003975 public void setRadioCapability(RadioAccessFamily[] rafs) {
3976 try {
3977 ProxyController.getInstance().setRadioCapability(rafs);
3978 } catch (RuntimeException e) {
3979 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3980 }
3981 }
3982
3983 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003984 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003985 Phone phone = PhoneFactory.getPhone(phoneId);
3986 if (phone == null) {
3987 return RadioAccessFamily.RAF_UNKNOWN;
3988 }
3989 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003991 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003992 return RadioAccessFamily.RAF_UNKNOWN;
3993 }
3994
Malcolm Chenaabec062018-02-28 15:00:40 -08003995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3998 } finally {
3999 Binder.restoreCallingIdentity(identity);
4000 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004001 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004002
4003 @Override
4004 public void enableVideoCalling(boolean enable) {
4005 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004006
4007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004013 }
4014
4015 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004016 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4018 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4019 return false;
4020 }
Svet Ganovb320e182015-04-16 12:30:10 -07004021
Malcolm Chenaabec062018-02-28 15:00:40 -08004022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 // Check the user preference and the system-level IMS setting. Even if the user has
4025 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4026 // In the long run, we may instead need to check if there exists a connection service
4027 // which can support video calling.
4028 ImsManager imsManager =
4029 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4030 return imsManager.isVtEnabledByPlatform()
4031 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4032 && imsManager.isVtEnabledByUser();
4033 } finally {
4034 Binder.restoreCallingIdentity(identity);
4035 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004036 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004037
Andrew Leea1239f22015-03-02 17:44:07 -08004038 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004039 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4041 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4042 return false;
4043 }
4044
4045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 CarrierConfigManager configManager =
4048 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4049 return configManager.getConfigForSubId(mPhone.getSubId())
4050 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
Andrew Leea1239f22015-03-02 17:44:07 -08004054 }
4055
4056 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004057 public boolean isWorldPhone(int subId, String callingPackage) {
4058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4059 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4060 return false;
4061 }
4062
4063 final long identity = Binder.clearCallingIdentity();
4064 try {
4065 CarrierConfigManager configManager =
4066 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4067 return configManager.getConfigForSubId(mPhone.getSubId())
4068 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4069 } finally {
4070 Binder.restoreCallingIdentity(identity);
4071 }
Andrew Leea1239f22015-03-02 17:44:07 -08004072 }
4073
Andrew Lee9431b832015-03-09 18:46:45 -07004074 @Override
4075 public boolean isTtyModeSupported() {
4076 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004077 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004078 }
4079
4080 @Override
4081 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
Andrew Lee9431b832015-03-09 18:46:45 -07004088 }
4089
Hall Liu98187582018-01-22 19:15:32 -08004090 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4094 mPhone.getSubId()).getBoolean(
4095 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4096 boolean isDeviceSupported =
4097 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4098 return isCarrierSupported && isDeviceSupported;
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
Hall Liu98187582018-01-22 19:15:32 -08004102 }
4103
Hall Liu3ad5f012018-04-06 16:23:39 -07004104 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 return isRttSupported() && Settings.Secure.getInt(
4108 mPhone.getContext().getContentResolver(),
4109 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004113 }
4114
Sanket Padawe7310cc72015-01-14 09:53:20 -08004115 /**
4116 * Returns the unique device ID of phone, for example, the IMEI for
4117 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4118 *
4119 * <p>Requires Permission:
4120 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4121 */
4122 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004123 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004124 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004125 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004126 return null;
4127 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004128 int subId = phone.getSubId();
4129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4130 mApp, subId, callingPackage, "getDeviceId")) {
4131 return null;
4132 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004133
4134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 return phone.getDeviceId();
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004140 }
4141
Ping Sunc67b7c22016-03-02 19:16:45 +08004142 /**
4143 * {@hide}
4144 * Returns the IMS Registration Status on a particular subid
4145 *
4146 * @param subId
4147 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004148 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004149 Phone phone = getPhone(subId);
4150 if (phone != null) {
4151 return phone.isImsRegistered();
4152 } else {
4153 return false;
4154 }
4155 }
4156
Santos Cordon7a1885b2015-02-03 11:15:19 -08004157 @Override
4158 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004165 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004166
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004167 /**
4168 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004169 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004170 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004171 final long identity = Binder.clearCallingIdentity();
4172 try {
4173 Phone phone = getPhone(subId);
4174 if (phone != null) {
4175 return phone.isWifiCallingEnabled();
4176 } else {
4177 return false;
4178 }
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004181 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004182 }
4183
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004184 /**
4185 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004186 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004187 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 Phone phone = getPhone(subId);
4191 if (phone != null) {
4192 return phone.isVolteEnabled();
4193 } else {
4194 return false;
4195 }
4196 } finally {
4197 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004198 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004199 }
Svet Ganovb320e182015-04-16 12:30:10 -07004200
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004201 /**
4202 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004203 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004204 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004205 final long identity = Binder.clearCallingIdentity();
4206 try {
4207 Phone phone = getPhone(subId);
4208 if (phone != null) {
4209 return phone.isVideoEnabled();
4210 } else {
4211 return false;
4212 }
4213 } finally {
4214 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004215 }
4216 }
4217
4218 /**
4219 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4220 * defined in {@link ImsRegistrationImplBase}.
4221 */
4222 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004223 final long identity = Binder.clearCallingIdentity();
4224 try {
4225 Phone phone = getPhone(subId);
4226 if (phone != null) {
4227 return phone.getImsRegistrationTech();
4228 } else {
4229 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4230 }
4231 } finally {
4232 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004233 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004234 }
4235
Stuart Scott8eef64f2015-04-08 15:13:54 -07004236 @Override
4237 public void factoryReset(int subId) {
4238 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004239 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4240 return;
4241 }
4242
Svet Ganovcc087f82015-05-12 20:35:54 -07004243 final long identity = Binder.clearCallingIdentity();
4244 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004245 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4246 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004247 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004248 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004249 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4250 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004251 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004252 }
4253 } finally {
4254 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004255 }
4256 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004257
4258 @Override
4259 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 // We query all subscriptions instead of just the active ones, because
4263 // this might be called early on in the provisioning flow when the
4264 // subscriptions potentially aren't active yet.
4265 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4266 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004267 return null;
4268 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004269
Malcolm Chenaabec062018-02-28 15:00:40 -08004270 // This function may be called very early, say, from the setup wizard, at
4271 // which point we won't have a default subscription set. If that's the case
4272 // we just choose the first, which will be valid in "most cases".
4273 final int defaultSubId = getDefaultSubscription();
4274 SubscriptionInfo info = null;
4275 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4276 info = slist.get(0);
4277 } else {
4278 for (SubscriptionInfo item : slist) {
4279 if (item.getSubscriptionId() == defaultSubId) {
4280 info = item;
4281 break;
4282 }
4283 }
4284
4285 if (info == null) {
4286 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004287 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004288 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004289
Malcolm Chenaabec062018-02-28 15:00:40 -08004290 // Try and fetch the locale from the carrier properties or from the SIM language
4291 // preferences (EF-PL and EF-LI)...
4292 final int mcc = info.getMcc();
4293 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4294 String simLanguage = null;
4295 if (defaultPhone != null) {
4296 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4297 if (localeFromDefaultSim != null) {
4298 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4299 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4300 return localeFromDefaultSim.toLanguageTag();
4301 } else {
4302 simLanguage = localeFromDefaultSim.getLanguage();
4303 }
4304 }
4305 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004306
Malcolm Chenaabec062018-02-28 15:00:40 -08004307 // The SIM language preferences only store a language (e.g. fr = French), not an
4308 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4309 // the SIM and carrier preferences does not include a country we add the country
4310 // determined from the SIM MCC to provide an exact locale.
4311 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4312 simLanguage);
4313 if (mccLocale != null) {
4314 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4315 return mccLocale.toLanguageTag();
4316 }
4317
4318 if (DBG) log("No locale found - returning null");
4319 return null;
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004323 }
4324
4325 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004326 return mSubscriptionController.getAllSubInfoList(
4327 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004328 }
4329
Malcolm Chenaabec062018-02-28 15:00:40 -08004330 /**
4331 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4332 */
4333 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4334 return mSubscriptionController.getActiveSubscriptionInfoList(
4335 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004336 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004337
Chenjie Yu1ba97252018-01-11 18:16:20 -08004338 private final ModemActivityInfo mLastModemActivityInfo =
4339 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4340
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004341 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004342 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4343 * representing the state of the modem.
4344 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004345 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4346 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004347 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004348 */
4349 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004350 public void requestModemActivityInfo(ResultReceiver result) {
4351 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004352 ModemActivityInfo ret = null;
Adam Lesinski903a54c2016-04-11 14:49:52 -07004353
Malcolm Chenaabec062018-02-28 15:00:40 -08004354 final long identity = Binder.clearCallingIdentity();
4355 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004356 synchronized (mLastModemActivityInfo) {
4357 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
4358 null);
4359 if (info != null) {
4360 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4361 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4362 mergedTxTimeMs[i] =
4363 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4364 }
4365 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4366 mLastModemActivityInfo.setSleepTimeMillis(
4367 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4368 mLastModemActivityInfo.setIdleTimeMillis(
4369 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4370 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4371 mLastModemActivityInfo.setRxTimeMillis(
4372 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4373 mLastModemActivityInfo.setEnergyUsed(
4374 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004375 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004376 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4377 mLastModemActivityInfo.getSleepTimeMillis(),
4378 mLastModemActivityInfo.getIdleTimeMillis(),
4379 mLastModemActivityInfo.getTxTimeMillis(),
4380 mLastModemActivityInfo.getRxTimeMillis(),
4381 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004382 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004383 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004384 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004385 result.send(0, bundle);
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004388 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004389 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004390
4391 /**
4392 * {@hide}
4393 * Returns the service state information on specified subscription.
4394 */
4395 @Override
4396 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004398 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004399 return null;
4400 }
4401
Malcolm Chenaabec062018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
4404 final Phone phone = getPhone(subId);
4405 if (phone == null) {
4406 return null;
4407 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004408
Malcolm Chenaabec062018-02-28 15:00:40 -08004409 return phone.getServiceState();
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004413 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004414
4415 /**
4416 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4417 *
4418 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4419 * voicemail ringtone.
4420 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4421 * PhoneAccount.
4422 */
4423 @Override
4424 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004425 final long identity = Binder.clearCallingIdentity();
4426 try {
4427 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4428 if (phone == null) {
4429 phone = mPhone;
4430 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004431
Malcolm Chenaabec062018-02-28 15:00:40 -08004432 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004436 }
4437
4438 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004439 * Sets the per-account voicemail ringtone.
4440 *
4441 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4442 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4443 *
4444 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4445 * voicemail ringtone.
4446 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4447 * PhoneAccount.
4448 */
4449 @Override
4450 public void setVoicemailRingtoneUri(String callingPackage,
4451 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4453 if (!TextUtils.equals(callingPackage,
4454 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4456 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4457 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004458 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004459
4460 final long identity = Binder.clearCallingIdentity();
4461 try {
4462 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4463 if (phone == null) {
4464 phone = mPhone;
4465 }
4466 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4467 } finally {
4468 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004469 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004470 }
4471
4472 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004473 * Returns whether vibration is set for voicemail notification in Phone settings.
4474 *
4475 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4476 * voicemail vibration setting.
4477 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4478 */
4479 @Override
4480 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4484 if (phone == null) {
4485 phone = mPhone;
4486 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004487
Malcolm Chenaabec062018-02-28 15:00:40 -08004488 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004492 }
4493
Youhan Wange64578a2016-05-02 15:32:42 -07004494 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004495 * Sets the per-account voicemail vibration.
4496 *
4497 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4498 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4499 *
4500 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4501 * voicemail vibration setting.
4502 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4503 * specific PhoneAccount.
4504 */
4505 @Override
4506 public void setVoicemailVibrationEnabled(String callingPackage,
4507 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4509 if (!TextUtils.equals(callingPackage,
4510 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4513 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004514 }
4515
Malcolm Chenaabec062018-02-28 15:00:40 -08004516 final long identity = Binder.clearCallingIdentity();
4517 try {
4518 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4519 if (phone == null) {
4520 phone = mPhone;
4521 }
4522 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4523 } finally {
4524 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004525 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004526 }
4527
4528 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004529 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4530 *
4531 * @throws SecurityException if the caller does not have the required permission
4532 */
4533 private void enforceReadPrivilegedPermission() {
4534 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4535 null);
4536 }
4537
4538 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004539 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4540 * permission.
4541 *
4542 * @throws SecurityException if the caller does not have the required permission
4543 */
4544 private void enforceSendSmsPermission() {
4545 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4546 }
4547
4548 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004549 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004550 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004551 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004552 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004553 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 ComponentName componentName =
4557 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4558 if (componentName == null) {
4559 throw new SecurityException(
4560 "Caller not current active visual voicemail package[null]");
4561 }
4562 String vvmPackage = componentName.getPackageName();
4563 if (!callingPackage.equals(vvmPackage)) {
4564 throw new SecurityException("Caller not current active visual voicemail package["
4565 + vvmPackage + "]");
4566 }
4567 } finally {
4568 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004569 }
4570 }
4571
4572 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004573 * Return the application ID for the app type.
4574 *
4575 * @param subId the subscription ID that this request applies to.
4576 * @param appType the uicc app type.
4577 * @return Application ID for specificied app type, or null if no uicc.
4578 */
4579 @Override
4580 public String getAidForAppType(int subId, int appType) {
4581 enforceReadPrivilegedPermission();
4582 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004583
4584 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004585 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004586 if (phone == null) {
4587 return null;
4588 }
4589 String aid = null;
4590 try {
4591 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4592 .getApplicationByType(appType).getAid();
4593 } catch (Exception e) {
4594 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4595 }
4596 return aid;
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004599 }
Youhan Wange64578a2016-05-02 15:32:42 -07004600 }
4601
Youhan Wang4001d252016-05-11 10:29:41 -07004602 /**
4603 * Return the Electronic Serial Number.
4604 *
4605 * @param subId the subscription ID that this request applies to.
4606 * @return ESN or null if error.
4607 */
4608 @Override
4609 public String getEsn(int subId) {
4610 enforceReadPrivilegedPermission();
4611 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004612
4613 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004614 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004615 if (phone == null) {
4616 return null;
4617 }
4618 String esn = null;
4619 try {
4620 esn = phone.getEsn();
4621 } catch (Exception e) {
4622 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4623 }
4624 return esn;
4625 } finally {
4626 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004627 }
Youhan Wang4001d252016-05-11 10:29:41 -07004628 }
4629
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004630 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004631 * Return the Preferred Roaming List Version.
4632 *
4633 * @param subId the subscription ID that this request applies to.
4634 * @return PRLVersion or null if error.
4635 */
4636 @Override
4637 public String getCdmaPrlVersion(int subId) {
4638 enforceReadPrivilegedPermission();
4639 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004640
4641 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004642 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004643 if (phone == null) {
4644 return null;
4645 }
4646 String cdmaPrlVersion = null;
4647 try {
4648 cdmaPrlVersion = phone.getCdmaPrlVersion();
4649 } catch (Exception e) {
4650 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4651 }
4652 return cdmaPrlVersion;
4653 } finally {
4654 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004655 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004656 }
4657
4658 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004659 * Get snapshot of Telephony histograms
4660 * @return List of Telephony histograms
4661 * @hide
4662 */
4663 @Override
4664 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4666 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004667
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
4670 return RIL.getTelephonyRILTimingHistograms();
4671 } finally {
4672 Binder.restoreCallingIdentity(identity);
4673 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004674 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004675
4676 /**
4677 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004678 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004679 * Require system privileges. In the future we may add this to carrier APIs.
4680 *
4681 * @return The number of carriers set successfully, should match length of carriers
4682 */
4683 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004684 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004685 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004686
Meng Wang9b7c4e92017-02-17 11:41:27 -08004687 if (carriers == null) {
4688 throw new NullPointerException("carriers cannot be null");
4689 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004690
Malcolm Chenaabec062018-02-28 15:00:40 -08004691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4694 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4695 return retVal[0];
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004699 }
4700
4701 /**
4702 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004703 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004704 * Require system privileges. In the future we may add this to carrier APIs.
4705 *
4706 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4707 * means all carriers are allowed.
4708 */
4709 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004710 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004711 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004712
4713 final long identity = Binder.clearCallingIdentity();
4714 try {
4715 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4716 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004720 }
4721
fionaxu59545b42016-05-25 15:53:37 -07004722 /**
4723 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4724 * @param subId the subscription ID that this action applies to.
4725 * @param enabled control enable or disable metered apns.
4726 * {@hide}
4727 */
4728 @Override
4729 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4730 enforceModifyPermission();
4731 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004732
4733 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004734 if (phone == null) {
4735 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4736 return;
4737 }
4738 try {
4739 phone.carrierActionSetMeteredApnsEnabled(enabled);
4740 } catch (Exception e) {
4741 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004742 } finally {
4743 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004744 }
4745 }
4746
4747 /**
4748 * Action set from carrier signalling broadcast receivers to enable/disable radio
4749 * @param subId the subscription ID that this action applies to.
4750 * @param enabled control enable or disable radio.
4751 * {@hide}
4752 */
4753 @Override
4754 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4755 enforceModifyPermission();
4756 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004757
4758 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004759 if (phone == null) {
4760 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4761 return;
4762 }
4763 try {
4764 phone.carrierActionSetRadioEnabled(enabled);
4765 } catch (Exception e) {
4766 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004767 } finally {
4768 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004769 }
4770 }
4771
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004772 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004773 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4774 * network status based on which carrier apps could apply actions accordingly,
4775 * enable/disable default url handler for example.
4776 *
4777 * @param subId the subscription ID that this action applies to.
4778 * @param report control start/stop reporting the default network status.
4779 * {@hide}
4780 */
4781 @Override
4782 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4783 enforceModifyPermission();
4784 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004785
4786 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004787 if (phone == null) {
4788 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4789 return;
4790 }
4791 try {
4792 phone.carrierActionReportDefaultNetworkStatus(report);
4793 } catch (Exception e) {
4794 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004795 } finally {
4796 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004797 }
4798 }
4799
4800 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004801 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4802 * bug report is being generated.
4803 */
4804 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004805 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004806 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4807 != PackageManager.PERMISSION_GRANTED) {
4808 writer.println("Permission Denial: can't dump Phone from pid="
4809 + Binder.getCallingPid()
4810 + ", uid=" + Binder.getCallingUid()
4811 + "without permission "
4812 + android.Manifest.permission.DUMP);
4813 return;
4814 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004815 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004816 }
Jack Yueb89b242016-06-22 13:27:47 -07004817
Brad Ebingerdac2f002018-04-03 15:17:52 -07004818 @Override
4819 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4820 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4821 throws RemoteException {
4822 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4823 }
4824
Jack Yueb89b242016-06-22 13:27:47 -07004825 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004826 * Get aggregated video call data usage since boot.
4827 *
4828 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4829 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004830 * {@hide}
4831 */
4832 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004833 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004834 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4835 null);
4836
Malcolm Chenaabec062018-02-28 15:00:40 -08004837 final long identity = Binder.clearCallingIdentity();
4838 try {
4839 // NetworkStatsService keeps tracking the active network interface and identity. It
4840 // records the delta with the corresponding network identity.
4841 // We just return the total video call data usage snapshot since boot.
4842 Phone phone = getPhone(subId);
4843 if (phone != null) {
4844 return phone.getVtDataUsage(perUidStats);
4845 }
4846 return null;
4847 } finally {
4848 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004849 }
Jack Yueb89b242016-06-22 13:27:47 -07004850 }
Jack Yu75ab2952016-07-08 14:29:33 -07004851
4852 /**
4853 * Policy control of data connection. Usually used when data limit is passed.
4854 * @param enabled True if enabling the data, otherwise disabling.
4855 * @param subId Subscription index
4856 * {@hide}
4857 */
4858 @Override
4859 public void setPolicyDataEnabled(boolean enabled, int subId) {
4860 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004861
4862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 Phone phone = getPhone(subId);
4865 if (phone != null) {
4866 phone.setPolicyDataEnabled(enabled);
4867 }
4868 } finally {
4869 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004870 }
4871 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004872
4873 /**
4874 * Get Client request stats
4875 * @return List of Client Request Stats
4876 * @hide
4877 */
4878 @Override
4879 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004880 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004881 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004882 return null;
4883 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004884 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004885
Malcolm Chenaabec062018-02-28 15:00:40 -08004886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 if (phone != null) {
4889 return phone.getClientRequestStats();
4890 }
4891
4892 return null;
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004896 }
4897
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004898 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004899 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004900 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004901 }
Jack Yueb4124c2017-02-16 15:32:43 -08004902
4903 /**
Grace Chen70990072017-03-24 17:21:30 -07004904 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004905 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004906 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004907 * @param state State of SIM (power down, power up, pass through)
4908 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4909 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4910 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004911 *
4912 **/
4913 @Override
Grace Chen70990072017-03-24 17:21:30 -07004914 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004915 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004916 Phone phone = PhoneFactory.getPhone(slotIndex);
4917
Malcolm Chenaabec062018-02-28 15:00:40 -08004918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 if (phone != null) {
4921 phone.setSimPowerState(state);
4922 }
4923 } finally {
4924 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004925 }
4926 }
Shuo Qiandd210312017-04-12 22:11:33 +00004927
Tyler Gunn65d45c22017-06-05 11:22:26 -07004928 private boolean isUssdApiAllowed(int subId) {
4929 CarrierConfigManager configManager =
4930 (CarrierConfigManager) mPhone.getContext().getSystemService(
4931 Context.CARRIER_CONFIG_SERVICE);
4932 if (configManager == null) {
4933 return false;
4934 }
4935 PersistableBundle pb = configManager.getConfigForSubId(subId);
4936 if (pb == null) {
4937 return false;
4938 }
4939 return pb.getBoolean(
4940 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4941 }
4942
Shuo Qiandd210312017-04-12 22:11:33 +00004943 /**
4944 * Check if phone is in emergency callback mode
4945 * @return true if phone is in emergency callback mode
4946 * @param subId sub id
4947 */
goneil9c5f4872017-12-05 14:07:56 -08004948 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004949 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004950 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004951 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004952
4953 final long identity = Binder.clearCallingIdentity();
4954 try {
4955 if (phone != null) {
4956 return phone.isInEcm();
4957 } else {
4958 return false;
4959 }
4960 } finally {
4961 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004962 }
4963 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004964
4965 /**
4966 * Get the current signal strength information for the given subscription.
4967 * Because this information is not updated when the device is in a low power state
4968 * it should not be relied-upon to be current.
4969 * @param subId Subscription index
4970 * @return the most recent cached signal strength info from the modem
4971 */
4972 @Override
4973 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 Phone p = getPhone(subId);
4977 if (p == null) {
4978 return null;
4979 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004980
Malcolm Chenaabec062018-02-28 15:00:40 -08004981 return p.getSignalStrength();
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
4984 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004985 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004986
4987 @Override
4988 public UiccSlotInfo[] getUiccSlotsInfo() {
4989 enforceReadPrivilegedPermission();
4990
Malcolm Chenaabec062018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004994 if (slots == null) {
4995 Rlog.i(LOG_TAG, "slots is null.");
4996 return null;
4997 }
4998
Malcolm Chenaabec062018-02-28 15:00:40 -08004999 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5000 for (int i = 0; i < slots.length; i++) {
5001 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005002 if (slot == null) {
5003 continue;
5004 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005005
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005006 String cardId;
5007 UiccCard card = slot.getUiccCard();
5008 if (card != null) {
5009 cardId = card.getCardId();
5010 } else {
5011 cardId = slot.getIccId();
5012 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005013
Malcolm Chenaabec062018-02-28 15:00:40 -08005014 int cardState = 0;
5015 switch (slot.getCardState()) {
5016 case CARDSTATE_ABSENT:
5017 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5018 break;
5019 case CARDSTATE_PRESENT:
5020 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5021 break;
5022 case CARDSTATE_ERROR:
5023 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5024 break;
5025 case CARDSTATE_RESTRICTED:
5026 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5027 break;
5028 default:
5029 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005030
Malcolm Chenaabec062018-02-28 15:00:40 -08005031 }
5032
5033 infos[i] = new UiccSlotInfo(
5034 slot.isActive(),
5035 slot.isEuicc(),
5036 cardId,
5037 cardState,
5038 slot.getPhoneId(),
5039 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005040 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005041 return infos;
5042 } finally {
5043 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005044 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005045 }
5046
5047 @Override
5048 public boolean switchSlots(int[] physicalSlots) {
5049 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005050
5051 final long identity = Binder.clearCallingIdentity();
5052 try {
5053 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005057 }
Jack Yu4c988042018-02-27 15:30:01 -08005058
5059 @Override
5060 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5061 enforceModifyPermission();
5062 final Phone phone = getPhone(subId);
5063 if (phone == null) {
5064 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5065 return;
5066 }
5067
Malcolm Chenaabec062018-02-28 15:00:40 -08005068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 phone.setRadioIndicationUpdateMode(filters, mode);
5071 } finally {
5072 Binder.restoreCallingIdentity(identity);
5073 }
Jack Yu4c988042018-02-27 15:30:01 -08005074 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005075
5076 /**
goneil47ffb6e2018-04-06 15:40:58 -07005077 * A test API to reload the UICC profile.
5078 *
5079 * <p>Requires that the calling app has permission
5080 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5081 * @hide
5082 */
5083 @Override
5084 public void refreshUiccProfile(int subId) {
5085 enforceModifyPermission();
5086
5087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 Phone phone = getPhone(subId);
5090 if (phone == null) {
5091 return;
5092 }
5093 UiccCard uiccCard = phone.getUiccCard();
5094 if (uiccCard == null) {
5095 return;
5096 }
5097 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5098 if (uiccProfile == null) {
5099 return;
5100 }
5101 uiccProfile.refresh();
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
5105 }
5106
5107 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005108 * Returns false if the mobile data is disabled by default, otherwise return true.
5109 */
5110 private boolean getDefaultDataEnabled() {
5111 return "true".equalsIgnoreCase(
5112 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5113 }
5114
5115 /**
5116 * Returns true if the data roaming is enabled by default, i.e the system property
5117 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5118 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5119 */
5120 private boolean getDefaultDataRoamingEnabled(int subId) {
5121 final CarrierConfigManager configMgr = (CarrierConfigManager)
5122 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5123 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5124 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5125 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5126 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5127 return isDataRoamingEnabled;
5128 }
5129
5130 /**
5131 * Returns the default network type for the given {@code subId}, if the default network type is
5132 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5133 */
5134 private int getDefaultNetworkType(int subId) {
5135 return Integer.parseInt(
5136 TelephonyManager.getTelephonyProperty(
5137 mSubscriptionController.getPhoneId(subId),
5138 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5139 String.valueOf(Phone.PREFERRED_NT_MODE)));
5140 }
fionaxua13278b2018-03-21 00:08:13 -07005141
5142 @Override
5143 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5144 gid1, String gid2, String plmn, String spn) {
5145 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005146
5147 final long identity = Binder.clearCallingIdentity();
5148 try {
5149 final Phone phone = getPhone(subId);
5150 if (phone == null) {
5151 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5152 return;
5153 }
5154 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005157 }
fionaxua13278b2018-03-21 00:08:13 -07005158 }
5159
5160 @Override
5161 public int getCarrierIdListVersion(int subId) {
5162 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005163
5164 final long identity = Binder.clearCallingIdentity();
5165 try {
5166 final Phone phone = getPhone(subId);
5167 if (phone == null) {
5168 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5169 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5170 }
5171 return phone.getCarrierIdListVersion();
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005174 }
fionaxua13278b2018-03-21 00:08:13 -07005175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005176}