blob: e824fee0ac58344de5ede24e036a80c3b8825dd2 [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;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
sqianc5eccab2018-10-19 18:46:41 -070057import android.telephony.emergency.EmergencyNumber;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070060import android.telephony.CellInfoGsm;
61import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070062import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070063import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070064import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080065import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070066import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080067import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070068import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070069import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080072import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070073import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080074import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070076import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000078import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070081import android.telephony.cdma.CdmaCellLocation;
82import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070083import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080084import android.telephony.ims.aidl.IImsConfig;
85import android.telephony.ims.aidl.IImsMmTelFeature;
86import android.telephony.ims.aidl.IImsRcsFeature;
87import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070088import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080089import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080095
Brad Ebinger35c841c2018-10-01 10:40:55 -070096import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070097import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080098import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070099import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700100import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700101import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800102import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700103import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700104import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800107import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700108import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100109import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700110import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700111import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700113import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800114import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700115import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700116import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700117import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700119import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700120import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700121import com.android.internal.telephony.SmsApplication;
122import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800123import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800124import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700125import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700126import com.android.internal.telephony.uicc.IccIoResult;
127import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800128import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700129import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800130import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800132import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000133import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700134import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800135import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700136import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800137import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700138import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700139import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800140
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700141import java.io.FileDescriptor;
142import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800145import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700146import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800147import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100148import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800149import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150
151/**
152 * Implementation of the ITelephony interface.
153 */
Santos Cordon117fee72014-05-16 17:56:12 -0700154public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155 private static final String LOG_TAG = "PhoneInterfaceManager";
156 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
157 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159
160 // Message codes used with mMainThreadHandler
161 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700162 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
163 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164 private static final int CMD_OPEN_CHANNEL = 9;
165 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
166 private static final int CMD_CLOSE_CHANNEL = 11;
167 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800168 private static final int CMD_NV_READ_ITEM = 13;
169 private static final int EVENT_NV_READ_ITEM_DONE = 14;
170 private static final int CMD_NV_WRITE_ITEM = 15;
171 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
172 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
173 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700174 private static final int CMD_RESET_MODEM_CONFIG = 19;
175 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800176 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
177 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
178 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
179 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800180 private static final int CMD_SEND_ENVELOPE = 25;
181 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000182 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
183 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700184 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
185 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
186 private static final int CMD_EXCHANGE_SIM_IO = 31;
187 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800188 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
189 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700190 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
191 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700192 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
193 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700194 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
195 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
196 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
197 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700198 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
199 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
200 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
201 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700202 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800203 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
204 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205 private static final int CMD_SWITCH_SLOTS = 50;
206 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700207 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
208 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
209 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
210 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
211 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
212 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
213 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
214 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700215 private static final int CMD_GET_ALL_CELL_INFO = 60;
216 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
217 private static final int CMD_GET_CELL_LOCATION = 62;
218 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700219 private static final int CMD_MODEM_REBOOT = 64;
220 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800222 // Parameters of select command.
223 private static final int SELECT_COMMAND = 0xA4;
224 private static final int SELECT_P1 = 0x04;
225 private static final int SELECT_P2 = 0;
226 private static final int SELECT_P3 = 0x10;
227
Pengquan Meng85728fb2018-03-12 16:31:21 -0700228 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
229 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
230 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
231
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232 /** The singleton instance. */
233 private static PhoneInterfaceManager sInstance;
234
Wink Saville3ab207e2014-11-20 13:07:20 -0800235 private PhoneGlobals mApp;
236 private Phone mPhone;
237 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700238 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800239 private AppOpsManager mAppOps;
240 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800241 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800242 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700243 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
Derek Tan97ebb422014-09-05 16:55:38 -0700245 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
246 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800247 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700248
Derek Tan740e1672017-06-27 14:56:27 -0700249 // The AID of ISD-R.
250 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
251
yinxub1bed742017-04-17 11:45:04 -0700252 private NetworkScanRequestTracker mNetworkScanRequestTracker;
253
David Kelly5e06a7f2018-03-12 14:10:59 +0000254 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
255 private static final int MANUFACTURER_CODE_LENGTH = 8;
256
Derek Tan89e89d42014-07-08 17:00:10 -0700257 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700258 * A request object to use for transmitting data to an ICC.
259 */
260 private static final class IccAPDUArgument {
261 public int channel, cla, command, p1, p2, p3;
262 public String data;
263
264 public IccAPDUArgument(int channel, int cla, int command,
265 int p1, int p2, int p3, String data) {
266 this.channel = channel;
267 this.cla = cla;
268 this.command = command;
269 this.p1 = p1;
270 this.p2 = p2;
271 this.p3 = p3;
272 this.data = data;
273 }
274 }
275
276 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700277 * A request object to use for transmitting data to an ICC.
278 */
279 private static final class ManualNetworkSelectionArgument {
280 public OperatorInfo operatorInfo;
281 public boolean persistSelection;
282
283 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
284 this.operatorInfo = operatorInfo;
285 this.persistSelection = persistSelection;
286 }
287 }
288
289 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
291 * request after sending. The main thread will notify the request when it is complete.
292 */
293 private static final class MainThreadRequest {
294 /** The argument to use for the request */
295 public Object argument;
296 /** The result of the request that is run on the main thread */
297 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800298 // The subscriber id that this request applies to. Defaults to
299 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
300 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301
Nathan Harold92bed182018-10-12 18:16:49 -0700302 // In cases where subId is unavailable, the caller needs to specify the phone.
303 public Phone phone;
304
vagdeviaf9a5b92018-08-15 16:01:53 -0700305 public WorkSource workSource;
306
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307 public MainThreadRequest(Object argument) {
308 this.argument = argument;
309 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800310
Nathan Harold92bed182018-10-12 18:16:49 -0700311 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
312 this.argument = argument;
313 if (phone != null) {
314 this.phone = phone;
315 }
316 this.workSource = workSource;
317 }
318
vagdeviaf9a5b92018-08-15 16:01:53 -0700319 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800320 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800321 if (subId != null) {
322 this.subId = subId;
323 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700324 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 }
327
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800328 private static final class IncomingThirdPartyCallArgs {
329 public final ComponentName component;
330 public final String callId;
331 public final String callerDisplayName;
332
333 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
334 String callerDisplayName) {
335 this.component = component;
336 this.callId = callId;
337 this.callerDisplayName = callerDisplayName;
338 }
339 }
340
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 /**
342 * A handler that processes messages on the main thread in the phone process. Since many
343 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
344 * inbound binder threads to the main thread in the phone process. The Binder thread
345 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
346 * on, which will be notified when the operation completes and will contain the result of the
347 * request.
348 *
349 * <p>If a MainThreadRequest object is provided in the msg.obj field,
350 * note that request.result must be set to something non-null for the calling thread to
351 * unblock.
352 */
353 private final class MainThreadHandler extends Handler {
354 @Override
355 public void handleMessage(Message msg) {
356 MainThreadRequest request;
357 Message onCompleted;
358 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800359 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700360 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
362 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700363 case CMD_HANDLE_USSD_REQUEST: {
364 request = (MainThreadRequest) msg.obj;
365 final Phone phone = getPhoneFromRequest(request);
366 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
367 String ussdRequest = ussdObject.first;
368 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700369
Pengquan Menga1bb6272018-09-06 09:59:22 -0700370 if (!isUssdApiAllowed(request.subId)) {
371 // Carrier does not support use of this API, return failure.
372 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
373 UssdResponse response = new UssdResponse(ussdRequest, null);
374 Bundle returnData = new Bundle();
375 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
376 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700377
Pengquan Menga1bb6272018-09-06 09:59:22 -0700378 request.result = true;
379 notifyRequester(request);
380 return;
381 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700382
Pengquan Menga1bb6272018-09-06 09:59:22 -0700383 try {
384 request.result = phone != null
385 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
386 } catch (CallStateException cse) {
387 request.result = false;
388 }
389 // Wake up the requesting thread
390 notifyRequester(request);
391 break;
pkanwar32d516d2016-10-14 19:37:38 -0700392 }
393
Yorke Lee716f67e2015-06-17 15:39:16 -0700394 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700396 final Phone phone = getPhoneFromRequest(request);
397 request.result = phone != null ?
398 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
399 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700401 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700405 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700406 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800408 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700409 if (uiccCard == null) {
410 loge("iccTransmitApduLogicalChannel: No UICC");
411 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700412 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700413 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
415 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 iccArgument.channel, iccArgument.cla, iccArgument.command,
418 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700420 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 break;
422
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 ar = (AsyncResult) msg.obj;
425 request = (MainThreadRequest) ar.userObj;
426 if (ar.exception == null && ar.result != null) {
427 request.result = ar.result;
428 } else {
429 request.result = new IccIoResult(0x6F, 0, (byte[])null);
430 if (ar.result == null) {
431 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800432 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800434 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 } else {
436 loge("iccTransmitApduLogicalChannel: Unknown exception");
437 }
438 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 break;
441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
443 request = (MainThreadRequest) msg.obj;
444 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800445 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 if (uiccCard == null) {
447 loge("iccTransmitApduBasicChannel: No UICC");
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700449 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 } else {
451 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
452 request);
453 uiccCard.iccTransmitApduBasicChannel(
454 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
455 iccArgument.p3, iccArgument.data, onCompleted);
456 }
457 break;
458
459 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
460 ar = (AsyncResult) msg.obj;
461 request = (MainThreadRequest) ar.userObj;
462 if (ar.exception == null && ar.result != null) {
463 request.result = ar.result;
464 } else {
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
466 if (ar.result == null) {
467 loge("iccTransmitApduBasicChannel: Empty response");
468 } else if (ar.exception instanceof CommandException) {
469 loge("iccTransmitApduBasicChannel: CommandException: " +
470 ar.exception);
471 } else {
472 loge("iccTransmitApduBasicChannel: Unknown exception");
473 }
474 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700475 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 break;
477
478 case CMD_EXCHANGE_SIM_IO:
479 request = (MainThreadRequest) msg.obj;
480 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 if (uiccCard == null) {
483 loge("iccExchangeSimIO: No UICC");
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 } else {
487 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
488 request);
489 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
490 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
491 iccArgument.data, onCompleted);
492 }
493 break;
494
495 case EVENT_EXCHANGE_SIM_IO_DONE:
496 ar = (AsyncResult) msg.obj;
497 request = (MainThreadRequest) ar.userObj;
498 if (ar.exception == null && ar.result != null) {
499 request.result = ar.result;
500 } else {
501 request.result = new IccIoResult(0x6f, 0, (byte[])null);
502 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 break;
505
Derek Tan4d5e5c12014-02-04 11:54:58 -0800506 case CMD_SEND_ENVELOPE:
507 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800508 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700509 if (uiccCard == null) {
510 loge("sendEnvelopeWithStatus: No UICC");
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700513 } else {
514 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
515 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
516 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 break;
518
519 case EVENT_SEND_ENVELOPE_DONE:
520 ar = (AsyncResult) msg.obj;
521 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700522 if (ar.exception == null && ar.result != null) {
523 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800524 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
526 if (ar.result == null) {
527 loge("sendEnvelopeWithStatus: Empty response");
528 } else if (ar.exception instanceof CommandException) {
529 loge("sendEnvelopeWithStatus: CommandException: " +
530 ar.exception);
531 } else {
532 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
533 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800534 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800536 break;
537
Shishir Agrawal566b7612013-10-28 14:41:00 -0700538 case CMD_OPEN_CHANNEL:
539 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800540 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800541 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 if (uiccCard == null) {
543 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800544 request.result = new IccOpenLogicalChannelResponse(-1,
545 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 } else {
548 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800549 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
550 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 break;
553
554 case EVENT_OPEN_CHANNEL_DONE:
555 ar = (AsyncResult) msg.obj;
556 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 int[] result = (int[]) ar.result;
560 int channelId = result[0];
561 byte[] selectResponse = null;
562 if (result.length > 1) {
563 selectResponse = new byte[result.length - 1];
564 for (int i = 1; i < result.length; ++i) {
565 selectResponse[i - 1] = (byte) result[i];
566 }
567 }
568 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700569 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 if (ar.result == null) {
572 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 if (ar.exception != null) {
575 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
576 }
577
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700578 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700579 if (ar.exception instanceof CommandException) {
580 CommandException.Error error =
581 ((CommandException) (ar.exception)).getCommandError();
582 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700584 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700585 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 }
587 }
588 openChannelResp = new IccOpenLogicalChannelResponse(
589 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700591 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 break;
594
595 case CMD_CLOSE_CHANNEL:
596 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 if (uiccCard == null) {
599 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900600 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 } else {
603 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
604 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800609 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
610 break;
611
612 case CMD_NV_READ_ITEM:
613 request = (MainThreadRequest) msg.obj;
614 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700615 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800616 break;
617
618 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 ar = (AsyncResult) msg.obj;
620 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800621 if (ar.exception == null && ar.result != null) {
622 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800624 request.result = "";
625 if (ar.result == null) {
626 loge("nvReadItem: Empty response");
627 } else if (ar.exception instanceof CommandException) {
628 loge("nvReadItem: CommandException: " +
629 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800631 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 }
633 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
Jake Hambye994d462014-02-03 13:10:13 -0800637 case CMD_NV_WRITE_ITEM:
638 request = (MainThreadRequest) msg.obj;
639 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
640 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700641 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
642 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800643 break;
644
645 case EVENT_NV_WRITE_ITEM_DONE:
646 handleNullReturnEvent(msg, "nvWriteItem");
647 break;
648
649 case CMD_NV_WRITE_CDMA_PRL:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
652 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
653 break;
654
655 case EVENT_NV_WRITE_CDMA_PRL_DONE:
656 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
657 break;
658
chen xu6dac5ab2018-10-26 17:39:23 -0700659 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800660 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700661 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
662 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800663 break;
664
chen xu6dac5ab2018-10-26 17:39:23 -0700665 case EVENT_RESET_MODEM_CONFIG_DONE:
666 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
Jake Hamby7c27be32014-03-03 13:25:59 -0800669 case CMD_GET_PREFERRED_NETWORK_TYPE:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700672 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800673 break;
674
675 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result; // Integer
680 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800681 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800682 if (ar.result == null) {
683 loge("getPreferredNetworkType: Empty response");
684 } else if (ar.exception instanceof CommandException) {
685 loge("getPreferredNetworkType: CommandException: " +
686 ar.exception);
687 } else {
688 loge("getPreferredNetworkType: Unknown exception");
689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800692 break;
693
694 case CMD_SET_PREFERRED_NETWORK_TYPE:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
697 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700698 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 break;
700
701 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
702 handleNullReturnEvent(msg, "setPreferredNetworkType");
703 break;
704
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000705 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
706 request = (MainThreadRequest)msg.obj;
707 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700708 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000709 break;
710
711 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
712 ar = (AsyncResult)msg.obj;
713 request = (MainThreadRequest)ar.userObj;
714 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000716 break;
717
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800718 case CMD_SET_VOICEMAIL_NUMBER:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
721 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800722 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
723 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800724 break;
725
726 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
727 handleNullReturnEvent(msg, "setVoicemailNumber");
728 break;
729
Stuart Scott54788802015-03-30 13:18:01 -0700730 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
733 request);
734 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
735 break;
736
737 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
738 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
739 break;
740
Shishir Agrawal302c8692015-06-19 13:49:39 -0700741 case CMD_PERFORM_NETWORK_SCAN:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
744 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
745 break;
746
747 case EVENT_PERFORM_NETWORK_SCAN_DONE:
748 ar = (AsyncResult) msg.obj;
749 request = (MainThreadRequest) ar.userObj;
750 CellNetworkScanResult cellScanResult;
751 if (ar.exception == null && ar.result != null) {
752 cellScanResult = new CellNetworkScanResult(
753 CellNetworkScanResult.STATUS_SUCCESS,
754 (List<OperatorInfo>) ar.result);
755 } else {
756 if (ar.result == null) {
757 loge("getCellNetworkScanResults: Empty response");
758 }
759 if (ar.exception != null) {
760 loge("getCellNetworkScanResults: Exception: " + ar.exception);
761 }
762 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
763 if (ar.exception instanceof CommandException) {
764 CommandException.Error error =
765 ((CommandException) (ar.exception)).getCommandError();
766 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
767 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
768 } else if (error == CommandException.Error.GENERIC_FAILURE) {
769 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
770 }
771 }
772 cellScanResult = new CellNetworkScanResult(errorCode, null);
773 }
774 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700776 break;
777
778 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
779 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700780 ManualNetworkSelectionArgument selArg =
781 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700782 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
783 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700784 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
785 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 break;
787
788 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
791 if (ar.exception == null) {
792 request.result = true;
793 } else {
794 request.result = false;
795 loge("setNetworkSelectionModeManual " + ar.exception);
796 }
797 notifyRequester(request);
798 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 break;
800
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 case CMD_GET_MODEM_ACTIVITY_INFO:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700804 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700805 break;
806
807 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 if (ar.exception == null && ar.result != null) {
811 request.result = ar.result;
812 } else {
813 if (ar.result == null) {
814 loge("queryModemActivityInfo: Empty response");
815 } else if (ar.exception instanceof CommandException) {
816 loge("queryModemActivityInfo: CommandException: " +
817 ar.exception);
818 } else {
819 loge("queryModemActivityInfo: Unknown exception");
820 }
821 }
Amit Mahajand4766222016-01-28 15:28:28 -0800822 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
823 if (request.result == null) {
824 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
825 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700826 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700827 break;
828
Meng Wang1a7c35a2016-05-05 20:56:15 -0700829 case CMD_SET_ALLOWED_CARRIERS:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
832 mPhone.setAllowedCarriers(
833 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700834 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700835 break;
836
837 case EVENT_SET_ALLOWED_CARRIERS_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 if (ar.result == null) {
844 loge("setAllowedCarriers: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("setAllowedCarriers: CommandException: " +
847 ar.exception);
848 } else {
849 loge("setAllowedCarriers: Unknown exception");
850 }
851 }
852 // Result cannot be null. Return -1 on error.
853 if (request.result == null) {
854 request.result = new int[]{-1};
855 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700856 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 break;
858
859 case CMD_GET_ALLOWED_CARRIERS:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700862 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 break;
864
865 case EVENT_GET_ALLOWED_CARRIERS_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
871 if (ar.result == null) {
872 loge("getAllowedCarriers: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("getAllowedCarriers: CommandException: " +
875 ar.exception);
876 } else {
877 loge("getAllowedCarriers: Unknown exception");
878 }
879 }
880 // Result cannot be null. Return empty list of CarrierIdentifier.
881 if (request.result == null) {
882 request.result = new ArrayList<CarrierIdentifier>(0);
883 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700884 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 break;
886
Nathan Haroldb3014052017-01-25 15:57:32 -0800887 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
888 ar = (AsyncResult) msg.obj;
889 request = (MainThreadRequest) ar.userObj;
890 if (ar.exception == null && ar.result != null) {
891 request.result = ar.result;
892 } else {
893 request.result = new IllegalArgumentException(
894 "Failed to retrieve Forbidden Plmns");
895 if (ar.result == null) {
896 loge("getForbiddenPlmns: Empty response");
897 } else {
898 loge("getForbiddenPlmns: Unknown exception");
899 }
900 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700901 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800902 break;
903
904 case CMD_GET_FORBIDDEN_PLMNS:
905 request = (MainThreadRequest) msg.obj;
906 uiccCard = getUiccCardFromRequest(request);
907 if (uiccCard == null) {
908 loge("getForbiddenPlmns() UiccCard is null");
909 request.result = new IllegalArgumentException(
910 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700911 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800912 break;
913 }
914 Integer appType = (Integer) request.argument;
915 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
916 if (uiccApp == null) {
917 loge("getForbiddenPlmns() no app with specified type -- "
918 + appType);
919 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700920 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800921 break;
922 } else {
923 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
924 + " specified type -- " + appType);
925 }
926 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
927 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
928 onCompleted);
929 break;
930
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000931 case CMD_SWITCH_SLOTS:
932 request = (MainThreadRequest) msg.obj;
933 int[] physicalSlots = (int[]) request.argument;
934 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
935 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
936 break;
937
938 case EVENT_SWITCH_SLOTS_DONE:
939 ar = (AsyncResult) msg.obj;
940 request = (MainThreadRequest) ar.userObj;
941 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
943 break;
944 case CMD_GET_NETWORK_SELECTION_MODE:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
947 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
948 break;
949
950 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
951 ar = (AsyncResult) msg.obj;
952 request = (MainThreadRequest) ar.userObj;
953 if (ar.exception != null) {
954 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
955 } else {
956 int mode = ((int[]) ar.result)[0];
957 if (mode == 0) {
958 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
959 } else {
960 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
961 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000962 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700963 notifyRequester(request);
964 break;
965 case CMD_GET_CDMA_ROAMING_MODE:
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
968 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
969 break;
970 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 if (ar.exception != null) {
974 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
975 } else {
976 request.result = ((int[]) ar.result)[0];
977 }
978 notifyRequester(request);
979 break;
980 case CMD_SET_CDMA_ROAMING_MODE:
981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
983 int mode = (int) request.argument;
984 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
985 break;
986 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 request.result = ar.exception == null;
990 notifyRequester(request);
991 break;
992 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
995 int subscriptionMode = (int) request.argument;
996 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
997 break;
998 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 request.result = ar.exception == null;
1002 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001003 break;
1004
Nathan Harold3ff88932018-08-14 10:19:49 -07001005 case CMD_GET_ALL_CELL_INFO:
1006 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001007 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001008 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001009 break;
1010
1011 case EVENT_GET_ALL_CELL_INFO_DONE:
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001014 // If a timeout occurs, the response will be null
1015 request.result = (ar.exception == null && ar.result != null)
1016 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001017 synchronized (request) {
1018 request.notifyAll();
1019 }
1020 break;
1021
1022 case CMD_GET_CELL_LOCATION: {
1023 request = (MainThreadRequest) msg.obj;
1024 WorkSource ws = (WorkSource) request.argument;
1025 Phone phone = getPhoneFromRequest(request);
1026 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1027 break;
1028 }
1029
1030 case EVENT_GET_CELL_LOCATION_DONE: {
1031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
1033 if (ar.exception == null) {
1034 request.result = ar.result;
1035 } else {
1036 Phone phone = getPhoneFromRequest(request);
1037 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1038 ? new CdmaCellLocation() : new GsmCellLocation();
1039 }
1040
1041 synchronized (request) {
1042 request.notifyAll();
1043 }
1044 break;
1045 }
1046
chen xu6dac5ab2018-10-26 17:39:23 -07001047 case CMD_MODEM_REBOOT:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1050 mPhone.rebootModem(onCompleted);
1051 break;
1052
1053 case EVENT_CMD_MODEM_REBOOT_DONE:
1054 handleNullReturnEvent(msg, "rebootModem");
1055 break;
1056
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001057 default:
1058 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1059 break;
1060 }
1061 }
Jake Hambye994d462014-02-03 13:10:13 -08001062
Pengquan Menga1bb6272018-09-06 09:59:22 -07001063 private void notifyRequester(MainThreadRequest request) {
1064 synchronized (request) {
1065 request.notifyAll();
1066 }
1067 }
1068
Jake Hambye994d462014-02-03 13:10:13 -08001069 private void handleNullReturnEvent(Message msg, String command) {
1070 AsyncResult ar = (AsyncResult) msg.obj;
1071 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1072 if (ar.exception == null) {
1073 request.result = true;
1074 } else {
1075 request.result = false;
1076 if (ar.exception instanceof CommandException) {
1077 loge(command + ": CommandException: " + ar.exception);
1078 } else {
1079 loge(command + ": Unknown exception");
1080 }
1081 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001082 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 }
1085
1086 /**
1087 * Posts the specified command to be executed on the main thread,
1088 * waits for the request to complete, and returns the result.
1089 * @see #sendRequestAsync
1090 */
1091 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001092 return sendRequest(
1093 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001094 }
1095
1096 /**
1097 * Posts the specified command to be executed on the main thread,
1098 * waits for the request to complete, and returns the result.
1099 * @see #sendRequestAsync
1100 */
1101 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1102 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001103 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001104 }
1105
1106 /**
1107 * Posts the specified command to be executed on the main thread,
1108 * waits for the request to complete, and returns the result.
1109 * @see #sendRequestAsync
1110 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001111 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001112 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001113 }
1114
1115 /**
1116 * Posts the specified command to be executed on the main thread,
1117 * waits for the request to complete, and returns the result.
1118 * @see #sendRequestAsync
1119 */
Nathan Harold92bed182018-10-12 18:16:49 -07001120 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1121 return sendRequest(command, argument, subId, null, workSource);
1122 }
1123
1124 /**
1125 * Posts the specified command to be executed on the main thread,
1126 * waits for the request to complete, and returns the result.
1127 * @see #sendRequestAsync
1128 */
1129 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1130 return sendRequest(
1131 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1132 }
1133
1134 /**
1135 * Posts the specified command to be executed on the main thread,
1136 * waits for the request to complete, and returns the result.
1137 * @see #sendRequestAsync
1138 */
1139 private Object sendRequest(
1140 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1142 throw new RuntimeException("This method will deadlock if called from the main thread.");
1143 }
1144
Nathan Harold92bed182018-10-12 18:16:49 -07001145 MainThreadRequest request = null;
1146 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1147 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1148 } else if (phone != null) {
1149 request = new MainThreadRequest(argument, phone, workSource);
1150 } else {
1151 request = new MainThreadRequest(argument, subId, workSource);
1152 }
1153
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154 Message msg = mMainThreadHandler.obtainMessage(command, request);
1155 msg.sendToTarget();
1156
1157 // Wait for the request to complete
1158 synchronized (request) {
1159 while (request.result == null) {
1160 try {
1161 request.wait();
1162 } catch (InterruptedException e) {
1163 // Do nothing, go back and wait until the request is complete
1164 }
1165 }
1166 }
1167 return request.result;
1168 }
1169
1170 /**
1171 * Asynchronous ("fire and forget") version of sendRequest():
1172 * Posts the specified command to be executed on the main thread, and
1173 * returns immediately.
1174 * @see #sendRequest
1175 */
1176 private void sendRequestAsync(int command) {
1177 mMainThreadHandler.sendEmptyMessage(command);
1178 }
1179
1180 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001181 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1182 * @see {@link #sendRequest(int,Object)}
1183 */
1184 private void sendRequestAsync(int command, Object argument) {
1185 MainThreadRequest request = new MainThreadRequest(argument);
1186 Message msg = mMainThreadHandler.obtainMessage(command, request);
1187 msg.sendToTarget();
1188 }
1189
1190 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 * Initialize the singleton PhoneInterfaceManager instance.
1192 * This is only done once, at startup, from PhoneApp.onCreate().
1193 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001194 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 synchronized (PhoneInterfaceManager.class) {
1196 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001197 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001198 } else {
1199 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1200 }
1201 return sInstance;
1202 }
1203 }
1204
1205 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001206 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 mApp = app;
1208 mPhone = phone;
1209 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001210 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1212 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001213 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001214 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001215 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001216 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001217 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 publish();
1220 }
1221
1222 private void publish() {
1223 if (DBG) log("publish: " + this);
1224
1225 ServiceManager.addService("phone", this);
1226 }
1227
Stuart Scott584921c2015-01-15 17:10:34 -08001228 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001229 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1230 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001231 }
1232
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001233 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1234 Phone phone = getPhoneFromRequest(request);
1235 return phone == null ? null :
1236 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1237 }
1238
Wink Saville36469e72014-06-11 15:17:00 -07001239 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001240 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001241 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243
1244 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001245 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001246 }
1247
Wink Savilleb564aae2014-10-23 10:18:09 -07001248 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (DBG) log("dial: " + number);
1250 // No permission check needed here: This is just a wrapper around the
1251 // ACTION_DIAL intent, which is available to any app since it puts up
1252 // the UI before it does anything.
1253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001254 final long identity = Binder.clearCallingIdentity();
1255 try {
1256 String url = createTelUrl(number);
1257 if (url == null) {
1258 return;
1259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001261 // PENDING: should we just silently fail if phone is offhook or ringing?
1262 PhoneConstants.State state = mCM.getState(subId);
1263 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1264 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1265 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1266 mApp.startActivity(intent);
1267 }
1268 } finally {
1269 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 }
1271 }
1272
1273 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001274 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001275 }
1276
Wink Savilleb564aae2014-10-23 10:18:09 -07001277 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 if (DBG) log("call: " + number);
1279
1280 // This is just a wrapper around the ACTION_CALL intent, but we still
1281 // need to do a permission check since we're calling startActivity()
1282 // from the context of the phone app.
1283 enforceCallPermission();
1284
1285 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1286 != AppOpsManager.MODE_ALLOWED) {
1287 return;
1288 }
1289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001290 final long identity = Binder.clearCallingIdentity();
1291 try {
1292 String url = createTelUrl(number);
1293 if (url == null) {
1294 return;
1295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001297 boolean isValid = false;
1298 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1299 if (slist != null) {
1300 for (SubscriptionInfo subInfoRecord : slist) {
1301 if (subInfoRecord.getSubscriptionId() == subId) {
1302 isValid = true;
1303 break;
1304 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001305 }
Wink Saville08874612014-08-31 19:19:58 -07001306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001307 if (!isValid) {
1308 return;
1309 }
Wink Saville08874612014-08-31 19:19:58 -07001310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001311 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1312 intent.putExtra(SUBSCRIPTION_KEY, subId);
1313 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1314 mApp.startActivity(intent);
1315 } finally {
1316 Binder.restoreCallingIdentity(identity);
1317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 }
1319
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001321 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001322 }
1323
Wink Savilleb564aae2014-10-23 10:18:09 -07001324 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001326 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1327 }
1328
1329 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001330 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001331 }
1332
Wink Savilleb564aae2014-10-23 10:18:09 -07001333 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001334 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001335 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1336 }
1337
1338 /** {@hide} */
1339 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001340 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001341 }
1342
Wink Savilleb564aae2014-10-23 10:18:09 -07001343 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001345
1346 final long identity = Binder.clearCallingIdentity();
1347 try {
1348 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1349 checkSimPin.start();
1350 return checkSimPin.unlockSim(null, pin);
1351 } finally {
1352 Binder.restoreCallingIdentity(identity);
1353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001354 }
1355
Wink Saville9de0f752013-10-22 19:04:03 -07001356 /** {@hide} */
1357 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001358 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
Wink Savilleb564aae2014-10-23 10:18:09 -07001361 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001363
1364 final long identity = Binder.clearCallingIdentity();
1365 try {
1366 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1367 checkSimPuk.start();
1368 return checkSimPuk.unlockSim(puk, pin);
1369 } finally {
1370 Binder.restoreCallingIdentity(identity);
1371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372 }
1373
1374 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001375 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 * a synchronous one.
1377 */
1378 private static class UnlockSim extends Thread {
1379
1380 private final IccCard mSimCard;
1381
1382 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001383 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1384 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385
1386 // For replies from SimCard interface
1387 private Handler mHandler;
1388
1389 // For async handler to identify request type
1390 private static final int SUPPLY_PIN_COMPLETE = 100;
1391
1392 public UnlockSim(IccCard simCard) {
1393 mSimCard = simCard;
1394 }
1395
1396 @Override
1397 public void run() {
1398 Looper.prepare();
1399 synchronized (UnlockSim.this) {
1400 mHandler = new Handler() {
1401 @Override
1402 public void handleMessage(Message msg) {
1403 AsyncResult ar = (AsyncResult) msg.obj;
1404 switch (msg.what) {
1405 case SUPPLY_PIN_COMPLETE:
1406 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1407 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001408 mRetryCount = msg.arg1;
1409 if (ar.exception != null) {
1410 if (ar.exception instanceof CommandException &&
1411 ((CommandException)(ar.exception)).getCommandError()
1412 == CommandException.Error.PASSWORD_INCORRECT) {
1413 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1414 } else {
1415 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1416 }
1417 } else {
1418 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 mDone = true;
1421 UnlockSim.this.notifyAll();
1422 }
1423 break;
1424 }
1425 }
1426 };
1427 UnlockSim.this.notifyAll();
1428 }
1429 Looper.loop();
1430 }
1431
1432 /*
1433 * Use PIN or PUK to unlock SIM card
1434 *
1435 * If PUK is null, unlock SIM card with PIN
1436 *
1437 * If PUK is not null, unlock SIM card with PUK and set PIN code
1438 */
Wink Saville9de0f752013-10-22 19:04:03 -07001439 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
1441 while (mHandler == null) {
1442 try {
1443 wait();
1444 } catch (InterruptedException e) {
1445 Thread.currentThread().interrupt();
1446 }
1447 }
1448 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1449
1450 if (puk == null) {
1451 mSimCard.supplyPin(pin, callback);
1452 } else {
1453 mSimCard.supplyPuk(puk, pin, callback);
1454 }
1455
1456 while (!mDone) {
1457 try {
1458 Log.d(LOG_TAG, "wait for done");
1459 wait();
1460 } catch (InterruptedException e) {
1461 // Restore the interrupted status
1462 Thread.currentThread().interrupt();
1463 }
1464 }
1465 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001466 int[] resultArray = new int[2];
1467 resultArray[0] = mResult;
1468 resultArray[1] = mRetryCount;
1469 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470 }
1471 }
1472
1473 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001474 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001475
1476 }
1477
Wink Savilleb564aae2014-10-23 10:18:09 -07001478 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 // No permission check needed here: this call is harmless, and it's
1480 // needed for the ServiceState.requestStateUpdate() call (which is
1481 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001482 final long identity = Binder.clearCallingIdentity();
1483 try {
1484 final Phone phone = getPhone(subId);
1485 if (phone != null) {
1486 phone.updateServiceLocation();
1487 }
1488 } finally {
1489 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 }
1492
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001493 @Override
1494 public boolean isRadioOn(String callingPackage) {
1495 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001496 }
1497
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001498 @Override
1499 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001501 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001502 return false;
1503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001504
1505 final long identity = Binder.clearCallingIdentity();
1506 try {
1507 return isRadioOnForSubscriber(subId);
1508 } finally {
1509 Binder.restoreCallingIdentity(identity);
1510 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001511 }
1512
1513 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001514 final long identity = Binder.clearCallingIdentity();
1515 try {
1516 final Phone phone = getPhone(subId);
1517 if (phone != null) {
1518 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1519 } else {
1520 return false;
1521 }
1522 } finally {
1523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
1526
1527 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001528 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
Wink Saville36469e72014-06-11 15:17:00 -07001530
Wink Savilleb564aae2014-10-23 10:18:09 -07001531 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001533
1534 final long identity = Binder.clearCallingIdentity();
1535 try {
1536 final Phone phone = getPhone(subId);
1537 if (phone != null) {
1538 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1539 }
1540 } finally {
1541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001542 }
Wink Saville36469e72014-06-11 15:17:00 -07001543 }
1544
1545 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001546 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001547 }
1548
Wink Savilleb564aae2014-10-23 10:18:09 -07001549 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001551
1552 final long identity = Binder.clearCallingIdentity();
1553 try {
1554 final Phone phone = getPhone(subId);
1555 if (phone == null) {
1556 return false;
1557 }
1558 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1559 toggleRadioOnOffForSubscriber(subId);
1560 }
1561 return true;
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
Wink Saville36469e72014-06-11 15:17:00 -07001566
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001567 public boolean needMobileRadioShutdown() {
1568 /*
1569 * If any of the Radios are available, it will need to be
1570 * shutdown. So return true if any Radio is available.
1571 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1575 Phone phone = PhoneFactory.getPhone(i);
1576 if (phone != null && phone.isRadioAvailable()) return true;
1577 }
1578 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1579 return false;
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001582 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001583 }
1584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001585 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001586 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001587 enforceModifyPermission();
1588
1589 final long identity = Binder.clearCallingIdentity();
1590 try {
1591 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1592 logv("Shutting down Phone " + i);
1593 shutdownRadioUsingPhoneId(i);
1594 }
1595 } finally {
1596 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001597 }
1598 }
1599
1600 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001601 Phone phone = PhoneFactory.getPhone(phoneId);
1602 if (phone != null && phone.isRadioAvailable()) {
1603 phone.shutdownRadio();
1604 }
1605 }
1606
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001608 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001609
1610 final long identity = Binder.clearCallingIdentity();
1611 try {
1612 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1613 if (defaultPhone != null) {
1614 defaultPhone.setRadioPower(turnOn);
1615 return true;
1616 } else {
1617 loge("There's no default phone.");
1618 return false;
1619 }
1620 } finally {
1621 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001622 }
Wink Saville36469e72014-06-11 15:17:00 -07001623 }
1624
Wink Savilleb564aae2014-10-23 10:18:09 -07001625 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001626 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001627
1628 final long identity = Binder.clearCallingIdentity();
1629 try {
1630 final Phone phone = getPhone(subId);
1631 if (phone != null) {
1632 phone.setRadioPower(turnOn);
1633 return true;
1634 } else {
1635 return false;
1636 }
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 }
1641
Wink Saville36469e72014-06-11 15:17:00 -07001642 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001643 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 public boolean enableDataConnectivity() {
1645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001646
1647 final long identity = Binder.clearCallingIdentity();
1648 try {
1649 int subId = mSubscriptionController.getDefaultDataSubId();
1650 final Phone phone = getPhone(subId);
1651 if (phone != null) {
1652 phone.setUserDataEnabled(true);
1653 return true;
1654 } else {
1655 return false;
1656 }
1657 } finally {
1658 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 }
1661
Wink Saville36469e72014-06-11 15:17:00 -07001662 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001663 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 public boolean disableDataConnectivity() {
1665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001666
1667 final long identity = Binder.clearCallingIdentity();
1668 try {
1669 int subId = mSubscriptionController.getDefaultDataSubId();
1670 final Phone phone = getPhone(subId);
1671 if (phone != null) {
1672 phone.setUserDataEnabled(false);
1673 return true;
1674 } else {
1675 return false;
1676 }
1677 } finally {
1678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001683 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684 final long identity = Binder.clearCallingIdentity();
1685 try {
1686 final Phone phone = getPhone(subId);
1687 if (phone != null) {
1688 return phone.isDataAllowed();
1689 } else {
1690 return false;
1691 }
1692 } finally {
1693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
1696
1697 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001698 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001699 }
1700
pkanwarae03a6b2016-11-06 20:37:09 -08001701 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001702 enforceCallPermission();
1703
1704 final long identity = Binder.clearCallingIdentity();
1705 try {
1706 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1707 return;
1708 }
1709 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1710 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1711 } finally {
1712 Binder.restoreCallingIdentity(identity);
1713 }
pkanwar32d516d2016-10-14 19:37:38 -07001714 };
1715
Wink Savilleb564aae2014-10-23 10:18:09 -07001716 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001718
1719 final long identity = Binder.clearCallingIdentity();
1720 try {
1721 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1722 return false;
1723 }
1724 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001731 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001732 }
1733
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001734 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 Phone phone = PhoneFactory.getPhone(slotIndex);
1738 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1739 PhoneConstantConversions.convertCallState(phone.getState());
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
1742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
1744
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001747 final long identity = Binder.clearCallingIdentity();
1748 try {
1749 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1750 if (phone != null) {
1751 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1752 } else {
1753 return PhoneConstantConversions.convertDataState(
1754 PhoneConstants.DataState.DISCONNECTED);
1755 }
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760
Sanket Padawe356d7632015-06-22 14:03:32 -07001761 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763 final long identity = Binder.clearCallingIdentity();
1764 try {
1765 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1766 if (phone != null) {
1767 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1768 } else {
1769 return TelephonyManager.DATA_ACTIVITY_NONE;
1770 }
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
1775
1776 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001777 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001778 mPhone.getContext().getSystemService(AppOpsManager.class)
1779 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001780 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001781 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001782 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
1784
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 final long identity = Binder.clearCallingIdentity();
1787 try {
1788 if (DBG_LOC) log("getCellLocation: is active user");
1789 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 int subId = mSubscriptionController.getDefaultDataSubId();
1791 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1792 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001793 return data;
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
1796 }
Svetoslav64fad262015-04-14 14:35:21 -07001797 }
1798
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001800 public String getNetworkCountryIsoForPhone(int phoneId) {
1801 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1802 // registered cell info, so return a NULL country instead.
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001805 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1806 // Get default phone in this case.
1807 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1808 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001809 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001810 // Todo: fix this when we can get the actual cellular network info when the device
1811 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001812 if (TelephonyManager.NETWORK_TYPE_IWLAN
1813 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1814 return "";
1815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001816 Phone phone = PhoneFactory.getPhone(phoneId);
1817 if (phone != null) {
1818 ServiceStateTracker sst = phone.getServiceStateTracker();
1819 if (sst != null) {
1820 LocaleTracker lt = sst.getLocaleTracker();
1821 if (lt != null) {
1822 return lt.getCurrentCountry();
1823 }
1824 }
1825 }
1826 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001827 } finally {
1828 Binder.restoreCallingIdentity(identity);
1829 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001830 }
1831
1832 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001834 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001835 }
1836
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001838 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 mApp.enforceCallingOrSelfPermission(
1840 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001841
1842 final long identity = Binder.clearCallingIdentity();
1843 try {
1844 final Phone phone = getPhone(subId);
1845 if (phone != null) {
1846 phone.enableLocationUpdates();
1847 }
1848 } finally {
1849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 }
1852
1853 @Override
1854 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001855 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001856 }
1857
Sanket Padawe356d7632015-06-22 14:03:32 -07001858 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001859 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 mApp.enforceCallingOrSelfPermission(
1861 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862
1863 final long identity = Binder.clearCallingIdentity();
1864 try {
1865 final Phone phone = getPhone(subId);
1866 if (phone != null) {
1867 phone.disableLocationUpdates();
1868 }
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Nathan Harold31d7ff32018-10-15 20:20:30 -07001874 /**
1875 * Returns the target SDK version number for a given package name.
1876 *
1877 * @return target SDK if the package is found or INT_MAX.
1878 */
1879 private int getTargetSdk(String packageName) {
1880 try {
1881 final ApplicationInfo ai =
1882 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1883 if (ai != null) return ai.targetSdkVersion;
1884 } catch (PackageManager.NameNotFoundException unexpected) {
1885 }
1886 return Integer.MAX_VALUE;
1887 }
1888
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 @Override
1890 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001891 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1892 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001893 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1894 throw new SecurityException(
1895 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1896 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001897
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1899 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1900 return null;
1901 }
Svetoslav64fad262015-04-14 14:35:21 -07001902
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001903 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904
Nathan Haroldf180aac2018-06-01 18:43:55 -07001905 List<CellInfo> info = getAllCellInfo(callingPackage);
1906 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907
Nathan Haroldf180aac2018-06-01 18:43:55 -07001908 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1909 for (CellInfo ci : info) {
1910 if (ci instanceof CellInfoGsm) {
1911 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1912 } else if (ci instanceof CellInfoWcdma) {
1913 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001916 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 }
1918
1919
1920 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001921 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001922 mPhone.getContext().getSystemService(AppOpsManager.class)
1923 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001924 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001925 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001926 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 }
1928
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001929 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001930 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931 final long identity = Binder.clearCallingIdentity();
1932 try {
1933 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1934 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001935 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001936 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937 if (info != null) cellInfos.addAll(info);
1938 }
1939 return cellInfos;
1940 } finally {
1941 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943 }
1944
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001945 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001947 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001948 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001949
1950 final long identity = Binder.clearCallingIdentity();
1951 try {
1952 mPhone.setCellInfoListRate(rateInMillis, workSource);
1953 } finally {
1954 Binder.restoreCallingIdentity(identity);
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
1957
Shishir Agrawala9f32182016-04-12 12:00:16 -07001958 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001959 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001960 Phone phone = PhoneFactory.getPhone(slotIndex);
1961 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001962 return null;
1963 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001964 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001965 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1966 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001967 return null;
1968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969
1970 final long identity = Binder.clearCallingIdentity();
1971 try {
1972 return phone.getImei();
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
1975 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001976 }
1977
1978 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001979 public String getTypeAllocationCodeForSlot(int slotIndex) {
1980 Phone phone = PhoneFactory.getPhone(slotIndex);
1981 String tac = null;
1982 if (phone != null) {
1983 String imei = phone.getImei();
1984 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1985 }
1986 return tac;
1987 }
1988
1989 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001990 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001991 Phone phone = PhoneFactory.getPhone(slotIndex);
1992 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001993 return null;
1994 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001995 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001996 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1997 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001998 return null;
1999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000
2001 final long identity = Binder.clearCallingIdentity();
2002 try {
2003 return phone.getMeid();
2004 } finally {
2005 Binder.restoreCallingIdentity(identity);
2006 }
Jack Yu2af8d712017-03-15 17:14:14 -07002007 }
2008
2009 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002010 public String getManufacturerCodeForSlot(int slotIndex) {
2011 Phone phone = PhoneFactory.getPhone(slotIndex);
2012 String manufacturerCode = null;
2013 if (phone != null) {
2014 String meid = phone.getMeid();
2015 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2016 }
2017 return manufacturerCode;
2018 }
2019
2020 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002021 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002022 Phone phone = PhoneFactory.getPhone(slotIndex);
2023 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002024 return null;
2025 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002026 int subId = phone.getSubId();
2027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2028 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2029 return null;
2030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002031
2032 final long identity = Binder.clearCallingIdentity();
2033 try {
2034 return phone.getDeviceSvn();
2035 } finally {
2036 Binder.restoreCallingIdentity(identity);
2037 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002038 }
2039
fionaxu43304da2017-11-27 22:51:16 -08002040 @Override
2041 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 final Phone phone = getPhone(subId);
2045 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
2048 }
fionaxu43304da2017-11-27 22:51:16 -08002049 }
2050
2051 @Override
2052 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002053 final long identity = Binder.clearCallingIdentity();
2054 try {
2055 final Phone phone = getPhone(subId);
2056 return phone == null ? null : phone.getCarrierName();
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
2059 }
fionaxu43304da2017-11-27 22:51:16 -08002060 }
2061
calvinpanffe225e2018-11-01 19:43:06 +08002062 @Override
2063 public int getSubscriptionMNOCarrierId(int subId) {
2064 final long identity = Binder.clearCallingIdentity();
2065 try {
2066 final Phone phone = getPhone(subId);
2067 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2068 } finally {
2069 Binder.restoreCallingIdentity(identity);
2070 }
2071 }
2072
chen xu25637222018-11-04 17:17:00 -08002073 @Override
2074 public int getSubscriptionPreciseCarrierId(int subId) {
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 final Phone phone = getPhone(subId);
2078 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2079 : phone.getPreciseCarrierId();
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
2082 }
2083 }
2084
2085 @Override
2086 public String getSubscriptionPreciseCarrierName(int subId) {
2087 final long identity = Binder.clearCallingIdentity();
2088 try {
2089 final Phone phone = getPhone(subId);
2090 return phone == null ? null : phone.getPreciseCarrierName();
2091 } finally {
2092 Binder.restoreCallingIdentity(identity);
2093 }
2094 }
2095
chen xu651eec72018-11-11 19:03:44 -08002096 @Override
2097 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) {
2098 final Phone phone = PhoneFactory.getPhone(slotIndex);
2099 if (phone == null) {
2100 return TelephonyManager.UNKNOWN_CARRIER_ID;
2101 }
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
2108 }
2109
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 //
2111 // Internal helper methods.
2112 //
2113
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002114 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2116 *
2117 * @throws SecurityException if the caller does not have the required permission
2118 */
2119 private void enforceModifyPermission() {
2120 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2121 }
2122
2123 /**
2124 * Make sure the caller has the CALL_PHONE permission.
2125 *
2126 * @throws SecurityException if the caller does not have the required permission
2127 */
2128 private void enforceCallPermission() {
2129 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2130 }
2131
Stuart Scott8eef64f2015-04-08 15:13:54 -07002132 private void enforceConnectivityInternalPermission() {
2133 mApp.enforceCallingOrSelfPermission(
2134 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2135 "ConnectivityService");
2136 }
2137
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 private String createTelUrl(String number) {
2139 if (TextUtils.isEmpty(number)) {
2140 return null;
2141 }
2142
Jake Hambye994d462014-02-03 13:10:13 -08002143 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 }
2145
Ihab Awadf9e92732013-12-05 18:02:52 -08002146 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2148 }
2149
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002150 private static void logv(String msg) {
2151 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2152 }
2153
Ihab Awadf9e92732013-12-05 18:02:52 -08002154 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2156 }
2157
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002158 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002160 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002161 }
2162
Sanket Padawe356d7632015-06-22 14:03:32 -07002163 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002164 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 final Phone phone = PhoneFactory.getPhone(slotIndex);
2168 if (phone == null) {
2169 return PhoneConstants.PHONE_TYPE_NONE;
2170 } else {
2171 return phone.getPhoneType();
2172 }
2173 } finally {
2174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 }
2177
2178 /**
2179 * Returns the CDMA ERI icon index to display
2180 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002181 @Override
2182 public int getCdmaEriIconIndex(String callingPackage) {
2183 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002184 }
2185
Sanket Padawe356d7632015-06-22 14:03:32 -07002186 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002187 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002189 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002190 return -1;
2191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 final Phone phone = getPhone(subId);
2196 if (phone != null) {
2197 return phone.getCdmaEriIconIndex();
2198 } else {
2199 return -1;
2200 }
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 }
2205
2206 /**
2207 * Returns the CDMA ERI icon mode,
2208 * 0 - ON
2209 * 1 - FLASHING
2210 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002211 @Override
2212 public int getCdmaEriIconMode(String callingPackage) {
2213 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002214 }
2215
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002217 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002219 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002220 return -1;
2221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222
2223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 final Phone phone = getPhone(subId);
2226 if (phone != null) {
2227 return phone.getCdmaEriIconMode();
2228 } else {
2229 return -1;
2230 }
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
2236 /**
2237 * Returns the CDMA ERI text,
2238 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002239 @Override
2240 public String getCdmaEriText(String callingPackage) {
2241 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002242 }
2243
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002247 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 return null;
2249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250
2251 final long identity = Binder.clearCallingIdentity();
2252 try {
2253 final Phone phone = getPhone(subId);
2254 if (phone != null) {
2255 return phone.getCdmaEriText();
2256 } else {
2257 return null;
2258 }
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 }
2263
2264 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002265 * Returns the CDMA MDN.
2266 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2270 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271
2272 final long identity = Binder.clearCallingIdentity();
2273 try {
2274 final Phone phone = getPhone(subId);
2275 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2276 return phone.getLine1Number();
2277 } else {
2278 return null;
2279 }
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002282 }
2283 }
2284
2285 /**
2286 * Returns the CDMA MIN.
2287 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002289 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2291 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 final Phone phone = getPhone(subId);
2296 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2297 return phone.getCdmaMin();
2298 } else {
2299 return null;
2300 }
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002303 }
2304 }
2305
2306 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 * Returns true if CDMA provisioning needs to run.
2308 */
2309 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 return mPhone.needsOtaServiceProvisioning();
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 }
2317
2318 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002319 * Sets the voice mail number of a given subId.
2320 */
2321 @Override
2322 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002323 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2328 new Pair<String, String>(alphaTag, number), new Integer(subId));
2329 return success;
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002333 }
2334
Ta-wei Yen87c49842016-05-13 21:19:52 -07002335 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002336 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2338 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2339 if (!TextUtils.equals(callingPackage, systemDialer)) {
2340 throw new SecurityException("caller must be system dialer");
2341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2346 if (phoneAccountHandle == null) {
2347 return null;
2348 }
2349 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002352 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002353 }
2354
2355 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002356 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002359 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002360 return null;
2361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002362
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 return RemoteVvmTaskManager
2366 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2367 } finally {
2368 Binder.restoreCallingIdentity(identity);
2369 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002370 }
2371
2372 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002373 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2374 VisualVoicemailSmsFilterSettings settings) {
2375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2380 mPhone.getContext(), callingPackage, subId, settings);
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002384 }
2385
2386 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002387 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002389
2390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2393 mPhone.getContext(), callingPackage, subId);
2394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002397 }
2398
2399 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002400 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2401 String callingPackage, int subId) {
2402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002403
2404 final long identity = Binder.clearCallingIdentity();
2405 try {
2406 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2407 mPhone.getContext(), callingPackage, subId);
2408 } finally {
2409 Binder.restoreCallingIdentity(identity);
2410 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002411 }
2412
2413 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002414 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002415 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416
2417 final long identity = Binder.clearCallingIdentity();
2418 try {
2419 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2420 mPhone.getContext(), subId);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002424 }
2425
2426 @Override
2427 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2428 String number, int port, String text, PendingIntent sentIntent) {
2429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002430 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002431 enforceSendSmsPermission();
2432 // Make the calls as the phone process.
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2436 if (port == 0) {
2437 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2438 sentIntent, null, false);
2439 } else {
2440 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2441 smsManager.sendDataMessageWithSelfPermissions(number, null,
2442 (short) port, data, sentIntent, null);
2443 }
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
2446 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002447 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002448 /**
fionaxu0152e512016-11-14 13:36:14 -08002449 * Sets the voice activation state of a given subId.
2450 */
2451 @Override
2452 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2454 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002455
2456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 final Phone phone = getPhone(subId);
2459 if (phone != null) {
2460 phone.setVoiceActivationState(activationState);
2461 } else {
2462 loge("setVoiceActivationState fails with invalid subId: " + subId);
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002466 }
2467 }
2468
2469 /**
2470 * Sets the data activation state of a given subId.
2471 */
2472 @Override
2473 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2475 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 final Phone phone = getPhone(subId);
2480 if (phone != null) {
2481 phone.setDataActivationState(activationState);
2482 } else {
2483 loge("setVoiceActivationState fails with invalid subId: " + subId);
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002487 }
2488 }
2489
2490 /**
2491 * Returns the voice activation state of a given subId.
2492 */
2493 @Override
2494 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002495 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496
fionaxu0152e512016-11-14 13:36:14 -08002497 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 if (phone != null) {
2501 return phone.getVoiceActivationState();
2502 } else {
2503 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002507 }
2508 }
2509
2510 /**
2511 * Returns the data activation state of a given subId.
2512 */
2513 @Override
2514 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002515 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002516
fionaxu0152e512016-11-14 13:36:14 -08002517 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 if (phone != null) {
2521 return phone.getDataActivationState();
2522 } else {
2523 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2524 }
2525 } finally {
2526 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002527 }
2528 }
2529
2530 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 * Returns the unread count of voicemails
2532 */
2533 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002534 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002535 }
2536
2537 /**
2538 * Returns the unread count of voicemails for a subId
2539 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002541 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 final Phone phone = getPhone(subId);
2545 if (phone != null) {
2546 return phone.getVoiceMessageCount();
2547 } else {
2548 return 0;
2549 }
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
2555 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002556 * returns true, if the device is in a state where both voice and data
2557 * are supported simultaneously. This can change based on location or network condition.
2558 */
2559 @Override
2560 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561 final long identity = Binder.clearCallingIdentity();
2562 try {
2563 final Phone phone = getPhone(subId);
2564 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002568 }
2569
2570 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002571 * Send the dialer code if called from the current default dialer or the caller has
2572 * carrier privilege.
2573 * @param inputCode The dialer code to send
2574 */
2575 @Override
2576 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2578 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2579 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002580 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2581 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 mPhone.sendDialerSpecialCode(inputCode);
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
2589 }
fionaxu235cc5e2017-03-06 22:25:57 -08002590 }
2591
2592 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002593 * Returns the data network type.
2594 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 *
2596 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2597 */
2598 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002599 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone phone = getPhone(getDefaultSubscription());
2603 if (phone != null) {
2604 return phone.getServiceState().getDataNetworkType();
2605 } else {
2606 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002610 }
Wink Saville36469e72014-06-11 15:17:00 -07002611 }
2612
Pengquan Menga1bb6272018-09-06 09:59:22 -07002613 @Override
2614 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002615 if (!isActiveSubscription(subId)) {
2616 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2617 }
2618
Pengquan Menga1bb6272018-09-06 09:59:22 -07002619 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2620 }
2621
Brad Ebinger35c841c2018-10-01 10:40:55 -07002622 @Override
2623 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2624 String callingPackage) throws RemoteException {
2625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2626 "addImsRegistrationCallback")) {
2627 return;
2628 }
2629 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2630 final long token = Binder.clearCallingIdentity();
2631 try {
2632 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2633 .addRegistrationCallbackForSubscription(c, subId);
2634 } finally {
2635 Binder.restoreCallingIdentity(token);
2636 }
2637 }
2638
2639 @Override
2640 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2641 String callingPackage) {
2642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2643 "removeImsRegistrationCallback")) {
2644 return;
2645 }
2646 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2647 Binder.withCleanCallingIdentity(() ->
2648 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2649 .removeRegistrationCallbackForSubscription(c, subId));
2650 }
2651
2652 @Override
2653 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2654 String callingPackage) throws RemoteException {
2655 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2656 "addMmTelCapabilityCallback")) {
2657 return;
2658 }
2659 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2660 final long token = Binder.clearCallingIdentity();
2661 try {
2662 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2663 .addCapabilitiesCallbackForSubscription(c, subId);
2664 } finally {
2665 Binder.restoreCallingIdentity(token);
2666 }
2667 }
2668
2669 @Override
2670 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2671 String callingPackage) {
2672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2673 "removeMmTelCapabilityCallback")) {
2674 return;
2675 }
2676 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2677 Binder.withCleanCallingIdentity(() ->
2678 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2679 .removeCapabilitiesCallbackForSubscription(c, subId));
2680 }
2681
2682 @Override
2683 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2685 "isCapable")) {
2686 return false;
2687 }
2688 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2689 final long token = Binder.clearCallingIdentity();
2690 try {
2691 return ImsManager.getInstance(mPhone.getContext(),
2692 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2693 } catch (ImsException e) {
2694 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2695 return false;
2696 } finally {
2697 Binder.restoreCallingIdentity(token);
2698 }
2699 }
2700
2701 @Override
2702 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2704 "isAvailable")) {
2705 return false;
2706 }
2707 final long token = Binder.clearCallingIdentity();
2708 try {
2709 Phone phone = getPhone(subId);
2710 if (phone == null) return false;
2711 return phone.isImsCapabilityAvailable(capability, regTech);
2712 } finally {
2713 Binder.restoreCallingIdentity(token);
2714 }
2715 }
2716
2717 @Override
2718 public boolean isAdvancedCallingSettingEnabled(int subId) {
2719 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2721 final long token = Binder.clearCallingIdentity();
2722 try {
2723 return ImsManager.getInstance(mPhone.getContext(),
2724 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2725 } finally {
2726 Binder.restoreCallingIdentity(token);
2727 }
2728 }
2729
2730 @Override
2731 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2733 "setAdvancedCallingSetting");
2734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2737 ImsManager.getInstance(mPhone.getContext(),
2738 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2739 } finally {
2740 Binder.restoreCallingIdentity(identity);
2741 }
2742 }
2743
2744 @Override
2745 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2747 "isVtSettingEnabled")) {
2748 return false;
2749 }
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2753 return ImsManager.getInstance(mPhone.getContext(),
2754 getSlotIndexOrException(subId)).isVtEnabledByUser();
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
2758 }
2759
2760 @Override
2761 public void setVtSetting(int subId, boolean isEnabled) {
2762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2763 "setVtSetting");
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2767 ImsManager.getInstance(mPhone.getContext(),
2768 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
2772 }
2773
2774 @Override
2775 public boolean isVoWiFiSettingEnabled(int subId) {
2776 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2780 return ImsManager.getInstance(mPhone.getContext(),
2781 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
2785 }
2786
2787 @Override
2788 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2790 "setVoWiFiSetting");
2791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2794 ImsManager.getInstance(mPhone.getContext(),
2795 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
2798 }
2799 }
2800
2801 @Override
2802 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2803 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2807 return ImsManager.getInstance(mPhone.getContext(),
2808 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
2812 }
2813
2814 @Override
2815 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2817 "setVoWiFiRoamingSetting");
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2821 ImsManager.getInstance(mPhone.getContext(),
2822 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
2825 }
2826 }
2827
2828 @Override
2829 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2831 "setVoWiFiNonPersistent");
2832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2835 ImsManager.getInstance(mPhone.getContext(),
2836 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
2839 }
2840 }
2841
2842 @Override
2843 public int getVoWiFiModeSetting(int subId) {
2844 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2848 return ImsManager.getInstance(mPhone.getContext(),
2849 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
2853 }
2854
2855 @Override
2856 public void setVoWiFiModeSetting(int subId, int mode) {
2857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2858 "setVoWiFiModeSetting");
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2862 ImsManager.getInstance(mPhone.getContext(),
2863 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2864 } finally {
2865 Binder.restoreCallingIdentity(identity);
2866 }
2867 }
2868
2869 @Override
2870 public int getVoWiFiRoamingModeSetting(int subId) {
2871 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2875 return ImsManager.getInstance(mPhone.getContext(),
2876 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
2879 }
2880 }
2881
2882 @Override
2883 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2885 "setVoWiFiRoamingModeSetting");
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2889 ImsManager.getInstance(mPhone.getContext(),
2890 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
2893 }
2894 }
2895
2896 @Override
2897 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2899 "setRttCapabilityEnabled");
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2903 ImsManager.getInstance(mPhone.getContext(),
2904 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
2908 }
2909
2910 @Override
2911 public boolean isTtyOverVolteEnabled(int subId) {
2912 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2916 return ImsManager.getInstance(mPhone.getContext(),
2917 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
2920 }
2921 }
2922
2923 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2924 int slotId = SubscriptionManager.getSlotIndex(subId);
2925 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2926 throw new IllegalArgumentException("Invalid Subscription Id.");
2927 }
2928 return slotId;
2929 }
2930
Wink Saville36469e72014-06-11 15:17:00 -07002931 /**
2932 * Returns the network type for a subId
2933 */
2934 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002935 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002937 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002938 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2939 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 final Phone phone = getPhone(subId);
2944 if (phone != null) {
2945 return phone.getServiceState().getDataNetworkType();
2946 } else {
2947 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
2953
2954 /**
2955 * Returns the data network type
2956 */
2957 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002958 public int getDataNetworkType(String callingPackage) {
2959 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002960 }
2961
2962 /**
2963 * Returns the data network type for a subId
2964 */
2965 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002966 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002968 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002969 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2970 }
2971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final Phone phone = getPhone(subId);
2975 if (phone != null) {
2976 return phone.getServiceState().getDataNetworkType();
2977 } else {
2978 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2979 }
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 }
2984
2985 /**
Wink Saville36469e72014-06-11 15:17:00 -07002986 * Returns the Voice network type for a subId
2987 */
2988 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002989 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002991 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002992 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2993 }
2994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 final Phone phone = getPhone(subId);
2998 if (phone != null) {
2999 return phone.getServiceState().getVoiceNetworkType();
3000 } else {
3001 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3002 }
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 }
3007
3008 /**
3009 * @return true if a ICC card is present
3010 */
3011 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003012 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003013 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3014 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003015 }
3016
3017 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003018 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003019 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003020 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003021 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 final Phone phone = PhoneFactory.getPhone(slotIndex);
3025 if (phone != null) {
3026 return phone.getIccCard().hasIccCard();
3027 } else {
3028 return false;
3029 }
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 }
3034
3035 /**
3036 * Return if the current radio is LTE on CDMA. This
3037 * is a tri-state return value as for a period of time
3038 * the mode may be unknown.
3039 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003040 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003042 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003044 @Override
3045 public int getLteOnCdmaMode(String callingPackage) {
3046 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003047 }
3048
Sanket Padawe356d7632015-06-22 14:03:32 -07003049 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003050 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003052 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003053 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3054 }
3055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 final Phone phone = getPhone(subId);
3059 if (phone == null) {
3060 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3061 } else {
3062 return phone.getLteOnCdmaMode();
3063 }
3064 } finally {
3065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003066 }
Wink Saville36469e72014-06-11 15:17:00 -07003067 }
3068
3069 public void setPhone(Phone phone) {
3070 mPhone = phone;
3071 }
3072
3073 /**
3074 * {@hide}
3075 * Returns Default subId, 0 in the case of single standby.
3076 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003077 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003078 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003079 }
3080
Shishir Agrawala9f32182016-04-12 12:00:16 -07003081 private int getSlotForDefaultSubscription() {
3082 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3083 }
3084
Wink Savilleb564aae2014-10-23 10:18:09 -07003085 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003086 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003088
Pengquan Menge92a50d2018-09-21 15:54:48 -07003089 private boolean isActiveSubscription(int subId) {
3090 return mSubscriptionController.isActiveSubId(subId);
3091 }
3092
Ihab Awadf2177b72013-11-25 13:33:23 -08003093 /**
3094 * @see android.telephony.TelephonyManager.WifiCallingChoices
3095 */
3096 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3100 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3101 getWhenToMakeWifiCallsDefaultPreference());
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003105 }
3106
3107 /**
3108 * @see android.telephony.TelephonyManager.WifiCallingChoices
3109 */
3110 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3114 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3115 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003119 }
3120
Sailesh Nepald1e68152013-12-12 19:08:02 -08003121 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003122 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003123 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003124 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003125
Shishir Agrawal566b7612013-10-28 14:41:00 -07003126 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003127 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3128 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3130 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 if (TextUtils.equals(ISDR_AID, aid)) {
3136 // Only allows LPA to open logical channel to ISD-R.
3137 ComponentInfo bestComponent =
3138 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3139 if (bestComponent == null
3140 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3141 loge("The calling package is not allowed to access ISD-R.");
3142 throw new SecurityException(
3143 "The calling package is not allowed to access ISD-R.");
3144 }
Derek Tan740e1672017-06-27 14:56:27 -07003145 }
Derek Tan740e1672017-06-27 14:56:27 -07003146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 if (DBG) {
3148 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3149 }
3150 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3151 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3152 if (DBG) log("iccOpenLogicalChannel: " + response);
3153 return response;
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003157 }
3158
3159 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003160 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3162 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3167 if (channel < 0) {
3168 return false;
3169 }
3170 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3171 if (DBG) log("iccCloseLogicalChannel: " + success);
3172 return success;
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003175 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003176 }
3177
3178 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003179 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003180 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3182 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 if (DBG) {
3187 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3188 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3189 + p3 + " data=" + data);
3190 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 if (channel < 0) {
3193 return "";
3194 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3197 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3198 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 // Append the returned status code to the end of the response payload.
3201 String s = Integer.toHexString(
3202 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3203 if (response.payload != null) {
3204 s = IccUtils.bytesToHexString(response.payload) + s;
3205 }
3206 return s;
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003209 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003210 }
Jake Hambye994d462014-02-03 13:10:13 -08003211
Evan Charltonc66da362014-05-16 14:06:40 -07003212 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003213 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3214 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3216 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3222 && TextUtils.equals(ISDR_AID, data)) {
3223 // Only allows LPA to select ISD-R.
3224 ComponentInfo bestComponent =
3225 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3226 if (bestComponent == null
3227 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3228 loge("The calling package is not allowed to select ISD-R.");
3229 throw new SecurityException(
3230 "The calling package is not allowed to select ISD-R.");
3231 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003232 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 if (DBG) {
3235 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3236 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3237 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3240 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3241 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243 // Append the returned status code to the end of the response payload.
3244 String s = Integer.toHexString(
3245 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3246 if (response.payload != null) {
3247 s = IccUtils.bytesToHexString(response.payload) + s;
3248 }
3249 return s;
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003252 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003253 }
3254
3255 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003256 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003257 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3259 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 if (DBG) {
3264 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3265 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3266 }
3267
3268 IccIoResult response =
3269 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3270 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3271 subId);
3272
3273 if (DBG) {
3274 log("Exchange SIM_IO [R]" + response);
3275 }
3276
3277 byte[] result = null;
3278 int length = 2;
3279 if (response.payload != null) {
3280 length = 2 + response.payload.length;
3281 result = new byte[length];
3282 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3283 } else {
3284 result = new byte[length];
3285 }
3286
3287 result[length - 1] = (byte) response.sw2;
3288 result[length - 2] = (byte) response.sw1;
3289 return result;
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003292 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003293 }
3294
Nathan Haroldb3014052017-01-25 15:57:32 -08003295 /**
3296 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3297 * on a particular subscription
3298 */
sqianb6e41952018-03-12 14:54:01 -07003299 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3301 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3302 return null;
3303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304
3305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 if (appType != TelephonyManager.APPTYPE_USIM
3308 && appType != TelephonyManager.APPTYPE_SIM) {
3309 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3310 return null;
3311 }
3312 Object response = sendRequest(
3313 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3314 if (response instanceof String[]) {
3315 return (String[]) response;
3316 }
3317 // Response is an Exception of some kind,
3318 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003319 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320 } finally {
3321 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003322 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003323 }
3324
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003326 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3328 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3333 if (response.payload == null) {
3334 return "";
3335 }
Evan Charltonc66da362014-05-16 14:06:40 -07003336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 // Append the returned status code to the end of the response payload.
3338 String s = Integer.toHexString(
3339 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3340 s = IccUtils.bytesToHexString(response.payload) + s;
3341 return s;
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
Evan Charltonc66da362014-05-16 14:06:40 -07003345 }
3346
Jake Hambye994d462014-02-03 13:10:13 -08003347 /**
3348 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3349 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3350 *
3351 * @param itemID the ID of the item to read
3352 * @return the NV item as a String, or null on error.
3353 */
3354 @Override
3355 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003356 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3358 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003363 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3365 return value;
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
Jake Hambye994d462014-02-03 13:10:13 -08003369 }
3370
3371 /**
3372 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3373 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3374 *
3375 * @param itemID the ID of the item to read
3376 * @param itemValue the value to write, as a String
3377 * @return true on success; false on any failure
3378 */
3379 @Override
3380 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3383 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003384
3385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3388 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003389 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3391 return success;
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
Jake Hambye994d462014-02-03 13:10:13 -08003395 }
3396
3397 /**
3398 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3399 * Used for device configuration by some CDMA operators.
3400 *
3401 * @param preferredRoamingList byte array containing the new PRL
3402 * @return true on success; false on any failure
3403 */
3404 @Override
3405 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3407 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3412 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3413 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3414 return success;
3415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
Jake Hambye994d462014-02-03 13:10:13 -08003418 }
3419
3420 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003421 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003422 * Used for device configuration by some CDMA operators.
3423 *
chen xu6dac5ab2018-10-26 17:39:23 -07003424 * @param slotIndex - device slot.
3425 *
Jake Hambye994d462014-02-03 13:10:13 -08003426 * @return true on success; false on any failure
3427 */
3428 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003429 public boolean resetModemConfig(int slotIndex) {
3430 Phone phone = PhoneFactory.getPhone(slotIndex);
3431 if (phone != null) {
3432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3433 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
chen xu6dac5ab2018-10-26 17:39:23 -07003435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3438 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3439 return success;
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 }
chen xu6dac5ab2018-10-26 17:39:23 -07003444 return false;
3445 }
3446
3447 /**
3448 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3449 *
3450 * @param slotIndex - device slot.
3451 *
3452 * @return true on success; false on any failure
3453 */
3454 @Override
3455 public boolean rebootModem(int slotIndex) {
3456 Phone phone = PhoneFactory.getPhone(slotIndex);
3457 if (phone != null) {
3458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3459 mApp, phone.getSubId(), "rebootModem");
3460
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3464 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3465 return success;
3466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
3469 }
3470 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003471 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003472
Svet Ganovb320e182015-04-16 12:30:10 -07003473 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003475 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003476 return new String[0];
3477 }
3478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 return mPhone.getPcscfAddress(apnType);
3482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
Wink Saville36469e72014-06-11 15:17:00 -07003485 }
3486
Brad Ebinger51f743a2017-01-23 13:50:20 -08003487 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003488 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3489 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003490 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003491 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493
3494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 PhoneFactory.getImsResolver().enableIms(slotId);
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003500 }
3501
3502 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003503 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3504 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003505 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003506 public void disableIms(int slotId) {
3507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508
3509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 PhoneFactory.getImsResolver().disableIms(slotId);
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003515 }
3516
3517 /**
3518 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3519 * feature or {@link null} if the service is not available. If the feature is available, the
3520 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3521 */
3522 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003523 IImsServiceFeatureCallback callback) {
3524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525
3526 final long identity = Binder.clearCallingIdentity();
3527 try {
3528 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003532 }
3533
3534 /**
3535 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3536 * feature during emergency calling or {@link null} if the service is not available. If the
3537 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3538 * listener for feature updates.
3539 */
3540 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
3548 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003549 }
3550
Brad Ebinger5f64b052017-12-14 14:26:15 -08003551 /**
3552 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3553 * specified.
3554 */
3555 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003564 }
3565
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003566 /**
3567 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3568 * specified.
3569 */
3570 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003579 }
3580
Brad Ebinger884c07b2018-02-15 16:17:40 -08003581 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003582 * Sets the ImsService Package Name that Telephony will bind to.
3583 *
3584 * @param slotId the slot ID that the ImsService should bind for.
3585 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3586 * ImsService is the device default ImsService.
3587 * @param packageName The package name of the application that contains the ImsService to bind
3588 * to.
3589 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3590 * @hide
3591 */
3592 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003593 int[] subIds = SubscriptionManager.getSubId(slotId);
3594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3595 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3596 "setImsService");
3597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3601 isCarrierImsService, packageName);
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
3604 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003605 }
3606
3607 /**
3608 * Return the ImsService configuration.
3609 *
3610 * @param slotId The slot that the ImsService is associated with.
3611 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3612 * the device default.
3613 * @return the package name of the ImsService configuration.
3614 */
3615 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003616 int[] subIds = SubscriptionManager.getSubId(slotId);
3617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3618 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3619 "getImsService");
3620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3624 isCarrierImsService);
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003628 }
3629
Wink Saville36469e72014-06-11 15:17:00 -07003630 public void setImsRegistrationState(boolean registered) {
3631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 mPhone.setImsRegistrationState(registered);
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
Wink Saville36469e72014-06-11 15:17:00 -07003639 }
3640
3641 /**
Stuart Scott54788802015-03-30 13:18:01 -07003642 * Set the network selection mode to automatic.
3643 *
3644 */
3645 @Override
3646 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3648 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
Pengquan Menge92a50d2018-09-21 15:54:48 -07003650 if (!isActiveSubscription(subId)) {
3651 return;
3652 }
3653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3657 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
Stuart Scott54788802015-03-30 13:18:01 -07003661 }
3662
Pengquan Mengea84e042018-09-20 14:57:26 -07003663 /**
3664 * Ask the radio to connect to the input network and change selection mode to manual.
3665 *
3666 * @param subId the id of the subscription.
3667 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3668 * the operator to attach to.
3669 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3670 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3671 * normal network selection next time.
3672 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003673 */
3674 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003675 public boolean setNetworkSelectionModeManual(
3676 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3678 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003679
3680 if (!isActiveSubscription(subId)) {
3681 return false;
3682 }
3683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684 final long identity = Binder.clearCallingIdentity();
3685 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003686 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003688 if (DBG) {
3689 log("setNetworkSelectionModeManual: subId: " + subId
3690 + " operator: " + operatorInfo);
3691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003692 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003696 }
3697
3698 /**
3699 * Scans for available networks.
3700 */
3701 @Override
3702 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3704 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705
Pengquan Menga1bb6272018-09-06 09:59:22 -07003706 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 try {
3708 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003709 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003714 }
3715
3716 /**
yinxub1bed742017-04-17 11:45:04 -07003717 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003718 *
yinxub1bed742017-04-17 11:45:04 -07003719 * @param subId id of the subscription
3720 * @param request contains the radio access networks with bands/channels to scan
3721 * @param messenger callback messenger for scan results or errors
3722 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003723 * @return the id of the requested scan which can be used to stop the scan.
3724 */
3725 @Override
3726 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3727 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3729 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730
3731 final long identity = Binder.clearCallingIdentity();
3732 try {
3733 return mNetworkScanRequestTracker.startNetworkScan(
3734 request, messenger, binder, getPhone(subId));
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
3737 }
yinxu504e1392017-04-12 16:03:22 -07003738 }
3739
3740 /**
3741 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003742 *
3743 * @param subId id of the subscription
3744 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003745 */
3746 @Override
3747 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3749 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
yinxu504e1392017-04-12 16:03:22 -07003757 }
3758
3759 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003760 * Get the calculated preferred network type.
3761 * Used for debugging incorrect network type.
3762 *
3763 * @return the preferred network type, defined in RILConstants.java.
3764 */
3765 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003766 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003768 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003769 return RILConstants.PREFERRED_NETWORK_MODE;
3770 }
3771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 // FIXME: need to get SubId from somewhere.
3775 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
Junda Liu84d15a22014-07-02 11:21:04 -07003779 }
3780
3781 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003782 * Get the preferred network type.
3783 * Used for device configuration by some CDMA operators.
3784 *
3785 * @return the preferred network type, defined in RILConstants.java.
3786 */
3787 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003788 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 if (DBG) log("getPreferredNetworkType");
3795 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3796 int networkType = (result != null ? result[0] : -1);
3797 if (DBG) log("getPreferredNetworkType: " + networkType);
3798 return networkType;
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003802 }
3803
3804 /**
3805 * Set the preferred network type.
3806 * Used for device configuration by some CDMA operators.
3807 *
3808 * @param networkType the preferred network type, defined in RILConstants.java.
3809 * @return true on success; false on any failure.
3810 */
3811 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003812 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3814 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815
3816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3819 Boolean success = (Boolean) sendRequest(
3820 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3821 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3822 if (success) {
3823 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3824 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3825 }
3826 return success;
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003829 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003830 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003831
3832 /**
Junda Liu475951f2014-11-07 16:45:03 -08003833 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07003834 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003835 * tethering.
3836 *
3837 * @return 0: Not required. 1: required. 2: Not set.
3838 * @hide
3839 */
3840 @Override
3841 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843
3844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3847 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07003848 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3850 dunRequired = 1;
3851 }
3852 return dunRequired;
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003855 }
Junda Liu475951f2014-11-07 16:45:03 -08003856 }
3857
3858 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003859 * Set mobile data enabled
3860 * Used by the user through settings etc to turn on/off mobile data
3861 *
3862 * @param enable {@code true} turn turn data on, else {@code false}
3863 */
3864 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003865 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 int phoneId = mSubscriptionController.getPhoneId(subId);
3872 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3873 Phone phone = PhoneFactory.getPhone(phoneId);
3874 if (phone != null) {
3875 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3876 phone.setUserDataEnabled(enable);
3877 } else {
3878 loge("setUserDataEnabled: no phone for subId=" + subId);
3879 }
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003882 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003883 }
3884
3885 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003886 * Get the user enabled state of Mobile Data.
3887 *
3888 * TODO: remove and use isUserDataEnabled.
3889 * This can't be removed now because some vendor codes
3890 * calls through ITelephony directly while they should
3891 * use TelephonyManager.
3892 *
3893 * @return true on enabled
3894 */
3895 @Override
3896 public boolean getDataEnabled(int subId) {
3897 return isUserDataEnabled(subId);
3898 }
3899
3900 /**
3901 * Get whether mobile data is enabled per user setting.
3902 *
3903 * There are other factors deciding whether mobile data is actually enabled, but they are
3904 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003905 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003906 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003907 *
3908 * @return {@code true} if data is enabled else {@code false}
3909 */
3910 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003911 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003912 try {
3913 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3914 null);
3915 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3917 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 int phoneId = mSubscriptionController.getPhoneId(subId);
3923 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3924 Phone phone = PhoneFactory.getPhone(phoneId);
3925 if (phone != null) {
3926 boolean retVal = phone.isUserDataEnabled();
3927 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3928 return retVal;
3929 } else {
3930 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3931 return false;
3932 }
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003935 }
3936 }
3937
3938 /**
3939 * Get whether mobile data is enabled.
3940 *
3941 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3942 * whether mobile data is actually enabled.
3943 *
3944 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3945 *
3946 * @return {@code true} if data is enabled else {@code false}
3947 */
3948 @Override
3949 public boolean isDataEnabled(int subId) {
3950 try {
3951 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3952 null);
3953 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3955 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 int phoneId = mSubscriptionController.getPhoneId(subId);
3961 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3962 Phone phone = PhoneFactory.getPhone(phoneId);
3963 if (phone != null) {
3964 boolean retVal = phone.isDataEnabled();
3965 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3966 return retVal;
3967 } else {
3968 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3969 return false;
3970 }
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003973 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003974 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003975
3976 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003977 public int getCarrierPrivilegeStatus(int subId) {
3978 final Phone phone = getPhone(subId);
3979 if (phone == null) {
3980 loge("getCarrierPrivilegeStatus: Invalid subId");
3981 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3982 }
3983 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003984 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003985 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003986 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3987 }
3988 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003989 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003990 }
Junda Liu29340342014-07-10 15:23:27 -07003991
3992 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003993 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3994 final Phone phone = getPhone(subId);
3995 if (phone == null) {
3996 loge("getCarrierPrivilegeStatus: Invalid subId");
3997 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3998 }
3999 UiccProfile profile =
4000 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4001 if (profile == null) {
4002 loge("getCarrierPrivilegeStatus: No UICC");
4003 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4004 }
4005 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4006 }
4007
4008 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004009 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004010 if (TextUtils.isEmpty(pkgName))
4011 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004012 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004013 if (card == null) {
4014 loge("checkCarrierPrivilegesForPackage: No UICC");
4015 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4016 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004017 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4018 }
4019
4020 @Override
4021 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004022 if (TextUtils.isEmpty(pkgName))
4023 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004024 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4025 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4026 UiccCard card = UiccController.getInstance().getUiccCard(i);
4027 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004028 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004029 continue;
4030 }
4031
4032 result = card.getCarrierPrivilegeStatus(
4033 mPhone.getContext().getPackageManager(), pkgName);
4034 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4035 break;
4036 }
4037 }
4038
4039 return result;
Junda Liu29340342014-07-10 15:23:27 -07004040 }
Derek Tan89e89d42014-07-08 17:00:10 -07004041
4042 @Override
Junda Liue64de782015-04-16 17:19:16 -07004043 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4044 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4045 loge("phoneId " + phoneId + " is not valid.");
4046 return null;
4047 }
4048 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004049 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004050 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004051 return null ;
4052 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004053 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004054 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004055 }
4056
Amith Yamasani6e118872016-02-19 12:53:51 -08004057 @Override
4058 public List<String> getPackagesWithCarrierPrivileges() {
4059 PackageManager pm = mPhone.getContext().getPackageManager();
4060 List<String> privilegedPackages = new ArrayList<>();
4061 List<PackageInfo> packages = null;
4062 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4063 UiccCard card = UiccController.getInstance().getUiccCard(i);
4064 if (card == null) {
4065 // No UICC in that slot.
4066 continue;
4067 }
4068 if (card.hasCarrierPrivilegeRules()) {
4069 if (packages == null) {
4070 // Only check packages in user 0 for now
4071 packages = pm.getInstalledPackagesAsUser(
4072 PackageManager.MATCH_DISABLED_COMPONENTS
4073 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4074 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4075 }
4076 for (int p = packages.size() - 1; p >= 0; p--) {
4077 PackageInfo pkgInfo = packages.get(p);
4078 if (pkgInfo != null && pkgInfo.packageName != null
4079 && card.getCarrierPrivilegeStatus(pkgInfo)
4080 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4081 privilegedPackages.add(pkgInfo.packageName);
4082 }
4083 }
4084 }
4085 }
4086 return privilegedPackages;
4087 }
4088
Wink Savilleb564aae2014-10-23 10:18:09 -07004089 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004090 final Phone phone = getPhone(subId);
4091 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004092 if (card == null) {
4093 loge("getIccId: No UICC");
4094 return null;
4095 }
4096 String iccId = card.getIccId();
4097 if (TextUtils.isEmpty(iccId)) {
4098 loge("getIccId: ICC ID is null or empty.");
4099 return null;
4100 }
4101 return iccId;
4102 }
4103
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004104 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004105 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4106 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004107 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4108 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 final String iccId = getIccId(subId);
4113 final Phone phone = getPhone(subId);
4114 if (phone == null) {
4115 return false;
4116 }
4117 final String subscriberId = phone.getSubscriberId();
4118
4119 if (DBG_MERGE) {
4120 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4121 + subscriberId + " to " + number);
4122 }
4123
4124 if (TextUtils.isEmpty(iccId)) {
4125 return false;
4126 }
4127
4128 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4129
4130 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4131 if (alphaTag == null) {
4132 editor.remove(alphaTagPrefKey);
4133 } else {
4134 editor.putString(alphaTagPrefKey, alphaTag);
4135 }
4136
4137 // Record both the line number and IMSI for this ICCID, since we need to
4138 // track all merged IMSIs based on line number
4139 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4140 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4141 if (number == null) {
4142 editor.remove(numberPrefKey);
4143 editor.remove(subscriberPrefKey);
4144 } else {
4145 editor.putString(numberPrefKey, number);
4146 editor.putString(subscriberPrefKey, subscriberId);
4147 }
4148
4149 editor.commit();
4150 return true;
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004153 }
Derek Tan7226c842014-07-02 17:42:23 -07004154 }
4155
4156 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004157 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004158 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004160 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004161 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004162 return null;
4163 }
Derek Tan97ebb422014-09-05 16:55:38 -07004164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 final long identity = Binder.clearCallingIdentity();
4166 try {
4167 String iccId = getIccId(subId);
4168 if (iccId != null) {
4169 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4170 if (DBG_MERGE) {
4171 log("getLine1NumberForDisplay returning "
4172 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4173 }
4174 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4177 return null;
4178 } finally {
4179 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004180 }
Derek Tan7226c842014-07-02 17:42:23 -07004181 }
4182
4183 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004184 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004186 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004187 return null;
4188 }
Derek Tan97ebb422014-09-05 16:55:38 -07004189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 String iccId = getIccId(subId);
4193 if (iccId != null) {
4194 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4195 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4196 }
4197 return null;
4198 } finally {
4199 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004200 }
Derek Tan7226c842014-07-02 17:42:23 -07004201 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004202
4203 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004204 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004205 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4206 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004208 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4209 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004210 return null;
4211 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004212
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004213 final long identity = Binder.clearCallingIdentity();
4214 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final Context context = mPhone.getContext();
4216 final TelephonyManager tele = TelephonyManager.from(context);
4217 final SubscriptionManager sub = SubscriptionManager.from(context);
4218
4219 // Figure out what subscribers are currently active
4220 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4221 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4222 // the process, where TelephonyManager was instantiated.
4223 // Otherwise AppOps check will fail.
4224
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004225 final int[] subIds = sub.getActiveSubscriptionIdList();
4226 for (int subId : subIds) {
4227 activeSubscriberIds.add(tele.getSubscriberId(subId));
4228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229
4230 // First pass, find a number override for an active subscriber
4231 String mergeNumber = null;
4232 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4233 for (String key : prefs.keySet()) {
4234 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4235 final String subscriberId = (String) prefs.get(key);
4236 if (activeSubscriberIds.contains(subscriberId)) {
4237 final String iccId = key.substring(
4238 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4239 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4240 mergeNumber = (String) prefs.get(numberKey);
4241 if (DBG_MERGE) {
4242 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4243 + " for active subscriber " + subscriberId);
4244 }
4245 if (!TextUtils.isEmpty(mergeNumber)) {
4246 break;
4247 }
4248 }
4249 }
4250 }
4251
4252 // Shortcut when no active merged subscribers
4253 if (TextUtils.isEmpty(mergeNumber)) {
4254 return null;
4255 }
4256
4257 // Second pass, find all subscribers under that line override
4258 final ArraySet<String> result = new ArraySet<>();
4259 for (String key : prefs.keySet()) {
4260 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4261 final String number = (String) prefs.get(key);
4262 if (mergeNumber.equals(number)) {
4263 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4264 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4265 final String subscriberId = (String) prefs.get(subscriberKey);
4266 if (!TextUtils.isEmpty(subscriberId)) {
4267 result.add(subscriberId);
4268 }
4269 }
4270 }
4271 }
4272
4273 final String[] resultArray = result.toArray(new String[result.size()]);
4274 Arrays.sort(resultArray);
4275 if (DBG_MERGE) {
4276 Slog.d(LOG_TAG,
4277 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4278 }
4279 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004282 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004283 }
4284
4285 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004286 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004287 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4288 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289
4290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 final Phone phone = getPhone(subId);
4293 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004297 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004298
4299 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004300 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004301 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4302 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004303 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304
4305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 final Phone phone = getPhone(subId);
4308 if (phone == null) {
4309 return false;
4310 }
4311 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4312 cdmaNonRoamingList);
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004315 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004316 }
4317
4318 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004319 @Deprecated
4320 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4321 enforceModifyPermission();
4322
4323 int returnValue = 0;
4324 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004325 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004326 if(result.exception == null) {
4327 if (result.result != null) {
4328 byte[] responseData = (byte[])(result.result);
4329 if(responseData.length > oemResp.length) {
4330 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4331 responseData.length + "bytes. Buffer Size is " +
4332 oemResp.length + "bytes.");
4333 }
4334 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4335 returnValue = responseData.length;
4336 }
4337 } else {
4338 CommandException ex = (CommandException) result.exception;
4339 returnValue = ex.getCommandError().ordinal();
4340 if(returnValue > 0) returnValue *= -1;
4341 }
4342 } catch (RuntimeException e) {
4343 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4344 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4345 if(returnValue > 0) returnValue *= -1;
4346 }
4347
4348 return returnValue;
4349 }
4350
4351 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004352 public void setRadioCapability(RadioAccessFamily[] rafs) {
4353 try {
4354 ProxyController.getInstance().setRadioCapability(rafs);
4355 } catch (RuntimeException e) {
4356 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4357 }
4358 }
4359
4360 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004361 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004362 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004363 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004364 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004365 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 final long identity = Binder.clearCallingIdentity();
4368 try {
chen xub97461a2018-10-26 14:17:57 -07004369 TelephonyPermissions
4370 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4371 mApp, phone.getSubId(), "getRadioAccessFamily");
4372 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
chen xub97461a2018-10-26 14:17:57 -07004376 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004377 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004378
4379 @Override
4380 public void enableVideoCalling(boolean enable) {
4381 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382
4383 final long identity = Binder.clearCallingIdentity();
4384 try {
4385 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004389 }
4390
4391 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004392 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4394 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4395 return false;
4396 }
Svet Ganovb320e182015-04-16 12:30:10 -07004397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398 final long identity = Binder.clearCallingIdentity();
4399 try {
4400 // Check the user preference and the system-level IMS setting. Even if the user has
4401 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4402 // In the long run, we may instead need to check if there exists a connection service
4403 // which can support video calling.
4404 ImsManager imsManager =
4405 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4406 return imsManager.isVtEnabledByPlatform()
4407 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4408 && imsManager.isVtEnabledByUser();
4409 } finally {
4410 Binder.restoreCallingIdentity(identity);
4411 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004412 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004413
Andrew Leea1239f22015-03-02 17:44:07 -08004414 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4417 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4418 return false;
4419 }
4420
4421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 CarrierConfigManager configManager =
4424 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4425 return configManager.getConfigForSubId(mPhone.getSubId())
4426 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
Andrew Leea1239f22015-03-02 17:44:07 -08004430 }
4431
4432 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 public boolean isWorldPhone(int subId, String callingPackage) {
4434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4435 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4436 return false;
4437 }
4438
4439 final long identity = Binder.clearCallingIdentity();
4440 try {
4441 CarrierConfigManager configManager =
4442 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4443 return configManager.getConfigForSubId(mPhone.getSubId())
4444 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4445 } finally {
4446 Binder.restoreCallingIdentity(identity);
4447 }
Andrew Leea1239f22015-03-02 17:44:07 -08004448 }
4449
Andrew Lee9431b832015-03-09 18:46:45 -07004450 @Override
4451 public boolean isTtyModeSupported() {
4452 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004453 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004454 }
4455
4456 @Override
4457 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
Andrew Lee9431b832015-03-09 18:46:45 -07004464 }
4465
Hall Liuf6668912018-10-31 17:05:23 -07004466 /**
4467 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4468 * support for the feature and device firmware support.
4469 *
4470 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4471 */
4472 @Override
4473 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4477 mPhone.getSubId()).getBoolean(
4478 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4479 boolean isDeviceSupported =
4480 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4481 return isCarrierSupported && isDeviceSupported;
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
Hall Liu98187582018-01-22 19:15:32 -08004485 }
4486
Hall Liuf6668912018-10-31 17:05:23 -07004487 /**
4488 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4489 * both also support RTT.
4490 */
4491 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 final long identity = Binder.clearCallingIdentity();
4493 try {
Hall Liuf6668912018-10-31 17:05:23 -07004494 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 mPhone.getContext().getContentResolver(),
4496 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004500 }
4501
Sanket Padawe7310cc72015-01-14 09:53:20 -08004502 /**
4503 * Returns the unique device ID of phone, for example, the IMEI for
4504 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4505 *
4506 * <p>Requires Permission:
4507 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4508 */
4509 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004510 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004511 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004512 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004513 return null;
4514 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004515 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004516 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4517 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004518 return null;
4519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
4523 return phone.getDeviceId();
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004527 }
4528
Ping Sunc67b7c22016-03-02 19:16:45 +08004529 /**
4530 * {@hide}
4531 * Returns the IMS Registration Status on a particular subid
4532 *
4533 * @param subId
4534 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004535 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004536 Phone phone = getPhone(subId);
4537 if (phone != null) {
4538 return phone.isImsRegistered();
4539 } else {
4540 return false;
4541 }
4542 }
4543
Santos Cordon7a1885b2015-02-03 11:15:19 -08004544 @Override
4545 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546 final long identity = Binder.clearCallingIdentity();
4547 try {
4548 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004552 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004553
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004554 /**
4555 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004556 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004557 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 final long identity = Binder.clearCallingIdentity();
4559 try {
4560 Phone phone = getPhone(subId);
4561 if (phone != null) {
4562 return phone.isWifiCallingEnabled();
4563 } else {
4564 return false;
4565 }
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004568 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004569 }
4570
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004571 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004572 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004573 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004574 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 Phone phone = getPhone(subId);
4578 if (phone != null) {
4579 return phone.isVideoEnabled();
4580 } else {
4581 return false;
4582 }
4583 } finally {
4584 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004585 }
4586 }
4587
4588 /**
4589 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4590 * defined in {@link ImsRegistrationImplBase}.
4591 */
4592 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 Phone phone = getPhone(subId);
4596 if (phone != null) {
4597 return phone.getImsRegistrationTech();
4598 } else {
4599 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4600 }
4601 } finally {
4602 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004603 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004604 }
4605
Stuart Scott8eef64f2015-04-08 15:13:54 -07004606 @Override
4607 public void factoryReset(int subId) {
4608 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004609 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4610 return;
4611 }
4612
Svet Ganovcc087f82015-05-12 20:35:54 -07004613 final long identity = Binder.clearCallingIdentity();
4614 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004615 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4616 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004617 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004618 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004619 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4620 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004621 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004622 }
4623 } finally {
4624 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004625 }
4626 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004627
4628 @Override
4629 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 // We query all subscriptions instead of just the active ones, because
4633 // this might be called early on in the provisioning flow when the
4634 // subscriptions potentially aren't active yet.
4635 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4636 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004637 return null;
4638 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 // This function may be called very early, say, from the setup wizard, at
4641 // which point we won't have a default subscription set. If that's the case
4642 // we just choose the first, which will be valid in "most cases".
4643 final int defaultSubId = getDefaultSubscription();
4644 SubscriptionInfo info = null;
4645 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4646 info = slist.get(0);
4647 } else {
4648 for (SubscriptionInfo item : slist) {
4649 if (item.getSubscriptionId() == defaultSubId) {
4650 info = item;
4651 break;
4652 }
4653 }
4654
4655 if (info == null) {
4656 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004657 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004658 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 // Try and fetch the locale from the carrier properties or from the SIM language
4661 // preferences (EF-PL and EF-LI)...
4662 final int mcc = info.getMcc();
4663 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4664 String simLanguage = null;
4665 if (defaultPhone != null) {
4666 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4667 if (localeFromDefaultSim != null) {
4668 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4669 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4670 return localeFromDefaultSim.toLanguageTag();
4671 } else {
4672 simLanguage = localeFromDefaultSim.getLanguage();
4673 }
4674 }
4675 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677 // The SIM language preferences only store a language (e.g. fr = French), not an
4678 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4679 // the SIM and carrier preferences does not include a country we add the country
4680 // determined from the SIM MCC to provide an exact locale.
4681 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4682 simLanguage);
4683 if (mccLocale != null) {
4684 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4685 return mccLocale.toLanguageTag();
4686 }
4687
4688 if (DBG) log("No locale found - returning null");
4689 return null;
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004693 }
4694
4695 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696 return mSubscriptionController.getAllSubInfoList(
4697 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004698 }
4699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700 /**
4701 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4702 */
4703 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4704 return mSubscriptionController.getActiveSubscriptionInfoList(
4705 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004706 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004707
Chenjie Yu1ba97252018-01-11 18:16:20 -08004708 private final ModemActivityInfo mLastModemActivityInfo =
4709 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4710
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004711 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004712 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4713 * representing the state of the modem.
4714 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004715 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4716 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004717 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004718 */
4719 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004720 public void requestModemActivityInfo(ResultReceiver result) {
4721 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004722 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 ModemActivityInfo ret = null;
4727 synchronized (mLastModemActivityInfo) {
4728 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4729 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004730 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004731 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4733 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4734 mergedTxTimeMs[i] =
4735 info.getTxTimeMillis()[i]
4736 + mLastModemActivityInfo.getTxTimeMillis()[i];
4737 }
4738 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4739 mLastModemActivityInfo.setSleepTimeMillis(
4740 info.getSleepTimeMillis()
4741 + mLastModemActivityInfo.getSleepTimeMillis());
4742 mLastModemActivityInfo.setIdleTimeMillis(
4743 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4744 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4745 mLastModemActivityInfo.setRxTimeMillis(
4746 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4747 mLastModemActivityInfo.setEnergyUsed(
4748 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4751 mLastModemActivityInfo.getSleepTimeMillis(),
4752 mLastModemActivityInfo.getIdleTimeMillis(),
4753 mLastModemActivityInfo.getTxTimeMillis(),
4754 mLastModemActivityInfo.getRxTimeMillis(),
4755 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 Bundle bundle = new Bundle();
4758 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4759 result.send(0, bundle);
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004762 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004763 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004764
Siddharth Rayb8114062018-06-17 15:02:38 -07004765 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4766 // less than total activity duration.
4767 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4768 if (info == null) {
4769 return false;
4770 }
4771 int activityDurationMs =
4772 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4773 int totalTxTimeMs = 0;
4774 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4775 totalTxTimeMs += info.getTxTimeMillis()[i];
4776 }
4777 return (info.isValid()
4778 && (info.getSleepTimeMillis() <= activityDurationMs)
4779 && (info.getIdleTimeMillis() <= activityDurationMs)
4780 && (info.getRxTimeMillis() <= activityDurationMs)
4781 && (totalTxTimeMs <= activityDurationMs));
4782 }
4783
Jack Yu85bd38a2015-11-09 11:34:32 -08004784 /**
4785 * {@hide}
4786 * Returns the service state information on specified subscription.
4787 */
4788 @Override
4789 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004791 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004792 return null;
4793 }
4794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 final Phone phone = getPhone(subId);
4798 if (phone == null) {
4799 return null;
4800 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 return phone.getServiceState();
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004806 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004807
4808 /**
4809 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4810 *
4811 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4812 * voicemail ringtone.
4813 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4814 * PhoneAccount.
4815 */
4816 @Override
4817 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4821 if (phone == null) {
4822 phone = mPhone;
4823 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4826 } finally {
4827 Binder.restoreCallingIdentity(identity);
4828 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004829 }
4830
4831 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004832 * Sets the per-account voicemail ringtone.
4833 *
4834 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4835 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4836 *
4837 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4838 * voicemail ringtone.
4839 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4840 * PhoneAccount.
4841 */
4842 @Override
4843 public void setVoicemailRingtoneUri(String callingPackage,
4844 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4845 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4846 if (!TextUtils.equals(callingPackage,
4847 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4849 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4850 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004851 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852
4853 final long identity = Binder.clearCallingIdentity();
4854 try {
4855 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4856 if (phone == null) {
4857 phone = mPhone;
4858 }
4859 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4860 } finally {
4861 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004862 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004863 }
4864
4865 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004866 * Returns whether vibration is set for voicemail notification in Phone settings.
4867 *
4868 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4869 * voicemail vibration setting.
4870 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4871 */
4872 @Override
4873 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4877 if (phone == null) {
4878 phone = mPhone;
4879 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004885 }
4886
Youhan Wange64578a2016-05-02 15:32:42 -07004887 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004888 * Sets the per-account voicemail vibration.
4889 *
4890 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4891 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4892 *
4893 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4894 * voicemail vibration setting.
4895 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4896 * specific PhoneAccount.
4897 */
4898 @Override
4899 public void setVoicemailVibrationEnabled(String callingPackage,
4900 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4901 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4902 if (!TextUtils.equals(callingPackage,
4903 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4905 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4906 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004907 }
4908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 final long identity = Binder.clearCallingIdentity();
4910 try {
4911 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4912 if (phone == null) {
4913 phone = mPhone;
4914 }
4915 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4916 } finally {
4917 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004918 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004919 }
4920
4921 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004922 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4923 *
4924 * @throws SecurityException if the caller does not have the required permission
4925 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004926 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004927 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004928 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004929 }
4930
4931 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004932 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4933 * permission.
4934 *
4935 * @throws SecurityException if the caller does not have the required permission
4936 */
4937 private void enforceSendSmsPermission() {
4938 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4939 }
4940
4941 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004942 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004943 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004944 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004945 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004946 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 final long identity = Binder.clearCallingIdentity();
4948 try {
4949 ComponentName componentName =
4950 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4951 if (componentName == null) {
4952 throw new SecurityException(
4953 "Caller not current active visual voicemail package[null]");
4954 }
4955 String vvmPackage = componentName.getPackageName();
4956 if (!callingPackage.equals(vvmPackage)) {
4957 throw new SecurityException("Caller not current active visual voicemail package["
4958 + vvmPackage + "]");
4959 }
4960 } finally {
4961 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004962 }
4963 }
4964
4965 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004966 * Return the application ID for the app type.
4967 *
4968 * @param subId the subscription ID that this request applies to.
4969 * @param appType the uicc app type.
4970 * @return Application ID for specificied app type, or null if no uicc.
4971 */
4972 @Override
4973 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004974 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004975 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976
4977 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004978 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004979 if (phone == null) {
4980 return null;
4981 }
4982 String aid = null;
4983 try {
4984 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4985 .getApplicationByType(appType).getAid();
4986 } catch (Exception e) {
4987 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4988 }
4989 return aid;
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004992 }
Youhan Wange64578a2016-05-02 15:32:42 -07004993 }
4994
Youhan Wang4001d252016-05-11 10:29:41 -07004995 /**
4996 * Return the Electronic Serial Number.
4997 *
4998 * @param subId the subscription ID that this request applies to.
4999 * @return ESN or null if error.
5000 */
5001 @Override
5002 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005003 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005004 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005
5006 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005007 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 if (phone == null) {
5009 return null;
5010 }
5011 String esn = null;
5012 try {
5013 esn = phone.getEsn();
5014 } catch (Exception e) {
5015 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5016 }
5017 return esn;
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005020 }
Youhan Wang4001d252016-05-11 10:29:41 -07005021 }
5022
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005023 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005024 * Return the Preferred Roaming List Version.
5025 *
5026 * @param subId the subscription ID that this request applies to.
5027 * @return PRLVersion or null if error.
5028 */
5029 @Override
5030 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005031 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005032 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033
5034 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005035 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 if (phone == null) {
5037 return null;
5038 }
5039 String cdmaPrlVersion = null;
5040 try {
5041 cdmaPrlVersion = phone.getCdmaPrlVersion();
5042 } catch (Exception e) {
5043 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5044 }
5045 return cdmaPrlVersion;
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005048 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005049 }
5050
5051 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005052 * Get snapshot of Telephony histograms
5053 * @return List of Telephony histograms
5054 * @hide
5055 */
5056 @Override
5057 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5059 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060
5061 final long identity = Binder.clearCallingIdentity();
5062 try {
5063 return RIL.getTelephonyRILTimingHistograms();
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005067 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005068
5069 /**
5070 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005071 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005072 * Require system privileges. In the future we may add this to carrier APIs.
5073 *
5074 * @return The number of carriers set successfully, should match length of carriers
5075 */
5076 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005077 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005078 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005079 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005080
Meng Wang9b7c4e92017-02-17 11:41:27 -08005081 if (carriers == null) {
5082 throw new NullPointerException("carriers cannot be null");
5083 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005088 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5089 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 return retVal[0];
5091 } finally {
5092 Binder.restoreCallingIdentity(identity);
5093 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005094 }
5095
5096 /**
5097 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005098 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005099 * Require system privileges. In the future we may add this to carrier APIs.
5100 *
5101 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5102 * means all carriers are allowed.
5103 */
5104 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005105 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005106 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005107 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108
5109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005112 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5113 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005117 }
5118
fionaxu59545b42016-05-25 15:53:37 -07005119 /**
5120 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5121 * @param subId the subscription ID that this action applies to.
5122 * @param enabled control enable or disable metered apns.
5123 * {@hide}
5124 */
5125 @Override
5126 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5127 enforceModifyPermission();
5128 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129
5130 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005131 if (phone == null) {
5132 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5133 return;
5134 }
5135 try {
5136 phone.carrierActionSetMeteredApnsEnabled(enabled);
5137 } catch (Exception e) {
5138 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 } finally {
5140 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005141 }
5142 }
5143
5144 /**
5145 * Action set from carrier signalling broadcast receivers to enable/disable radio
5146 * @param subId the subscription ID that this action applies to.
5147 * @param enabled control enable or disable radio.
5148 * {@hide}
5149 */
5150 @Override
5151 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5152 enforceModifyPermission();
5153 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154
5155 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005156 if (phone == null) {
5157 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5158 return;
5159 }
5160 try {
5161 phone.carrierActionSetRadioEnabled(enabled);
5162 } catch (Exception e) {
5163 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005166 }
5167 }
5168
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005169 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005170 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5171 * network status based on which carrier apps could apply actions accordingly,
5172 * enable/disable default url handler for example.
5173 *
5174 * @param subId the subscription ID that this action applies to.
5175 * @param report control start/stop reporting the default network status.
5176 * {@hide}
5177 */
5178 @Override
5179 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5180 enforceModifyPermission();
5181 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182
5183 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005184 if (phone == null) {
5185 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5186 return;
5187 }
5188 try {
5189 phone.carrierActionReportDefaultNetworkStatus(report);
5190 } catch (Exception e) {
5191 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005194 }
5195 }
5196
5197 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005198 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5199 * bug report is being generated.
5200 */
5201 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005202 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005203 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5204 != PackageManager.PERMISSION_GRANTED) {
5205 writer.println("Permission Denial: can't dump Phone from pid="
5206 + Binder.getCallingPid()
5207 + ", uid=" + Binder.getCallingUid()
5208 + "without permission "
5209 + android.Manifest.permission.DUMP);
5210 return;
5211 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005212 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005213 }
Jack Yueb89b242016-06-22 13:27:47 -07005214
Brad Ebingerdac2f002018-04-03 15:17:52 -07005215 @Override
5216 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5217 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5218 throws RemoteException {
5219 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5220 }
5221
Jack Yueb89b242016-06-22 13:27:47 -07005222 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005223 * Get aggregated video call data usage since boot.
5224 *
5225 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5226 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005227 * {@hide}
5228 */
5229 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005230 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005231 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5232 null);
5233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 final long identity = Binder.clearCallingIdentity();
5235 try {
5236 // NetworkStatsService keeps tracking the active network interface and identity. It
5237 // records the delta with the corresponding network identity.
5238 // We just return the total video call data usage snapshot since boot.
5239 Phone phone = getPhone(subId);
5240 if (phone != null) {
5241 return phone.getVtDataUsage(perUidStats);
5242 }
5243 return null;
5244 } finally {
5245 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005246 }
Jack Yueb89b242016-06-22 13:27:47 -07005247 }
Jack Yu75ab2952016-07-08 14:29:33 -07005248
5249 /**
5250 * Policy control of data connection. Usually used when data limit is passed.
5251 * @param enabled True if enabling the data, otherwise disabling.
5252 * @param subId Subscription index
5253 * {@hide}
5254 */
5255 @Override
5256 public void setPolicyDataEnabled(boolean enabled, int subId) {
5257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258
5259 final long identity = Binder.clearCallingIdentity();
5260 try {
5261 Phone phone = getPhone(subId);
5262 if (phone != null) {
5263 phone.setPolicyDataEnabled(enabled);
5264 }
5265 } finally {
5266 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005267 }
5268 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005269
5270 /**
5271 * Get Client request stats
5272 * @return List of Client Request Stats
5273 * @hide
5274 */
5275 @Override
5276 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005278 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005279 return null;
5280 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005281 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 if (phone != null) {
5286 return phone.getClientRequestStats();
5287 }
5288
5289 return null;
5290 } finally {
5291 Binder.restoreCallingIdentity(identity);
5292 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005293 }
5294
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005295 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005296 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005297 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005298 }
Jack Yueb4124c2017-02-16 15:32:43 -08005299
5300 /**
Grace Chen70990072017-03-24 17:21:30 -07005301 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005302 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005303 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005304 * @param state State of SIM (power down, power up, pass through)
5305 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5306 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5307 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005308 *
5309 **/
5310 @Override
Grace Chen70990072017-03-24 17:21:30 -07005311 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005312 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005313 Phone phone = PhoneFactory.getPhone(slotIndex);
5314
vagdeviaf9a5b92018-08-15 16:01:53 -07005315 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 final long identity = Binder.clearCallingIdentity();
5318 try {
5319 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005320 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 }
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005324 }
5325 }
Shuo Qiandd210312017-04-12 22:11:33 +00005326
Tyler Gunn65d45c22017-06-05 11:22:26 -07005327 private boolean isUssdApiAllowed(int subId) {
5328 CarrierConfigManager configManager =
5329 (CarrierConfigManager) mPhone.getContext().getSystemService(
5330 Context.CARRIER_CONFIG_SERVICE);
5331 if (configManager == null) {
5332 return false;
5333 }
5334 PersistableBundle pb = configManager.getConfigForSubId(subId);
5335 if (pb == null) {
5336 return false;
5337 }
5338 return pb.getBoolean(
5339 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5340 }
5341
Shuo Qiandd210312017-04-12 22:11:33 +00005342 /**
5343 * Check if phone is in emergency callback mode
5344 * @return true if phone is in emergency callback mode
5345 * @param subId sub id
5346 */
goneil9c5f4872017-12-05 14:07:56 -08005347 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005348 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005349 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005350 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351
5352 final long identity = Binder.clearCallingIdentity();
5353 try {
5354 if (phone != null) {
5355 return phone.isInEcm();
5356 } else {
5357 return false;
5358 }
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005361 }
5362 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005363
5364 /**
5365 * Get the current signal strength information for the given subscription.
5366 * Because this information is not updated when the device is in a low power state
5367 * it should not be relied-upon to be current.
5368 * @param subId Subscription index
5369 * @return the most recent cached signal strength info from the modem
5370 */
5371 @Override
5372 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
5375 Phone p = getPhone(subId);
5376 if (p == null) {
5377 return null;
5378 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 return p.getSignalStrength();
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005384 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005385
Pengquan Meng77b7f132018-08-22 14:49:57 -07005386 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005387 * Get the current modem radio state for the given slot.
5388 * @param slotIndex slot index.
5389 * @param callingPackage the name of the package making the call.
5390 * @return the current radio power state from the modem
5391 */
5392 @Override
5393 public int getRadioPowerState(int slotIndex, String callingPackage) {
5394 Phone phone = PhoneFactory.getPhone(slotIndex);
5395 if (phone != null) {
5396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5397 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5398 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5399 }
5400
5401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 return phone.getRadioPowerState();
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
5406 }
5407 }
5408 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5409 }
5410
5411 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005412 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5413 *
5414 * <p>Requires one of the following permissions:
5415 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5416 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5417 * privileges.
5418 *
5419 * @param subId subscription id
5420 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5421 * {@code false}.
5422 */
5423 @Override
5424 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005425 boolean isEnabled = false;
5426 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005427 try {
5428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005429 null /* message */);
5430 Phone phone = getPhone(subId);
5431 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005432 } catch (Exception e) {
5433 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5434 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005438 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005439 }
5440
5441
5442 /**
5443 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5444 *
5445 * <p> Requires permission:
5446 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5447 * privileges.
5448 *
5449 * @param subId subscription id
5450 * @param isEnabled {@code true} means enable, {@code false} means disable.
5451 */
5452 @Override
5453 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005454 final long identity = Binder.clearCallingIdentity();
5455 try {
5456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5457 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005458
Pengquan Menga1bb6272018-09-06 09:59:22 -07005459 Phone phone = getPhone(subId);
5460 if (phone != null) {
5461 phone.setDataRoamingEnabled(isEnabled);
5462 }
5463 } finally {
5464 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005465 }
5466 }
5467
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005468 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005469 public boolean isManualNetworkSelectionAllowed(int subId) {
5470 boolean isAllowed = true;
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5474 mApp, subId, "isManualNetworkSelectionAllowed");
5475 Phone phone = getPhone(subId);
5476 if (phone != null) {
5477 isAllowed = phone.isCspPlmnEnabled();
5478 }
5479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
5482 return isAllowed;
5483 }
5484
5485 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005486 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005487 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 final long identity = Binder.clearCallingIdentity();
5490 try {
5491 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5492 if (slots == null) {
5493 Rlog.i(LOG_TAG, "slots is null.");
5494 return null;
5495 }
5496
5497 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5498 for (int i = 0; i < slots.length; i++) {
5499 UiccSlot slot = slots[i];
5500 if (slot == null) {
5501 continue;
5502 }
5503
5504 String cardId;
5505 UiccCard card = slot.getUiccCard();
5506 if (card != null) {
5507 cardId = card.getCardId();
5508 } else {
5509 cardId = slot.getIccId();
5510 }
5511
5512 int cardState = 0;
5513 switch (slot.getCardState()) {
5514 case CARDSTATE_ABSENT:
5515 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5516 break;
5517 case CARDSTATE_PRESENT:
5518 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5519 break;
5520 case CARDSTATE_ERROR:
5521 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5522 break;
5523 case CARDSTATE_RESTRICTED:
5524 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5525 break;
5526 default:
5527 break;
5528
5529 }
5530
5531 infos[i] = new UiccSlotInfo(
5532 slot.isActive(),
5533 slot.isEuicc(),
5534 cardId,
5535 cardState,
5536 slot.getPhoneId(),
5537 slot.isExtendedApduSupported());
5538 }
5539 return infos;
5540 } finally {
5541 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005542 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005543 }
5544
5545 @Override
5546 public boolean switchSlots(int[] physicalSlots) {
5547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
5554 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005555 }
Jack Yu4c988042018-02-27 15:30:01 -08005556
5557 @Override
5558 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5559 enforceModifyPermission();
5560 final Phone phone = getPhone(subId);
5561 if (phone == null) {
5562 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5563 return;
5564 }
5565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 phone.setRadioIndicationUpdateMode(filters, mode);
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Jack Yu4c988042018-02-27 15:30:01 -08005572 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005573
5574 /**
goneil47ffb6e2018-04-06 15:40:58 -07005575 * A test API to reload the UICC profile.
5576 *
5577 * <p>Requires that the calling app has permission
5578 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5579 * @hide
5580 */
5581 @Override
5582 public void refreshUiccProfile(int subId) {
5583 enforceModifyPermission();
5584
5585 final long identity = Binder.clearCallingIdentity();
5586 try {
5587 Phone phone = getPhone(subId);
5588 if (phone == null) {
5589 return;
5590 }
5591 UiccCard uiccCard = phone.getUiccCard();
5592 if (uiccCard == null) {
5593 return;
5594 }
5595 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5596 if (uiccProfile == null) {
5597 return;
5598 }
5599 uiccProfile.refresh();
5600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
5603 }
5604
5605 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005606 * Returns false if the mobile data is disabled by default, otherwise return true.
5607 */
5608 private boolean getDefaultDataEnabled() {
5609 return "true".equalsIgnoreCase(
5610 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5611 }
5612
5613 /**
5614 * Returns true if the data roaming is enabled by default, i.e the system property
5615 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5616 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5617 */
5618 private boolean getDefaultDataRoamingEnabled(int subId) {
5619 final CarrierConfigManager configMgr = (CarrierConfigManager)
5620 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5621 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5622 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5623 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5624 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5625 return isDataRoamingEnabled;
5626 }
5627
5628 /**
5629 * Returns the default network type for the given {@code subId}, if the default network type is
5630 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5631 */
5632 private int getDefaultNetworkType(int subId) {
5633 return Integer.parseInt(
5634 TelephonyManager.getTelephonyProperty(
5635 mSubscriptionController.getPhoneId(subId),
5636 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5637 String.valueOf(Phone.PREFERRED_NT_MODE)));
5638 }
fionaxua13278b2018-03-21 00:08:13 -07005639
5640 @Override
5641 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5642 gid1, String gid2, String plmn, String spn) {
5643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644
5645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 final Phone phone = getPhone(subId);
5648 if (phone == null) {
5649 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5650 return;
5651 }
5652 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005655 }
fionaxua13278b2018-03-21 00:08:13 -07005656 }
5657
5658 @Override
5659 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005660 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 final Phone phone = getPhone(subId);
5665 if (phone == null) {
5666 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5667 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5668 }
5669 return phone.getCarrierIdListVersion();
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005672 }
fionaxua13278b2018-03-21 00:08:13 -07005673 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005674
5675 @Override
5676 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5678 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5679 return -1;
5680 }
5681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
5684 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005689
5690 @Override
5691 public int getCdmaRoamingMode(int subId) {
5692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5693 mApp, subId, "getCdmaRoamingMode");
5694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702
5703 @Override
5704 public boolean setCdmaRoamingMode(int subId, int mode) {
5705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5706 mApp, subId, "setCdmaRoamingMode");
5707
5708 final long identity = Binder.clearCallingIdentity();
5709 try {
5710 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
5714 }
5715
5716 @Override
5717 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5719 mApp, subId, "setCdmaSubscriptionMode");
5720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
5723 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
5727 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005728
5729 private void ensureUserRunning(int userId) {
5730 if (!mUserManager.isUserRunning(userId)) {
5731 throw new IllegalStateException("User " + userId + " does not exist or not running");
5732 }
5733 }
5734
5735 /**
5736 * Returns a list of SMS apps on a given user.
5737 *
5738 * Only the shell user (UID 2000 or 0) can call it.
5739 * Target user must be running.
5740 */
5741 @Override
5742 public String[] getSmsApps(int userId) {
5743 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5744 ensureUserRunning(userId);
5745
5746 final Collection<SmsApplicationData> apps =
5747 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5748
5749 String[] ret = new String[apps.size()];
5750 int i = 0;
5751 for (SmsApplicationData app : apps) {
5752 ret[i++] = app.mPackageName;
5753 }
5754 return ret;
5755 }
5756
5757 /**
5758 * Returns the default SMS app package name on a given user.
5759 *
5760 * Only the shell user (UID 2000 or 0) can call it.
5761 * Target user must be running.
5762 */
5763 @Override
5764 public String getDefaultSmsApp(int userId) {
5765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5766 ensureUserRunning(userId);
5767
5768 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5769 /* updateIfNeeded= */ true, userId);
5770 return cn == null ? null : cn.getPackageName();
5771 }
5772
5773 /**
5774 * Set a package as the default SMS app on a given user.
5775 *
5776 * Only the shell user (UID 2000 or 0) can call it.
5777 * Target user must be running.
5778 */
5779 @Override
5780 public void setDefaultSmsApp(int userId, String packageName) {
5781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5782 ensureUserRunning(userId);
5783
5784 boolean found = false;
5785 for (String pkg : getSmsApps(userId)) {
5786 if (TextUtils.equals(packageName, pkg)) {
5787 found = true;
5788 break;
5789 }
5790 }
5791 if (!found) {
5792 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5793 }
5794
5795 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5796 }
sqianc5eccab2018-10-19 18:46:41 -07005797
5798 @Override
5799 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5800 String callingPackage) {
5801 // TODO connect with internal content
5802 return null;
5803 }
5804
5805 @Override
5806 public boolean isCurrentEmergencyNumber(String number) {
5807 // TODO connect with internal content
5808 return false;
5809 }
chen xud6b45bd2018-10-30 22:27:10 -07005810
5811 @Override
5812 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5813 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5814 Phone phone = getPhone(subId);
5815 if (phone == null) {
5816 return null;
5817 }
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 UiccProfile profile = UiccController.getInstance()
5821 .getUiccProfileForPhone(phone.getPhoneId());
5822 if (profile != null) {
5823 return profile.getCertsFromCarrierPrivilegeAccessRules();
5824 }
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
5828 return null;
5829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005830}