blob: 740a0d477e050f174715efc35d05801174ba93d9 [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;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070063import android.telephony.ICellInfoCallback;
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;
calvinpaneed9ae82018-11-01 19:43:06 +080082import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070083import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070084import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080085import android.telephony.ims.aidl.IImsConfig;
86import android.telephony.ims.aidl.IImsMmTelFeature;
87import android.telephony.ims.aidl.IImsRcsFeature;
88import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070089import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080090import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080092import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080094import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080095import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080096
Brad Ebinger4c460712018-10-01 10:40:55 -070097import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070098import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080099import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700100import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700101import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700102import com.android.internal.telephony.CarrierInfoManager;
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 Chenf144d942018-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;
sqian2fff4a32018-11-05 14:18:37 -0800121import 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;
sqian2fff4a32018-11-05 14:18:37 -0800146import 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 xu1cc0abe2018-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 Meng0c05b502018-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 xu1cc0abe2018-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;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700221 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
222 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800224 // Parameters of select command.
225 private static final int SELECT_COMMAND = 0xA4;
226 private static final int SELECT_P1 = 0x04;
227 private static final int SELECT_P2 = 0;
228 private static final int SELECT_P3 = 0x10;
229
Pengquan Meng85728fb2018-03-12 16:31:21 -0700230 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
231 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
232 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
233
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 /** The singleton instance. */
235 private static PhoneInterfaceManager sInstance;
236
Wink Saville3ab207e2014-11-20 13:07:20 -0800237 private PhoneGlobals mApp;
238 private Phone mPhone;
239 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700240 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800241 private AppOpsManager mAppOps;
242 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800243 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800244 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700245 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
Derek Tan97ebb422014-09-05 16:55:38 -0700247 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
248 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700250
Derek Tan740e1672017-06-27 14:56:27 -0700251 // The AID of ISD-R.
252 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
253
yinxub1bed742017-04-17 11:45:04 -0700254 private NetworkScanRequestTracker mNetworkScanRequestTracker;
255
David Kelly5e06a7f2018-03-12 14:10:59 +0000256 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
257 private static final int MANUFACTURER_CODE_LENGTH = 8;
258
Derek Tan89e89d42014-07-08 17:00:10 -0700259 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700260 * A request object to use for transmitting data to an ICC.
261 */
262 private static final class IccAPDUArgument {
263 public int channel, cla, command, p1, p2, p3;
264 public String data;
265
266 public IccAPDUArgument(int channel, int cla, int command,
267 int p1, int p2, int p3, String data) {
268 this.channel = channel;
269 this.cla = cla;
270 this.command = command;
271 this.p1 = p1;
272 this.p2 = p2;
273 this.p3 = p3;
274 this.data = data;
275 }
276 }
277
278 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700279 * A request object to use for transmitting data to an ICC.
280 */
281 private static final class ManualNetworkSelectionArgument {
282 public OperatorInfo operatorInfo;
283 public boolean persistSelection;
284
285 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
286 this.operatorInfo = operatorInfo;
287 this.persistSelection = persistSelection;
288 }
289 }
290
291 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
293 * request after sending. The main thread will notify the request when it is complete.
294 */
295 private static final class MainThreadRequest {
296 /** The argument to use for the request */
297 public Object argument;
298 /** The result of the request that is run on the main thread */
299 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800300 // The subscriber id that this request applies to. Defaults to
301 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
302 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303
Nathan Harold92bed182018-10-12 18:16:49 -0700304 // In cases where subId is unavailable, the caller needs to specify the phone.
305 public Phone phone;
306
vagdevie435a3e2018-08-15 16:01:53 -0700307 public WorkSource workSource;
308
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309 public MainThreadRequest(Object argument) {
310 this.argument = argument;
311 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800312
Nathan Harold92bed182018-10-12 18:16:49 -0700313 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
314 this.argument = argument;
315 if (phone != null) {
316 this.phone = phone;
317 }
318 this.workSource = workSource;
319 }
320
vagdevie435a3e2018-08-15 16:01:53 -0700321 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800322 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800323 if (subId != null) {
324 this.subId = subId;
325 }
vagdevie435a3e2018-08-15 16:01:53 -0700326 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328 }
329
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800330 private static final class IncomingThirdPartyCallArgs {
331 public final ComponentName component;
332 public final String callId;
333 public final String callerDisplayName;
334
335 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
336 String callerDisplayName) {
337 this.component = component;
338 this.callId = callId;
339 this.callerDisplayName = callerDisplayName;
340 }
341 }
342
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 /**
344 * A handler that processes messages on the main thread in the phone process. Since many
345 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
346 * inbound binder threads to the main thread in the phone process. The Binder thread
347 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
348 * on, which will be notified when the operation completes and will contain the result of the
349 * request.
350 *
351 * <p>If a MainThreadRequest object is provided in the msg.obj field,
352 * note that request.result must be set to something non-null for the calling thread to
353 * unblock.
354 */
355 private final class MainThreadHandler extends Handler {
356 @Override
357 public void handleMessage(Message msg) {
358 MainThreadRequest request;
359 Message onCompleted;
360 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800361 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700362 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363
364 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700365 case CMD_HANDLE_USSD_REQUEST: {
366 request = (MainThreadRequest) msg.obj;
367 final Phone phone = getPhoneFromRequest(request);
368 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
369 String ussdRequest = ussdObject.first;
370 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700371
Pengquan Meng0c05b502018-09-06 09:59:22 -0700372 if (!isUssdApiAllowed(request.subId)) {
373 // Carrier does not support use of this API, return failure.
374 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
375 UssdResponse response = new UssdResponse(ussdRequest, null);
376 Bundle returnData = new Bundle();
377 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
378 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700379
Pengquan Meng0c05b502018-09-06 09:59:22 -0700380 request.result = true;
381 notifyRequester(request);
382 return;
383 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700384
Pengquan Meng0c05b502018-09-06 09:59:22 -0700385 try {
386 request.result = phone != null
387 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
388 } catch (CallStateException cse) {
389 request.result = false;
390 }
391 // Wake up the requesting thread
392 notifyRequester(request);
393 break;
pkanwar32d516d2016-10-14 19:37:38 -0700394 }
395
Yorke Lee716f67e2015-06-17 15:39:16 -0700396 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700398 final Phone phone = getPhoneFromRequest(request);
399 request.result = phone != null ?
400 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
401 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700403 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700408 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700409 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800410 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700411 if (uiccCard == null) {
412 loge("iccTransmitApduLogicalChannel: No UICC");
413 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700414 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
417 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 iccArgument.channel, iccArgument.cla, iccArgument.command,
420 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 break;
424
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 ar = (AsyncResult) msg.obj;
427 request = (MainThreadRequest) ar.userObj;
428 if (ar.exception == null && ar.result != null) {
429 request.result = ar.result;
430 } else {
431 request.result = new IccIoResult(0x6F, 0, (byte[])null);
432 if (ar.result == null) {
433 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800434 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800436 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 } else {
438 loge("iccTransmitApduLogicalChannel: Unknown exception");
439 }
440 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700441 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 break;
443
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
445 request = (MainThreadRequest) msg.obj;
446 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800447 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 if (uiccCard == null) {
449 loge("iccTransmitApduBasicChannel: No UICC");
450 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700451 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 } else {
453 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
454 request);
455 uiccCard.iccTransmitApduBasicChannel(
456 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
457 iccArgument.p3, iccArgument.data, onCompleted);
458 }
459 break;
460
461 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
462 ar = (AsyncResult) msg.obj;
463 request = (MainThreadRequest) ar.userObj;
464 if (ar.exception == null && ar.result != null) {
465 request.result = ar.result;
466 } else {
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
468 if (ar.result == null) {
469 loge("iccTransmitApduBasicChannel: Empty response");
470 } else if (ar.exception instanceof CommandException) {
471 loge("iccTransmitApduBasicChannel: CommandException: " +
472 ar.exception);
473 } else {
474 loge("iccTransmitApduBasicChannel: Unknown exception");
475 }
476 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700477 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 break;
479
480 case CMD_EXCHANGE_SIM_IO:
481 request = (MainThreadRequest) msg.obj;
482 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 if (uiccCard == null) {
485 loge("iccExchangeSimIO: No UICC");
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 } else {
489 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
490 request);
491 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
492 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
493 iccArgument.data, onCompleted);
494 }
495 break;
496
497 case EVENT_EXCHANGE_SIM_IO_DONE:
498 ar = (AsyncResult) msg.obj;
499 request = (MainThreadRequest) ar.userObj;
500 if (ar.exception == null && ar.result != null) {
501 request.result = ar.result;
502 } else {
503 request.result = new IccIoResult(0x6f, 0, (byte[])null);
504 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 break;
507
Derek Tan4d5e5c12014-02-04 11:54:58 -0800508 case CMD_SEND_ENVELOPE:
509 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800510 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700511 if (uiccCard == null) {
512 loge("sendEnvelopeWithStatus: No UICC");
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700515 } else {
516 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
517 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
518 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800519 break;
520
521 case EVENT_SEND_ENVELOPE_DONE:
522 ar = (AsyncResult) msg.obj;
523 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700524 if (ar.exception == null && ar.result != null) {
525 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700527 request.result = new IccIoResult(0x6F, 0, (byte[])null);
528 if (ar.result == null) {
529 loge("sendEnvelopeWithStatus: Empty response");
530 } else if (ar.exception instanceof CommandException) {
531 loge("sendEnvelopeWithStatus: CommandException: " +
532 ar.exception);
533 } else {
534 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
535 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800536 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700537 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 break;
539
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 case CMD_OPEN_CHANNEL:
541 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800542 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800543 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 if (uiccCard == null) {
545 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800546 request.result = new IccOpenLogicalChannelResponse(-1,
547 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 } else {
550 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800551 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
552 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 break;
555
556 case EVENT_OPEN_CHANNEL_DONE:
557 ar = (AsyncResult) msg.obj;
558 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 int[] result = (int[]) ar.result;
562 int channelId = result[0];
563 byte[] selectResponse = null;
564 if (result.length > 1) {
565 selectResponse = new byte[result.length - 1];
566 for (int i = 1; i < result.length; ++i) {
567 selectResponse[i - 1] = (byte) result[i];
568 }
569 }
570 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700571 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 if (ar.result == null) {
574 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 if (ar.exception != null) {
577 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
578 }
579
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700580 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700581 if (ar.exception instanceof CommandException) {
582 CommandException.Error error =
583 ((CommandException) (ar.exception)).getCommandError();
584 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700585 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700586 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700587 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 }
589 }
590 openChannelResp = new IccOpenLogicalChannelResponse(
591 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700593 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 break;
596
597 case CMD_CLOSE_CHANNEL:
598 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800599 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 if (uiccCard == null) {
601 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900602 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
606 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
607 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
610 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800611 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
612 break;
613
614 case CMD_NV_READ_ITEM:
615 request = (MainThreadRequest) msg.obj;
616 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700617 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800618 break;
619
620 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 ar = (AsyncResult) msg.obj;
622 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800623 if (ar.exception == null && ar.result != null) {
624 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800626 request.result = "";
627 if (ar.result == null) {
628 loge("nvReadItem: Empty response");
629 } else if (ar.exception instanceof CommandException) {
630 loge("nvReadItem: CommandException: " +
631 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800633 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 }
635 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
Jake Hambye994d462014-02-03 13:10:13 -0800639 case CMD_NV_WRITE_ITEM:
640 request = (MainThreadRequest) msg.obj;
641 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
642 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700643 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
644 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800645 break;
646
647 case EVENT_NV_WRITE_ITEM_DONE:
648 handleNullReturnEvent(msg, "nvWriteItem");
649 break;
650
651 case CMD_NV_WRITE_CDMA_PRL:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
654 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
655 break;
656
657 case EVENT_NV_WRITE_CDMA_PRL_DONE:
658 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
659 break;
660
chen xu1cc0abe2018-10-26 17:39:23 -0700661 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800662 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700663 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
664 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
chen xu1cc0abe2018-10-26 17:39:23 -0700667 case EVENT_RESET_MODEM_CONFIG_DONE:
668 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800669 break;
670
Jake Hamby7c27be32014-03-03 13:25:59 -0800671 case CMD_GET_PREFERRED_NETWORK_TYPE:
672 request = (MainThreadRequest) msg.obj;
673 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700674 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800675 break;
676
677 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result; // Integer
682 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800683 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800684 if (ar.result == null) {
685 loge("getPreferredNetworkType: Empty response");
686 } else if (ar.exception instanceof CommandException) {
687 loge("getPreferredNetworkType: CommandException: " +
688 ar.exception);
689 } else {
690 loge("getPreferredNetworkType: Unknown exception");
691 }
692 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700693 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 break;
695
696 case CMD_SET_PREFERRED_NETWORK_TYPE:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
699 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700700 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 break;
702
703 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
704 handleNullReturnEvent(msg, "setPreferredNetworkType");
705 break;
706
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000707 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
708 request = (MainThreadRequest)msg.obj;
709 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700710 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000711 break;
712
713 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
714 ar = (AsyncResult)msg.obj;
715 request = (MainThreadRequest)ar.userObj;
716 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700717 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000718 break;
719
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800720 case CMD_SET_VOICEMAIL_NUMBER:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
723 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800724 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
725 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800726 break;
727
728 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
729 handleNullReturnEvent(msg, "setVoicemailNumber");
730 break;
731
Stuart Scott54788802015-03-30 13:18:01 -0700732 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
735 request);
736 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
737 break;
738
739 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
740 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
741 break;
742
Shishir Agrawal302c8692015-06-19 13:49:39 -0700743 case CMD_PERFORM_NETWORK_SCAN:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
746 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
747 break;
748
749 case EVENT_PERFORM_NETWORK_SCAN_DONE:
750 ar = (AsyncResult) msg.obj;
751 request = (MainThreadRequest) ar.userObj;
752 CellNetworkScanResult cellScanResult;
753 if (ar.exception == null && ar.result != null) {
754 cellScanResult = new CellNetworkScanResult(
755 CellNetworkScanResult.STATUS_SUCCESS,
756 (List<OperatorInfo>) ar.result);
757 } else {
758 if (ar.result == null) {
759 loge("getCellNetworkScanResults: Empty response");
760 }
761 if (ar.exception != null) {
762 loge("getCellNetworkScanResults: Exception: " + ar.exception);
763 }
764 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
765 if (ar.exception instanceof CommandException) {
766 CommandException.Error error =
767 ((CommandException) (ar.exception)).getCommandError();
768 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
769 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
770 } else if (error == CommandException.Error.GENERIC_FAILURE) {
771 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
772 }
773 }
774 cellScanResult = new CellNetworkScanResult(errorCode, null);
775 }
776 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700777 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700778 break;
779
780 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
781 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700782 ManualNetworkSelectionArgument selArg =
783 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700784 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
785 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700786 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
787 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 break;
789
790 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700791 ar = (AsyncResult) msg.obj;
792 request = (MainThreadRequest) ar.userObj;
793 if (ar.exception == null) {
794 request.result = true;
795 } else {
796 request.result = false;
797 loge("setNetworkSelectionModeManual " + ar.exception);
798 }
799 notifyRequester(request);
800 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700801 break;
802
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700803 case CMD_GET_MODEM_ACTIVITY_INFO:
804 request = (MainThreadRequest) msg.obj;
805 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700806 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700807 break;
808
809 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null && ar.result != null) {
813 request.result = ar.result;
814 } else {
815 if (ar.result == null) {
816 loge("queryModemActivityInfo: Empty response");
817 } else if (ar.exception instanceof CommandException) {
818 loge("queryModemActivityInfo: CommandException: " +
819 ar.exception);
820 } else {
821 loge("queryModemActivityInfo: Unknown exception");
822 }
823 }
Amit Mahajand4766222016-01-28 15:28:28 -0800824 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
825 if (request.result == null) {
826 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
827 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700828 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700829 break;
830
Meng Wang1a7c35a2016-05-05 20:56:15 -0700831 case CMD_SET_ALLOWED_CARRIERS:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
834 mPhone.setAllowedCarriers(
835 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700836 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700837 break;
838
839 case EVENT_SET_ALLOWED_CARRIERS_DONE:
840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 if (ar.exception == null && ar.result != null) {
843 request.result = ar.result;
844 } else {
845 if (ar.result == null) {
846 loge("setAllowedCarriers: Empty response");
847 } else if (ar.exception instanceof CommandException) {
848 loge("setAllowedCarriers: CommandException: " +
849 ar.exception);
850 } else {
851 loge("setAllowedCarriers: Unknown exception");
852 }
853 }
854 // Result cannot be null. Return -1 on error.
855 if (request.result == null) {
856 request.result = new int[]{-1};
857 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700858 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700859 break;
860
861 case CMD_GET_ALLOWED_CARRIERS:
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700864 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700865 break;
866
867 case EVENT_GET_ALLOWED_CARRIERS_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
873 if (ar.result == null) {
874 loge("getAllowedCarriers: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("getAllowedCarriers: CommandException: " +
877 ar.exception);
878 } else {
879 loge("getAllowedCarriers: Unknown exception");
880 }
881 }
882 // Result cannot be null. Return empty list of CarrierIdentifier.
883 if (request.result == null) {
884 request.result = new ArrayList<CarrierIdentifier>(0);
885 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700886 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 break;
888
Nathan Haroldb3014052017-01-25 15:57:32 -0800889 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result;
894 } else {
895 request.result = new IllegalArgumentException(
896 "Failed to retrieve Forbidden Plmns");
897 if (ar.result == null) {
898 loge("getForbiddenPlmns: Empty response");
899 } else {
900 loge("getForbiddenPlmns: Unknown exception");
901 }
902 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700903 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800904 break;
905
906 case CMD_GET_FORBIDDEN_PLMNS:
907 request = (MainThreadRequest) msg.obj;
908 uiccCard = getUiccCardFromRequest(request);
909 if (uiccCard == null) {
910 loge("getForbiddenPlmns() UiccCard is null");
911 request.result = new IllegalArgumentException(
912 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700913 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800914 break;
915 }
916 Integer appType = (Integer) request.argument;
917 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
918 if (uiccApp == null) {
919 loge("getForbiddenPlmns() no app with specified type -- "
920 + appType);
921 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700922 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800923 break;
924 } else {
925 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
926 + " specified type -- " + appType);
927 }
928 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
929 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
930 onCompleted);
931 break;
932
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000933 case CMD_SWITCH_SLOTS:
934 request = (MainThreadRequest) msg.obj;
935 int[] physicalSlots = (int[]) request.argument;
936 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
937 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
938 break;
939
940 case EVENT_SWITCH_SLOTS_DONE:
941 ar = (AsyncResult) msg.obj;
942 request = (MainThreadRequest) ar.userObj;
943 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700944 notifyRequester(request);
945 break;
946 case CMD_GET_NETWORK_SELECTION_MODE:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
949 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
950 break;
951
952 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
953 ar = (AsyncResult) msg.obj;
954 request = (MainThreadRequest) ar.userObj;
955 if (ar.exception != null) {
956 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
957 } else {
958 int mode = ((int[]) ar.result)[0];
959 if (mode == 0) {
960 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
961 } else {
962 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
963 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000964 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700965 notifyRequester(request);
966 break;
967 case CMD_GET_CDMA_ROAMING_MODE:
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
970 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
971 break;
972 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 if (ar.exception != null) {
976 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
977 } else {
978 request.result = ((int[]) ar.result)[0];
979 }
980 notifyRequester(request);
981 break;
982 case CMD_SET_CDMA_ROAMING_MODE:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
985 int mode = (int) request.argument;
986 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
987 break;
988 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
991 request.result = ar.exception == null;
992 notifyRequester(request);
993 break;
994 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
997 int subscriptionMode = (int) request.argument;
998 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
999 break;
1000 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1001 ar = (AsyncResult) msg.obj;
1002 request = (MainThreadRequest) ar.userObj;
1003 request.result = ar.exception == null;
1004 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001005 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001006 case CMD_GET_ALL_CELL_INFO:
1007 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001008 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001009 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001010 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001011 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;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001021 case CMD_REQUEST_CELL_INFO_UPDATE:
1022 request = (MainThreadRequest) msg.obj;
1023 request.phone.requestCellInfoUpdate(request.workSource,
1024 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1025 break;
1026 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1030 try {
1031 if (ar.exception != null) {
1032 // something went wrong... the response is null
1033 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1034 cb.onCellInfo(null);
1035 } else if (ar.result == null) {
1036 // timeout occurred, so force the result to non-null "empty"
1037 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1038 cb.onCellInfo(new ArrayList<CellInfo>());
1039 } else {
1040 // use the result as returned
1041 cb.onCellInfo((List<CellInfo>) ar.result);
1042 }
1043 } catch (RemoteException re) {
1044 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1045 }
1046 break;
1047 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 request = (MainThreadRequest) msg.obj;
1049 WorkSource ws = (WorkSource) request.argument;
1050 Phone phone = getPhoneFromRequest(request);
1051 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1052 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001053 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 if (ar.exception == null) {
1057 request.result = ar.result;
1058 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1061 ? new CdmaCellLocation() : new GsmCellLocation();
1062 }
1063
1064 synchronized (request) {
1065 request.notifyAll();
1066 }
1067 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001068 case CMD_MODEM_REBOOT:
1069 request = (MainThreadRequest) msg.obj;
1070 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1071 mPhone.rebootModem(onCompleted);
1072 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001073 case EVENT_CMD_MODEM_REBOOT_DONE:
1074 handleNullReturnEvent(msg, "rebootModem");
1075 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 default:
1077 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1078 break;
1079 }
1080 }
Jake Hambye994d462014-02-03 13:10:13 -08001081
Pengquan Meng0c05b502018-09-06 09:59:22 -07001082 private void notifyRequester(MainThreadRequest request) {
1083 synchronized (request) {
1084 request.notifyAll();
1085 }
1086 }
1087
Jake Hambye994d462014-02-03 13:10:13 -08001088 private void handleNullReturnEvent(Message msg, String command) {
1089 AsyncResult ar = (AsyncResult) msg.obj;
1090 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1091 if (ar.exception == null) {
1092 request.result = true;
1093 } else {
1094 request.result = false;
1095 if (ar.exception instanceof CommandException) {
1096 loge(command + ": CommandException: " + ar.exception);
1097 } else {
1098 loge(command + ": Unknown exception");
1099 }
1100 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001101 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 }
1104
1105 /**
1106 * Posts the specified command to be executed on the main thread,
1107 * waits for the request to complete, and returns the result.
1108 * @see #sendRequestAsync
1109 */
1110 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001111 return sendRequest(
1112 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-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 */
1120 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1121 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001122 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001123 }
1124
1125 /**
1126 * Posts the specified command to be executed on the main thread,
1127 * waits for the request to complete, and returns the result.
1128 * @see #sendRequestAsync
1129 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001130 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001131 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001132 }
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 */
Nathan Harold92bed182018-10-12 18:16:49 -07001139 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1140 return sendRequest(command, argument, subId, null, workSource);
1141 }
1142
1143 /**
1144 * Posts the specified command to be executed on the main thread,
1145 * waits for the request to complete, and returns the result.
1146 * @see #sendRequestAsync
1147 */
1148 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1149 return sendRequest(
1150 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1151 }
1152
1153 /**
1154 * Posts the specified command to be executed on the main thread,
1155 * waits for the request to complete, and returns the result.
1156 * @see #sendRequestAsync
1157 */
1158 private Object sendRequest(
1159 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1161 throw new RuntimeException("This method will deadlock if called from the main thread.");
1162 }
1163
Nathan Harold92bed182018-10-12 18:16:49 -07001164 MainThreadRequest request = null;
1165 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1166 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1167 } else if (phone != null) {
1168 request = new MainThreadRequest(argument, phone, workSource);
1169 } else {
1170 request = new MainThreadRequest(argument, subId, workSource);
1171 }
1172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 Message msg = mMainThreadHandler.obtainMessage(command, request);
1174 msg.sendToTarget();
1175
1176 // Wait for the request to complete
1177 synchronized (request) {
1178 while (request.result == null) {
1179 try {
1180 request.wait();
1181 } catch (InterruptedException e) {
1182 // Do nothing, go back and wait until the request is complete
1183 }
1184 }
1185 }
1186 return request.result;
1187 }
1188
1189 /**
1190 * Asynchronous ("fire and forget") version of sendRequest():
1191 * Posts the specified command to be executed on the main thread, and
1192 * returns immediately.
1193 * @see #sendRequest
1194 */
1195 private void sendRequestAsync(int command) {
1196 mMainThreadHandler.sendEmptyMessage(command);
1197 }
1198
1199 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001200 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001201 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001202 */
1203 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001204 sendRequestAsync(command, argument, null, null);
1205 }
1206
1207 /**
1208 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1209 * @see {@link #sendRequest(int,Object)}
1210 */
1211 private void sendRequestAsync(
1212 int command, Object argument, Phone phone, WorkSource workSource) {
1213 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001214 Message msg = mMainThreadHandler.obtainMessage(command, request);
1215 msg.sendToTarget();
1216 }
1217
1218 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 * Initialize the singleton PhoneInterfaceManager instance.
1220 * This is only done once, at startup, from PhoneApp.onCreate().
1221 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001222 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 synchronized (PhoneInterfaceManager.class) {
1224 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001225 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 } else {
1227 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1228 }
1229 return sInstance;
1230 }
1231 }
1232
1233 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001234 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 mApp = app;
1236 mPhone = phone;
1237 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001238 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1240 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001241 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001242 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001243 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001244 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001245 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001246
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 publish();
1248 }
1249
1250 private void publish() {
1251 if (DBG) log("publish: " + this);
1252
1253 ServiceManager.addService("phone", this);
1254 }
1255
Stuart Scott584921c2015-01-15 17:10:34 -08001256 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001257 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1258 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001259 }
1260
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001261 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1262 Phone phone = getPhoneFromRequest(request);
1263 return phone == null ? null :
1264 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1265 }
1266
Wink Saville36469e72014-06-11 15:17:00 -07001267 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001268 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001269 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271
1272 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001273 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001274 }
1275
Wink Savilleb564aae2014-10-23 10:18:09 -07001276 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 if (DBG) log("dial: " + number);
1278 // No permission check needed here: This is just a wrapper around the
1279 // ACTION_DIAL intent, which is available to any app since it puts up
1280 // the UI before it does anything.
1281
Malcolm Chend965c8b2018-02-28 15:00:40 -08001282 final long identity = Binder.clearCallingIdentity();
1283 try {
1284 String url = createTelUrl(number);
1285 if (url == null) {
1286 return;
1287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288
Malcolm Chend965c8b2018-02-28 15:00:40 -08001289 // PENDING: should we just silently fail if phone is offhook or ringing?
1290 PhoneConstants.State state = mCM.getState(subId);
1291 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1292 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1293 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1294 mApp.startActivity(intent);
1295 }
1296 } finally {
1297 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 }
1299 }
1300
1301 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001302 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001303 }
1304
Wink Savilleb564aae2014-10-23 10:18:09 -07001305 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 if (DBG) log("call: " + number);
1307
1308 // This is just a wrapper around the ACTION_CALL intent, but we still
1309 // need to do a permission check since we're calling startActivity()
1310 // from the context of the phone app.
1311 enforceCallPermission();
1312
1313 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1314 != AppOpsManager.MODE_ALLOWED) {
1315 return;
1316 }
1317
Malcolm Chend965c8b2018-02-28 15:00:40 -08001318 final long identity = Binder.clearCallingIdentity();
1319 try {
1320 String url = createTelUrl(number);
1321 if (url == null) {
1322 return;
1323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324
Malcolm Chend965c8b2018-02-28 15:00:40 -08001325 boolean isValid = false;
1326 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1327 if (slist != null) {
1328 for (SubscriptionInfo subInfoRecord : slist) {
1329 if (subInfoRecord.getSubscriptionId() == subId) {
1330 isValid = true;
1331 break;
1332 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001333 }
Wink Saville08874612014-08-31 19:19:58 -07001334 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001335 if (!isValid) {
1336 return;
1337 }
Wink Saville08874612014-08-31 19:19:58 -07001338
Malcolm Chend965c8b2018-02-28 15:00:40 -08001339 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1340 intent.putExtra(SUBSCRIPTION_KEY, subId);
1341 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1342 mApp.startActivity(intent);
1343 } finally {
1344 Binder.restoreCallingIdentity(identity);
1345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346 }
1347
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001349 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001350 }
1351
Wink Savilleb564aae2014-10-23 10:18:09 -07001352 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001353 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001354 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1355 }
1356
1357 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001358 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
Wink Savilleb564aae2014-10-23 10:18:09 -07001361 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001362 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001363 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1364 }
1365
1366 /** {@hide} */
1367 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001368 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001369 }
1370
Wink Savilleb564aae2014-10-23 10:18:09 -07001371 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001373
1374 final long identity = Binder.clearCallingIdentity();
1375 try {
1376 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1377 checkSimPin.start();
1378 return checkSimPin.unlockSim(null, pin);
1379 } finally {
1380 Binder.restoreCallingIdentity(identity);
1381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 }
1383
Wink Saville9de0f752013-10-22 19:04:03 -07001384 /** {@hide} */
1385 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001386 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001387 }
1388
Wink Savilleb564aae2014-10-23 10:18:09 -07001389 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001391
1392 final long identity = Binder.clearCallingIdentity();
1393 try {
1394 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1395 checkSimPuk.start();
1396 return checkSimPuk.unlockSim(puk, pin);
1397 } finally {
1398 Binder.restoreCallingIdentity(identity);
1399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 }
1401
1402 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001403 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 * a synchronous one.
1405 */
1406 private static class UnlockSim extends Thread {
1407
1408 private final IccCard mSimCard;
1409
1410 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001411 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1412 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413
1414 // For replies from SimCard interface
1415 private Handler mHandler;
1416
1417 // For async handler to identify request type
1418 private static final int SUPPLY_PIN_COMPLETE = 100;
1419
1420 public UnlockSim(IccCard simCard) {
1421 mSimCard = simCard;
1422 }
1423
1424 @Override
1425 public void run() {
1426 Looper.prepare();
1427 synchronized (UnlockSim.this) {
1428 mHandler = new Handler() {
1429 @Override
1430 public void handleMessage(Message msg) {
1431 AsyncResult ar = (AsyncResult) msg.obj;
1432 switch (msg.what) {
1433 case SUPPLY_PIN_COMPLETE:
1434 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1435 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001436 mRetryCount = msg.arg1;
1437 if (ar.exception != null) {
1438 if (ar.exception instanceof CommandException &&
1439 ((CommandException)(ar.exception)).getCommandError()
1440 == CommandException.Error.PASSWORD_INCORRECT) {
1441 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1442 } else {
1443 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1444 }
1445 } else {
1446 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 mDone = true;
1449 UnlockSim.this.notifyAll();
1450 }
1451 break;
1452 }
1453 }
1454 };
1455 UnlockSim.this.notifyAll();
1456 }
1457 Looper.loop();
1458 }
1459
1460 /*
1461 * Use PIN or PUK to unlock SIM card
1462 *
1463 * If PUK is null, unlock SIM card with PIN
1464 *
1465 * If PUK is not null, unlock SIM card with PUK and set PIN code
1466 */
Wink Saville9de0f752013-10-22 19:04:03 -07001467 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468
1469 while (mHandler == null) {
1470 try {
1471 wait();
1472 } catch (InterruptedException e) {
1473 Thread.currentThread().interrupt();
1474 }
1475 }
1476 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1477
1478 if (puk == null) {
1479 mSimCard.supplyPin(pin, callback);
1480 } else {
1481 mSimCard.supplyPuk(puk, pin, callback);
1482 }
1483
1484 while (!mDone) {
1485 try {
1486 Log.d(LOG_TAG, "wait for done");
1487 wait();
1488 } catch (InterruptedException e) {
1489 // Restore the interrupted status
1490 Thread.currentThread().interrupt();
1491 }
1492 }
1493 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001494 int[] resultArray = new int[2];
1495 resultArray[0] = mResult;
1496 resultArray[1] = mRetryCount;
1497 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499 }
1500
1501 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001502 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001503
1504 }
1505
Wink Savilleb564aae2014-10-23 10:18:09 -07001506 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507 // No permission check needed here: this call is harmless, and it's
1508 // needed for the ServiceState.requestStateUpdate() call (which is
1509 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001510 final long identity = Binder.clearCallingIdentity();
1511 try {
1512 final Phone phone = getPhone(subId);
1513 if (phone != null) {
1514 phone.updateServiceLocation();
1515 }
1516 } finally {
1517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519 }
1520
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001521 @Override
1522 public boolean isRadioOn(String callingPackage) {
1523 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001524 }
1525
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001526 @Override
1527 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001529 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001530 return false;
1531 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001532
1533 final long identity = Binder.clearCallingIdentity();
1534 try {
1535 return isRadioOnForSubscriber(subId);
1536 } finally {
1537 Binder.restoreCallingIdentity(identity);
1538 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001539 }
1540
1541 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001542 final long identity = Binder.clearCallingIdentity();
1543 try {
1544 final Phone phone = getPhone(subId);
1545 if (phone != null) {
1546 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1547 } else {
1548 return false;
1549 }
1550 } finally {
1551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 }
1554
1555 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001556 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 }
Wink Saville36469e72014-06-11 15:17:00 -07001558
Wink Savilleb564aae2014-10-23 10:18:09 -07001559 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001561
1562 final long identity = Binder.clearCallingIdentity();
1563 try {
1564 final Phone phone = getPhone(subId);
1565 if (phone != null) {
1566 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1567 }
1568 } finally {
1569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 }
Wink Saville36469e72014-06-11 15:17:00 -07001571 }
1572
1573 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001574 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001575 }
1576
Wink Savilleb564aae2014-10-23 10:18:09 -07001577 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001578 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001579
1580 final long identity = Binder.clearCallingIdentity();
1581 try {
1582 final Phone phone = getPhone(subId);
1583 if (phone == null) {
1584 return false;
1585 }
1586 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1587 toggleRadioOnOffForSubscriber(subId);
1588 }
1589 return true;
1590 } finally {
1591 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
Wink Saville36469e72014-06-11 15:17:00 -07001594
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001595 public boolean needMobileRadioShutdown() {
1596 /*
1597 * If any of the Radios are available, it will need to be
1598 * shutdown. So return true if any Radio is available.
1599 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1603 Phone phone = PhoneFactory.getPhone(i);
1604 if (phone != null && phone.isRadioAvailable()) return true;
1605 }
1606 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1607 return false;
1608 } finally {
1609 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001610 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001611 }
1612
Malcolm Chend965c8b2018-02-28 15:00:40 -08001613 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001614 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001615 enforceModifyPermission();
1616
1617 final long identity = Binder.clearCallingIdentity();
1618 try {
1619 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1620 logv("Shutting down Phone " + i);
1621 shutdownRadioUsingPhoneId(i);
1622 }
1623 } finally {
1624 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001625 }
1626 }
1627
1628 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001629 Phone phone = PhoneFactory.getPhone(phoneId);
1630 if (phone != null && phone.isRadioAvailable()) {
1631 phone.shutdownRadio();
1632 }
1633 }
1634
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001636 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001637
1638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1641 if (defaultPhone != null) {
1642 defaultPhone.setRadioPower(turnOn);
1643 return true;
1644 } else {
1645 loge("There's no default phone.");
1646 return false;
1647 }
1648 } finally {
1649 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001650 }
Wink Saville36469e72014-06-11 15:17:00 -07001651 }
1652
Wink Savilleb564aae2014-10-23 10:18:09 -07001653 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001655
1656 final long identity = Binder.clearCallingIdentity();
1657 try {
1658 final Phone phone = getPhone(subId);
1659 if (phone != null) {
1660 phone.setRadioPower(turnOn);
1661 return true;
1662 } else {
1663 return false;
1664 }
1665 } finally {
1666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 }
1669
Wink Saville36469e72014-06-11 15:17:00 -07001670 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 public boolean enableDataConnectivity() {
1673 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001674
1675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 int subId = mSubscriptionController.getDefaultDataSubId();
1678 final Phone phone = getPhone(subId);
1679 if (phone != null) {
1680 phone.setUserDataEnabled(true);
1681 return true;
1682 } else {
1683 return false;
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 }
1689
Wink Saville36469e72014-06-11 15:17:00 -07001690 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001691 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 public boolean disableDataConnectivity() {
1693 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001694
1695 final long identity = Binder.clearCallingIdentity();
1696 try {
1697 int subId = mSubscriptionController.getDefaultDataSubId();
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 phone.setUserDataEnabled(false);
1701 return true;
1702 } else {
1703 return false;
1704 }
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 }
1709
Sanket Padawe356d7632015-06-22 14:03:32 -07001710 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001711 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
1716 return phone.isDataAllowed();
1717 } else {
1718 return false;
1719 }
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 }
1724
1725 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001726 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001727 }
1728
pkanwarae03a6b2016-11-06 20:37:09 -08001729 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001730 enforceCallPermission();
1731
1732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1735 return;
1736 }
1737 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1738 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1739 } finally {
1740 Binder.restoreCallingIdentity(identity);
1741 }
pkanwar32d516d2016-10-14 19:37:38 -07001742 };
1743
Wink Savilleb564aae2014-10-23 10:18:09 -07001744 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001746
1747 final long identity = Binder.clearCallingIdentity();
1748 try {
1749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1750 return false;
1751 }
1752 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001759 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001760 }
1761
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001762 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001763 final long identity = Binder.clearCallingIdentity();
1764 try {
1765 Phone phone = PhoneFactory.getPhone(slotIndex);
1766 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1767 PhoneConstantConversions.convertCallState(phone.getState());
1768 } finally {
1769 Binder.restoreCallingIdentity(identity);
1770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1778 if (phone != null) {
1779 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1780 } else {
1781 return PhoneConstantConversions.convertDataState(
1782 PhoneConstants.DataState.DISCONNECTED);
1783 }
1784 } finally {
1785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 }
1788
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001791 final long identity = Binder.clearCallingIdentity();
1792 try {
1793 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1794 if (phone != null) {
1795 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1796 } else {
1797 return TelephonyManager.DATA_ACTIVITY_NONE;
1798 }
1799 } finally {
1800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 }
1803
1804 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001805 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001806 mPhone.getContext().getSystemService(AppOpsManager.class)
1807 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001808 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001809 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001810 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001813 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 if (DBG_LOC) log("getCellLocation: is active user");
1817 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001818 int subId = mSubscriptionController.getDefaultDataSubId();
1819 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1820 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001821 return data;
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
1824 }
Svetoslav64fad262015-04-14 14:35:21 -07001825 }
1826
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001828 public String getNetworkCountryIsoForPhone(int phoneId) {
1829 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1830 // registered cell info, so return a NULL country instead.
1831 final long identity = Binder.clearCallingIdentity();
1832 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001833 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1834 // Get default phone in this case.
1835 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1836 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001837 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001838 // Todo: fix this when we can get the actual cellular network info when the device
1839 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001840 if (TelephonyManager.NETWORK_TYPE_IWLAN
1841 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1842 return "";
1843 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001844 Phone phone = PhoneFactory.getPhone(phoneId);
1845 if (phone != null) {
1846 ServiceStateTracker sst = phone.getServiceStateTracker();
1847 if (sst != null) {
1848 LocaleTracker lt = sst.getLocaleTracker();
1849 if (lt != null) {
1850 return lt.getCurrentCountry();
1851 }
1852 }
1853 }
1854 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001855 } finally {
1856 Binder.restoreCallingIdentity(identity);
1857 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001858 }
1859
1860 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001862 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001863 }
1864
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001866 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 mApp.enforceCallingOrSelfPermission(
1868 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001869
1870 final long identity = Binder.clearCallingIdentity();
1871 try {
1872 final Phone phone = getPhone(subId);
1873 if (phone != null) {
1874 phone.enableLocationUpdates();
1875 }
1876 } finally {
1877 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 }
1880
1881 @Override
1882 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001883 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001884 }
1885
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001887 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 mApp.enforceCallingOrSelfPermission(
1889 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001890
1891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 final Phone phone = getPhone(subId);
1894 if (phone != null) {
1895 phone.disableLocationUpdates();
1896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 }
1901
Nathan Harold31d7ff32018-10-15 20:20:30 -07001902 /**
1903 * Returns the target SDK version number for a given package name.
1904 *
1905 * @return target SDK if the package is found or INT_MAX.
1906 */
1907 private int getTargetSdk(String packageName) {
1908 try {
1909 final ApplicationInfo ai =
1910 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1911 if (ai != null) return ai.targetSdkVersion;
1912 } catch (PackageManager.NameNotFoundException unexpected) {
1913 }
1914 return Integer.MAX_VALUE;
1915 }
1916
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 @Override
1918 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001919 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1920 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001921 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1922 throw new SecurityException(
1923 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1924 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001925
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1927 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1928 return null;
1929 }
Svetoslav64fad262015-04-14 14:35:21 -07001930
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001931 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932
Nathan Haroldf180aac2018-06-01 18:43:55 -07001933 List<CellInfo> info = getAllCellInfo(callingPackage);
1934 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935
Nathan Haroldf180aac2018-06-01 18:43:55 -07001936 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1937 for (CellInfo ci : info) {
1938 if (ci instanceof CellInfoGsm) {
1939 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1940 } else if (ci instanceof CellInfoWcdma) {
1941 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001944 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001947 private List<CellInfo> getCachedCellInfo() {
1948 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1949 for (Phone phone : PhoneFactory.getPhones()) {
1950 List<CellInfo> info = phone.getAllCellInfo();
1951 if (info != null) cellInfos.addAll(info);
1952 }
1953 return cellInfos;
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955
1956 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001957 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001958 mPhone.getContext().getSystemService(AppOpsManager.class)
1959 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001960 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001961 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001962 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
1964
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001965 final int targetSdk = getTargetSdk(callingPackage);
1966 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1967 return getCachedCellInfo();
1968 }
1969
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001970 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001971 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001972 final long identity = Binder.clearCallingIdentity();
1973 try {
1974 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1975 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001976 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001977 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001978 if (info != null) cellInfos.addAll(info);
1979 }
1980 return cellInfos;
1981 } finally {
1982 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984 }
1985
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001986 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001987 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1988 requestCellInfoUpdateInternal(
1989 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
1990 }
1991
1992 @Override
1993 public void requestCellInfoUpdateWithWorkSource(
1994 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
1995 enforceModifyPermission();
1996 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
1997 }
1998
1999 private void requestCellInfoUpdateInternal(
2000 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2001 mPhone.getContext().getSystemService(AppOpsManager.class)
2002 .checkPackage(Binder.getCallingUid(), callingPackage);
2003 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2004 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
2005 return;
2006 }
2007
2008 final Phone phone = getPhone(subId);
2009 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2010
2011 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2012 }
2013
2014 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002016 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002017 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002018
2019 final long identity = Binder.clearCallingIdentity();
2020 try {
2021 mPhone.setCellInfoListRate(rateInMillis, workSource);
2022 } finally {
2023 Binder.restoreCallingIdentity(identity);
2024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025 }
2026
Shishir Agrawala9f32182016-04-12 12:00:16 -07002027 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002028 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002029 Phone phone = PhoneFactory.getPhone(slotIndex);
2030 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002031 return null;
2032 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002033 int subId = phone.getSubId();
2034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2035 mApp, subId, callingPackage, "getImeiForSlot")) {
2036 return null;
2037 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002038
2039 final long identity = Binder.clearCallingIdentity();
2040 try {
2041 return phone.getImei();
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002045 }
2046
2047 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002048 public String getTypeAllocationCodeForSlot(int slotIndex) {
2049 Phone phone = PhoneFactory.getPhone(slotIndex);
2050 String tac = null;
2051 if (phone != null) {
2052 String imei = phone.getImei();
2053 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2054 }
2055 return tac;
2056 }
2057
2058 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002059 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002060 Phone phone = PhoneFactory.getPhone(slotIndex);
2061 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002062 return null;
2063 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002064 int subId = phone.getSubId();
2065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2066 mApp, subId, callingPackage, "getMeidForSlot")) {
2067 return null;
2068 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002069
2070 final long identity = Binder.clearCallingIdentity();
2071 try {
2072 return phone.getMeid();
2073 } finally {
2074 Binder.restoreCallingIdentity(identity);
2075 }
Jack Yu2af8d712017-03-15 17:14:14 -07002076 }
2077
2078 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002079 public String getManufacturerCodeForSlot(int slotIndex) {
2080 Phone phone = PhoneFactory.getPhone(slotIndex);
2081 String manufacturerCode = null;
2082 if (phone != null) {
2083 String meid = phone.getMeid();
2084 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2085 }
2086 return manufacturerCode;
2087 }
2088
2089 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002090 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002091 Phone phone = PhoneFactory.getPhone(slotIndex);
2092 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002093 return null;
2094 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002095 int subId = phone.getSubId();
2096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2097 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2098 return null;
2099 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002100
2101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 return phone.getDeviceSvn();
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
2106 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002107 }
2108
fionaxu43304da2017-11-27 22:51:16 -08002109 @Override
2110 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002111 final long identity = Binder.clearCallingIdentity();
2112 try {
2113 final Phone phone = getPhone(subId);
2114 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2115 } finally {
2116 Binder.restoreCallingIdentity(identity);
2117 }
fionaxu43304da2017-11-27 22:51:16 -08002118 }
2119
2120 @Override
2121 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002122 final long identity = Binder.clearCallingIdentity();
2123 try {
2124 final Phone phone = getPhone(subId);
2125 return phone == null ? null : phone.getCarrierName();
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
2128 }
fionaxu43304da2017-11-27 22:51:16 -08002129 }
2130
calvinpaneed9ae82018-11-01 19:43:06 +08002131 @Override
2132 public int getSubscriptionMNOCarrierId(int subId) {
2133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 final Phone phone = getPhone(subId);
2136 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2137 } finally {
2138 Binder.restoreCallingIdentity(identity);
2139 }
2140 }
2141
chen xuc93cc282018-11-04 17:17:00 -08002142 @Override
2143 public int getSubscriptionPreciseCarrierId(int subId) {
2144 final long identity = Binder.clearCallingIdentity();
2145 try {
2146 final Phone phone = getPhone(subId);
2147 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2148 : phone.getPreciseCarrierId();
2149 } finally {
2150 Binder.restoreCallingIdentity(identity);
2151 }
2152 }
2153
2154 @Override
2155 public String getSubscriptionPreciseCarrierName(int subId) {
2156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 final Phone phone = getPhone(subId);
2159 return phone == null ? null : phone.getPreciseCarrierName();
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
2162 }
2163 }
2164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 //
2166 // Internal helper methods.
2167 //
2168
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002169 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2171 *
2172 * @throws SecurityException if the caller does not have the required permission
2173 */
2174 private void enforceModifyPermission() {
2175 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2176 }
2177
2178 /**
2179 * Make sure the caller has the CALL_PHONE permission.
2180 *
2181 * @throws SecurityException if the caller does not have the required permission
2182 */
2183 private void enforceCallPermission() {
2184 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2185 }
2186
Stuart Scott8eef64f2015-04-08 15:13:54 -07002187 private void enforceConnectivityInternalPermission() {
2188 mApp.enforceCallingOrSelfPermission(
2189 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2190 "ConnectivityService");
2191 }
2192
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 private String createTelUrl(String number) {
2194 if (TextUtils.isEmpty(number)) {
2195 return null;
2196 }
2197
Jake Hambye994d462014-02-03 13:10:13 -08002198 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200
Ihab Awadf9e92732013-12-05 18:02:52 -08002201 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2203 }
2204
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002205 private static void logv(String msg) {
2206 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2207 }
2208
Ihab Awadf9e92732013-12-05 18:02:52 -08002209 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2211 }
2212
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002213 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002215 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002216 }
2217
Sanket Padawe356d7632015-06-22 14:03:32 -07002218 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002219 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002220 final long identity = Binder.clearCallingIdentity();
2221 try {
2222 final Phone phone = PhoneFactory.getPhone(slotIndex);
2223 if (phone == null) {
2224 return PhoneConstants.PHONE_TYPE_NONE;
2225 } else {
2226 return phone.getPhoneType();
2227 }
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
2233 /**
2234 * Returns the CDMA ERI icon index to display
2235 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 @Override
2237 public int getCdmaEriIconIndex(String callingPackage) {
2238 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002239 }
2240
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002242 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002244 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 return -1;
2246 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002247
2248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 final Phone phone = getPhone(subId);
2251 if (phone != null) {
2252 return phone.getCdmaEriIconIndex();
2253 } else {
2254 return -1;
2255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
2261 /**
2262 * Returns the CDMA ERI icon mode,
2263 * 0 - ON
2264 * 1 - FLASHING
2265 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002266 @Override
2267 public int getCdmaEriIconMode(String callingPackage) {
2268 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002269 }
2270
Sanket Padawe356d7632015-06-22 14:03:32 -07002271 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002272 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002274 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002275 return -1;
2276 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002277
2278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 final Phone phone = getPhone(subId);
2281 if (phone != null) {
2282 return phone.getCdmaEriIconMode();
2283 } else {
2284 return -1;
2285 }
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
2291 /**
2292 * Returns the CDMA ERI text,
2293 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002294 @Override
2295 public String getCdmaEriText(String callingPackage) {
2296 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002297 }
2298
Sanket Padawe356d7632015-06-22 14:03:32 -07002299 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002300 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002302 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002303 return null;
2304 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002305
2306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 final Phone phone = getPhone(subId);
2309 if (phone != null) {
2310 return phone.getCdmaEriText();
2311 } else {
2312 return null;
2313 }
2314 } finally {
2315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 }
2318
2319 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002320 * Returns the CDMA MDN.
2321 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002322 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002323 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2325 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 final Phone phone = getPhone(subId);
2330 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2331 return phone.getLine1Number();
2332 } else {
2333 return null;
2334 }
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002337 }
2338 }
2339
2340 /**
2341 * Returns the CDMA MIN.
2342 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2346 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2352 return phone.getCdmaMin();
2353 } else {
2354 return null;
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002358 }
2359 }
2360
2361 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 * Returns true if CDMA provisioning needs to run.
2363 */
2364 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 return mPhone.needsOtaServiceProvisioning();
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
2370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
2373 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002374 * Sets the voice mail number of a given subId.
2375 */
2376 @Override
2377 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002378 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002379
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2383 new Pair<String, String>(alphaTag, number), new Integer(subId));
2384 return success;
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002388 }
2389
Ta-wei Yen87c49842016-05-13 21:19:52 -07002390 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002391 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2393 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2394 if (!TextUtils.equals(callingPackage, systemDialer)) {
2395 throw new SecurityException("caller must be system dialer");
2396 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002397
2398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2401 if (phoneAccountHandle == null) {
2402 return null;
2403 }
2404 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002407 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002408 }
2409
2410 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002411 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002412 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002414 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002415 return null;
2416 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002417
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 return RemoteVvmTaskManager
2421 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2422 } finally {
2423 Binder.restoreCallingIdentity(identity);
2424 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002425 }
2426
2427 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002428 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2429 VisualVoicemailSmsFilterSettings settings) {
2430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002431
2432 final long identity = Binder.clearCallingIdentity();
2433 try {
2434 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2435 mPhone.getContext(), callingPackage, subId, settings);
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
2438 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002439 }
2440
2441 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002442 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002444
2445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2448 mPhone.getContext(), callingPackage, subId);
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
2451 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002452 }
2453
2454 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002455 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2456 String callingPackage, int subId) {
2457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002458
2459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2462 mPhone.getContext(), callingPackage, subId);
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
2465 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002466 }
2467
2468 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002469 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002470 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002471
2472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2475 mPhone.getContext(), subId);
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
2478 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002479 }
2480
2481 @Override
2482 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2483 String number, int port, String text, PendingIntent sentIntent) {
2484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002485 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002486 enforceSendSmsPermission();
2487 // Make the calls as the phone process.
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2491 if (port == 0) {
2492 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2493 sentIntent, null, false);
2494 } else {
2495 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2496 smsManager.sendDataMessageWithSelfPermissions(number, null,
2497 (short) port, data, sentIntent, null);
2498 }
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
2501 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002502 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002503 /**
fionaxu0152e512016-11-14 13:36:14 -08002504 * Sets the voice activation state of a given subId.
2505 */
2506 @Override
2507 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2509 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 final Phone phone = getPhone(subId);
2514 if (phone != null) {
2515 phone.setVoiceActivationState(activationState);
2516 } else {
2517 loge("setVoiceActivationState fails with invalid subId: " + subId);
2518 }
2519 } finally {
2520 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002521 }
2522 }
2523
2524 /**
2525 * Sets the data activation state of a given subId.
2526 */
2527 @Override
2528 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2530 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 final Phone phone = getPhone(subId);
2535 if (phone != null) {
2536 phone.setDataActivationState(activationState);
2537 } else {
2538 loge("setVoiceActivationState fails with invalid subId: " + subId);
2539 }
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002542 }
2543 }
2544
2545 /**
2546 * Returns the voice activation state of a given subId.
2547 */
2548 @Override
2549 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002550 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002551
fionaxu0152e512016-11-14 13:36:14 -08002552 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 if (phone != null) {
2556 return phone.getVoiceActivationState();
2557 } else {
2558 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2559 }
2560 } finally {
2561 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002562 }
2563 }
2564
2565 /**
2566 * Returns the data activation state of a given subId.
2567 */
2568 @Override
2569 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002570 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002571
fionaxu0152e512016-11-14 13:36:14 -08002572 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 if (phone != null) {
2576 return phone.getDataActivationState();
2577 } else {
2578 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002582 }
2583 }
2584
2585 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 * Returns the unread count of voicemails
2587 */
2588 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002589 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002590 }
2591
2592 /**
2593 * Returns the unread count of voicemails for a subId
2594 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002595 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002596 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 final Phone phone = getPhone(subId);
2600 if (phone != null) {
2601 return phone.getVoiceMessageCount();
2602 } else {
2603 return 0;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
2610 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002611 * returns true, if the device is in a state where both voice and data
2612 * are supported simultaneously. This can change based on location or network condition.
2613 */
2614 @Override
2615 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 final Phone phone = getPhone(subId);
2619 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
2622 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002623 }
2624
2625 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002626 * Send the dialer code if called from the current default dialer or the caller has
2627 * carrier privilege.
2628 * @param inputCode The dialer code to send
2629 */
2630 @Override
2631 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2633 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2634 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002635 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2636 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002637 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 mPhone.sendDialerSpecialCode(inputCode);
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
fionaxu235cc5e2017-03-06 22:25:57 -08002645 }
2646
2647 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002648 * Returns the data network type.
2649 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 *
2651 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2652 */
2653 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002654 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(getDefaultSubscription());
2658 if (phone != null) {
2659 return phone.getServiceState().getDataNetworkType();
2660 } else {
2661 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002665 }
Wink Saville36469e72014-06-11 15:17:00 -07002666 }
2667
Pengquan Meng0c05b502018-09-06 09:59:22 -07002668 @Override
2669 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002670 if (!isActiveSubscription(subId)) {
2671 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2672 }
2673
Pengquan Meng0c05b502018-09-06 09:59:22 -07002674 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2675 }
2676
Brad Ebinger4c460712018-10-01 10:40:55 -07002677 @Override
2678 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2679 String callingPackage) throws RemoteException {
2680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2681 "addImsRegistrationCallback")) {
2682 return;
2683 }
2684 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2685 final long token = Binder.clearCallingIdentity();
2686 try {
2687 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2688 .addRegistrationCallbackForSubscription(c, subId);
2689 } finally {
2690 Binder.restoreCallingIdentity(token);
2691 }
2692 }
2693
2694 @Override
2695 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2696 String callingPackage) {
2697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2698 "removeImsRegistrationCallback")) {
2699 return;
2700 }
2701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2702 Binder.withCleanCallingIdentity(() ->
2703 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2704 .removeRegistrationCallbackForSubscription(c, subId));
2705 }
2706
2707 @Override
2708 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2709 String callingPackage) throws RemoteException {
2710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2711 "addMmTelCapabilityCallback")) {
2712 return;
2713 }
2714 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2715 final long token = Binder.clearCallingIdentity();
2716 try {
2717 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2718 .addCapabilitiesCallbackForSubscription(c, subId);
2719 } finally {
2720 Binder.restoreCallingIdentity(token);
2721 }
2722 }
2723
2724 @Override
2725 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2726 String callingPackage) {
2727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2728 "removeMmTelCapabilityCallback")) {
2729 return;
2730 }
2731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2732 Binder.withCleanCallingIdentity(() ->
2733 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2734 .removeCapabilitiesCallbackForSubscription(c, subId));
2735 }
2736
2737 @Override
2738 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2740 "isCapable")) {
2741 return false;
2742 }
2743 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2744 final long token = Binder.clearCallingIdentity();
2745 try {
2746 return ImsManager.getInstance(mPhone.getContext(),
2747 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2748 } catch (ImsException e) {
2749 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2750 return false;
2751 } finally {
2752 Binder.restoreCallingIdentity(token);
2753 }
2754 }
2755
2756 @Override
2757 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2759 "isAvailable")) {
2760 return false;
2761 }
2762 final long token = Binder.clearCallingIdentity();
2763 try {
2764 Phone phone = getPhone(subId);
2765 if (phone == null) return false;
2766 return phone.isImsCapabilityAvailable(capability, regTech);
2767 } finally {
2768 Binder.restoreCallingIdentity(token);
2769 }
2770 }
2771
2772 @Override
2773 public boolean isAdvancedCallingSettingEnabled(int subId) {
2774 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2775 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2776 final long token = Binder.clearCallingIdentity();
2777 try {
2778 return ImsManager.getInstance(mPhone.getContext(),
2779 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2780 } finally {
2781 Binder.restoreCallingIdentity(token);
2782 }
2783 }
2784
2785 @Override
2786 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2788 "setAdvancedCallingSetting");
2789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2792 ImsManager.getInstance(mPhone.getContext(),
2793 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
2796 }
2797 }
2798
2799 @Override
2800 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2802 "isVtSettingEnabled")) {
2803 return false;
2804 }
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2808 return ImsManager.getInstance(mPhone.getContext(),
2809 getSlotIndexOrException(subId)).isVtEnabledByUser();
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
2813 }
2814
2815 @Override
2816 public void setVtSetting(int subId, boolean isEnabled) {
2817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2818 "setVtSetting");
2819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2822 ImsManager.getInstance(mPhone.getContext(),
2823 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
2826 }
2827 }
2828
2829 @Override
2830 public boolean isVoWiFiSettingEnabled(int subId) {
2831 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2835 return ImsManager.getInstance(mPhone.getContext(),
2836 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
2839 }
2840 }
2841
2842 @Override
2843 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2845 "setVoWiFiSetting");
2846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2849 ImsManager.getInstance(mPhone.getContext(),
2850 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
2854 }
2855
2856 @Override
2857 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2858 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2862 return ImsManager.getInstance(mPhone.getContext(),
2863 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2864 } finally {
2865 Binder.restoreCallingIdentity(identity);
2866 }
2867 }
2868
2869 @Override
2870 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2872 "setVoWiFiRoamingSetting");
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2876 ImsManager.getInstance(mPhone.getContext(),
2877 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
2881 }
2882
2883 @Override
2884 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2886 "setVoWiFiNonPersistent");
2887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2890 ImsManager.getInstance(mPhone.getContext(),
2891 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
2894 }
2895 }
2896
2897 @Override
2898 public int getVoWiFiModeSetting(int subId) {
2899 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2903 return ImsManager.getInstance(mPhone.getContext(),
2904 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
2908 }
2909
2910 @Override
2911 public void setVoWiFiModeSetting(int subId, int mode) {
2912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2913 "setVoWiFiModeSetting");
2914 final long identity = Binder.clearCallingIdentity();
2915 try {
2916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2917 ImsManager.getInstance(mPhone.getContext(),
2918 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
2922 }
2923
2924 @Override
2925 public int getVoWiFiRoamingModeSetting(int subId) {
2926 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2930 return ImsManager.getInstance(mPhone.getContext(),
2931 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
2935 }
2936
2937 @Override
2938 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2940 "setVoWiFiRoamingModeSetting");
2941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2944 ImsManager.getInstance(mPhone.getContext(),
2945 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
2948 }
2949 }
2950
2951 @Override
2952 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2954 "setRttCapabilityEnabled");
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2958 ImsManager.getInstance(mPhone.getContext(),
2959 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
2963 }
2964
2965 @Override
2966 public boolean isTtyOverVolteEnabled(int subId) {
2967 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2971 return ImsManager.getInstance(mPhone.getContext(),
2972 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
2976 }
2977
2978 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2979 int slotId = SubscriptionManager.getSlotIndex(subId);
2980 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2981 throw new IllegalArgumentException("Invalid Subscription Id.");
2982 }
2983 return slotId;
2984 }
2985
Wink Saville36469e72014-06-11 15:17:00 -07002986 /**
2987 * Returns the network type for a subId
2988 */
2989 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002990 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002992 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002993 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2994 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002995
Malcolm Chend965c8b2018-02-28 15:00:40 -08002996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 final Phone phone = getPhone(subId);
2999 if (phone != null) {
3000 return phone.getServiceState().getDataNetworkType();
3001 } else {
3002 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3003 }
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 }
3008
3009 /**
3010 * Returns the data network type
3011 */
3012 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003013 public int getDataNetworkType(String callingPackage) {
3014 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003015 }
3016
3017 /**
3018 * Returns the data network type for a subId
3019 */
3020 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003021 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003023 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003024 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3025 }
3026
Malcolm Chend965c8b2018-02-28 15:00:40 -08003027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 final Phone phone = getPhone(subId);
3030 if (phone != null) {
3031 return phone.getServiceState().getDataNetworkType();
3032 } else {
3033 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3034 }
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 }
3039
3040 /**
Wink Saville36469e72014-06-11 15:17:00 -07003041 * Returns the Voice network type for a subId
3042 */
3043 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003044 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003046 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003047 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3048 }
3049
Malcolm Chend965c8b2018-02-28 15:00:40 -08003050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 final Phone phone = getPhone(subId);
3053 if (phone != null) {
3054 return phone.getServiceState().getVoiceNetworkType();
3055 } else {
3056 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3057 }
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
3063 /**
3064 * @return true if a ICC card is present
3065 */
3066 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003067 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003068 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3069 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003070 }
3071
3072 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003073 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003074 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003075 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003076 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 final Phone phone = PhoneFactory.getPhone(slotIndex);
3080 if (phone != null) {
3081 return phone.getIccCard().hasIccCard();
3082 } else {
3083 return false;
3084 }
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 }
3089
3090 /**
3091 * Return if the current radio is LTE on CDMA. This
3092 * is a tri-state return value as for a period of time
3093 * the mode may be unknown.
3094 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003095 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003097 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003099 @Override
3100 public int getLteOnCdmaMode(String callingPackage) {
3101 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003102 }
3103
Sanket Padawe356d7632015-06-22 14:03:32 -07003104 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003105 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003107 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003108 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3109 }
3110
Malcolm Chend965c8b2018-02-28 15:00:40 -08003111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 final Phone phone = getPhone(subId);
3114 if (phone == null) {
3115 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3116 } else {
3117 return phone.getLteOnCdmaMode();
3118 }
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003121 }
Wink Saville36469e72014-06-11 15:17:00 -07003122 }
3123
3124 public void setPhone(Phone phone) {
3125 mPhone = phone;
3126 }
3127
3128 /**
3129 * {@hide}
3130 * Returns Default subId, 0 in the case of single standby.
3131 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003132 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003133 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003134 }
3135
Shishir Agrawala9f32182016-04-12 12:00:16 -07003136 private int getSlotForDefaultSubscription() {
3137 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3138 }
3139
Wink Savilleb564aae2014-10-23 10:18:09 -07003140 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003141 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003143
Pengquan Meng466e2482018-09-21 15:54:48 -07003144 private boolean isActiveSubscription(int subId) {
3145 return mSubscriptionController.isActiveSubId(subId);
3146 }
3147
Ihab Awadf2177b72013-11-25 13:33:23 -08003148 /**
3149 * @see android.telephony.TelephonyManager.WifiCallingChoices
3150 */
3151 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3155 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3156 getWhenToMakeWifiCallsDefaultPreference());
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003160 }
3161
3162 /**
3163 * @see android.telephony.TelephonyManager.WifiCallingChoices
3164 */
3165 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3169 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3170 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
3173 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003174 }
3175
Sailesh Nepald1e68152013-12-12 19:08:02 -08003176 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003177 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003178 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003179 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003180
Shishir Agrawal566b7612013-10-28 14:41:00 -07003181 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003182 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3183 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3185 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003186 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003187
Malcolm Chend965c8b2018-02-28 15:00:40 -08003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 if (TextUtils.equals(ISDR_AID, aid)) {
3191 // Only allows LPA to open logical channel to ISD-R.
3192 ComponentInfo bestComponent =
3193 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3194 if (bestComponent == null
3195 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3196 loge("The calling package is not allowed to access ISD-R.");
3197 throw new SecurityException(
3198 "The calling package is not allowed to access ISD-R.");
3199 }
Derek Tan740e1672017-06-27 14:56:27 -07003200 }
Derek Tan740e1672017-06-27 14:56:27 -07003201
Malcolm Chend965c8b2018-02-28 15:00:40 -08003202 if (DBG) {
3203 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3204 }
3205 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3206 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3207 if (DBG) log("iccOpenLogicalChannel: " + response);
3208 return response;
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003212 }
3213
3214 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003215 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3217 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003218
Malcolm Chend965c8b2018-02-28 15:00:40 -08003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3222 if (channel < 0) {
3223 return false;
3224 }
3225 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3226 if (DBG) log("iccCloseLogicalChannel: " + success);
3227 return success;
3228 } finally {
3229 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003230 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003231 }
3232
3233 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003234 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003235 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3237 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003238
Malcolm Chend965c8b2018-02-28 15:00:40 -08003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 if (DBG) {
3242 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3243 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3244 + p3 + " data=" + data);
3245 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003246
Malcolm Chend965c8b2018-02-28 15:00:40 -08003247 if (channel < 0) {
3248 return "";
3249 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003250
Malcolm Chend965c8b2018-02-28 15:00:40 -08003251 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3252 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3253 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003254
Malcolm Chend965c8b2018-02-28 15:00:40 -08003255 // Append the returned status code to the end of the response payload.
3256 String s = Integer.toHexString(
3257 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3258 if (response.payload != null) {
3259 s = IccUtils.bytesToHexString(response.payload) + s;
3260 }
3261 return s;
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003264 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003265 }
Jake Hambye994d462014-02-03 13:10:13 -08003266
Evan Charltonc66da362014-05-16 14:06:40 -07003267 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003268 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3269 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3271 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003272 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003273
Malcolm Chend965c8b2018-02-28 15:00:40 -08003274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3277 && TextUtils.equals(ISDR_AID, data)) {
3278 // Only allows LPA to select ISD-R.
3279 ComponentInfo bestComponent =
3280 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3281 if (bestComponent == null
3282 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3283 loge("The calling package is not allowed to select ISD-R.");
3284 throw new SecurityException(
3285 "The calling package is not allowed to select ISD-R.");
3286 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003287 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003288
Malcolm Chend965c8b2018-02-28 15:00:40 -08003289 if (DBG) {
3290 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3291 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3292 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003293
Malcolm Chend965c8b2018-02-28 15:00:40 -08003294 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3295 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3296 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003297
Malcolm Chend965c8b2018-02-28 15:00:40 -08003298 // Append the returned status code to the end of the response payload.
3299 String s = Integer.toHexString(
3300 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3301 if (response.payload != null) {
3302 s = IccUtils.bytesToHexString(response.payload) + s;
3303 }
3304 return s;
3305 } finally {
3306 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003307 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003308 }
3309
3310 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003311 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003312 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3314 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003315
Malcolm Chend965c8b2018-02-28 15:00:40 -08003316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 if (DBG) {
3319 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3320 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3321 }
3322
3323 IccIoResult response =
3324 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3325 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3326 subId);
3327
3328 if (DBG) {
3329 log("Exchange SIM_IO [R]" + response);
3330 }
3331
3332 byte[] result = null;
3333 int length = 2;
3334 if (response.payload != null) {
3335 length = 2 + response.payload.length;
3336 result = new byte[length];
3337 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3338 } else {
3339 result = new byte[length];
3340 }
3341
3342 result[length - 1] = (byte) response.sw2;
3343 result[length - 2] = (byte) response.sw1;
3344 return result;
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003347 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003348 }
3349
Nathan Haroldb3014052017-01-25 15:57:32 -08003350 /**
3351 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3352 * on a particular subscription
3353 */
sqianb6e41952018-03-12 14:54:01 -07003354 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3356 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3357 return null;
3358 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003359
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 if (appType != TelephonyManager.APPTYPE_USIM
3363 && appType != TelephonyManager.APPTYPE_SIM) {
3364 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3365 return null;
3366 }
3367 Object response = sendRequest(
3368 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3369 if (response instanceof String[]) {
3370 return (String[]) response;
3371 }
3372 // Response is an Exception of some kind,
3373 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003374 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003375 } finally {
3376 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003377 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003378 }
3379
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003380 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003381 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3383 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003384
Malcolm Chend965c8b2018-02-28 15:00:40 -08003385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3388 if (response.payload == null) {
3389 return "";
3390 }
Evan Charltonc66da362014-05-16 14:06:40 -07003391
Malcolm Chend965c8b2018-02-28 15:00:40 -08003392 // Append the returned status code to the end of the response payload.
3393 String s = Integer.toHexString(
3394 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3395 s = IccUtils.bytesToHexString(response.payload) + s;
3396 return s;
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
Evan Charltonc66da362014-05-16 14:06:40 -07003400 }
3401
Jake Hambye994d462014-02-03 13:10:13 -08003402 /**
3403 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3404 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3405 *
3406 * @param itemID the ID of the item to read
3407 * @return the NV item as a String, or null on error.
3408 */
3409 @Override
3410 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003411 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3413 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003414
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003418 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003419 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3420 return value;
3421 } finally {
3422 Binder.restoreCallingIdentity(identity);
3423 }
Jake Hambye994d462014-02-03 13:10:13 -08003424 }
3425
3426 /**
3427 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3428 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3429 *
3430 * @param itemID the ID of the item to read
3431 * @param itemValue the value to write, as a String
3432 * @return true on success; false on any failure
3433 */
3434 @Override
3435 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003436 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3438 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003439
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3443 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003444 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003445 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3446 return success;
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
Jake Hambye994d462014-02-03 13:10:13 -08003450 }
3451
3452 /**
3453 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3454 * Used for device configuration by some CDMA operators.
3455 *
3456 * @param preferredRoamingList byte array containing the new PRL
3457 * @return true on success; false on any failure
3458 */
3459 @Override
3460 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3462 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003463
3464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3467 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3468 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3469 return success;
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
3472 }
Jake Hambye994d462014-02-03 13:10:13 -08003473 }
3474
3475 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003476 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003477 * Used for device configuration by some CDMA operators.
3478 *
chen xu1cc0abe2018-10-26 17:39:23 -07003479 * @param slotIndex - device slot.
3480 *
Jake Hambye994d462014-02-03 13:10:13 -08003481 * @return true on success; false on any failure
3482 */
3483 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003484 public boolean resetModemConfig(int slotIndex) {
3485 Phone phone = PhoneFactory.getPhone(slotIndex);
3486 if (phone != null) {
3487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3488 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003489
chen xu1cc0abe2018-10-26 17:39:23 -07003490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3493 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3494 return success;
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003498 }
chen xu1cc0abe2018-10-26 17:39:23 -07003499 return false;
3500 }
3501
3502 /**
3503 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3504 *
3505 * @param slotIndex - device slot.
3506 *
3507 * @return true on success; false on any failure
3508 */
3509 @Override
3510 public boolean rebootModem(int slotIndex) {
3511 Phone phone = PhoneFactory.getPhone(slotIndex);
3512 if (phone != null) {
3513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3514 mApp, phone.getSubId(), "rebootModem");
3515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3519 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3520 return success;
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
3524 }
3525 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003526 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003527
Svet Ganovb320e182015-04-16 12:30:10 -07003528 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003530 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003531 return new String[0];
3532 }
3533
Malcolm Chend965c8b2018-02-28 15:00:40 -08003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 return mPhone.getPcscfAddress(apnType);
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
Wink Saville36469e72014-06-11 15:17:00 -07003540 }
3541
Brad Ebinger51f743a2017-01-23 13:50:20 -08003542 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003543 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3544 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003545 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003546 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003547 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003548
3549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 PhoneFactory.getImsResolver().enableIms(slotId);
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003555 }
3556
3557 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003558 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3559 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003560 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003561 public void disableIms(int slotId) {
3562 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 PhoneFactory.getImsResolver().disableIms(slotId);
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
3569 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003570 }
3571
3572 /**
3573 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3574 * feature or {@link null} if the service is not available. If the feature is available, the
3575 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3576 */
3577 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003578 IImsServiceFeatureCallback callback) {
3579 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003580
3581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
3586 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003587 }
3588
3589 /**
3590 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3591 * feature during emergency calling or {@link null} if the service is not available. If the
3592 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3593 * listener for feature updates.
3594 */
3595 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3596 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003597
3598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
3603 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003604 }
3605
Brad Ebinger5f64b052017-12-14 14:26:15 -08003606 /**
3607 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3608 * specified.
3609 */
3610 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3611 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003612
3613 final long identity = Binder.clearCallingIdentity();
3614 try {
3615 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3616 } finally {
3617 Binder.restoreCallingIdentity(identity);
3618 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003619 }
3620
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003621 /**
3622 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3623 * specified.
3624 */
3625 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3626 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003627
3628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
3633 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003634 }
3635
Brad Ebinger884c07b2018-02-15 16:17:40 -08003636 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003637 * Sets the ImsService Package Name that Telephony will bind to.
3638 *
3639 * @param slotId the slot ID that the ImsService should bind for.
3640 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3641 * ImsService is the device default ImsService.
3642 * @param packageName The package name of the application that contains the ImsService to bind
3643 * to.
3644 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3645 * @hide
3646 */
3647 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003648 int[] subIds = SubscriptionManager.getSubId(slotId);
3649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3650 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3651 "setImsService");
3652
Malcolm Chend965c8b2018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3656 isCarrierImsService, packageName);
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003660 }
3661
3662 /**
3663 * Return the ImsService configuration.
3664 *
3665 * @param slotId The slot that the ImsService is associated with.
3666 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3667 * the device default.
3668 * @return the package name of the ImsService configuration.
3669 */
3670 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003671 int[] subIds = SubscriptionManager.getSubId(slotId);
3672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3673 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3674 "getImsService");
3675
Malcolm Chend965c8b2018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3679 isCarrierImsService);
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003683 }
3684
Wink Saville36469e72014-06-11 15:17:00 -07003685 public void setImsRegistrationState(boolean registered) {
3686 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003687
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 mPhone.setImsRegistrationState(registered);
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
Wink Saville36469e72014-06-11 15:17:00 -07003694 }
3695
3696 /**
Stuart Scott54788802015-03-30 13:18:01 -07003697 * Set the network selection mode to automatic.
3698 *
3699 */
3700 @Override
3701 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3703 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003704
Pengquan Meng466e2482018-09-21 15:54:48 -07003705 if (!isActiveSubscription(subId)) {
3706 return;
3707 }
3708
Malcolm Chend965c8b2018-02-28 15:00:40 -08003709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3712 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Stuart Scott54788802015-03-30 13:18:01 -07003716 }
3717
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003718 /**
3719 * Ask the radio to connect to the input network and change selection mode to manual.
3720 *
3721 * @param subId the id of the subscription.
3722 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3723 * the operator to attach to.
3724 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3725 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3726 * normal network selection next time.
3727 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003728 */
3729 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003730 public boolean setNetworkSelectionModeManual(
3731 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3733 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003734
3735 if (!isActiveSubscription(subId)) {
3736 return false;
3737 }
3738
Malcolm Chend965c8b2018-02-28 15:00:40 -08003739 final long identity = Binder.clearCallingIdentity();
3740 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003741 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003742 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003743 if (DBG) {
3744 log("setNetworkSelectionModeManual: subId: " + subId
3745 + " operator: " + operatorInfo);
3746 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003747 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003751 }
3752
3753 /**
3754 * Scans for available networks.
3755 */
3756 @Override
3757 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3759 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003760
Pengquan Meng0c05b502018-09-06 09:59:22 -07003761 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003762 try {
3763 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003764 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003765 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003769 }
3770
3771 /**
yinxub1bed742017-04-17 11:45:04 -07003772 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003773 *
yinxub1bed742017-04-17 11:45:04 -07003774 * @param subId id of the subscription
3775 * @param request contains the radio access networks with bands/channels to scan
3776 * @param messenger callback messenger for scan results or errors
3777 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003778 * @return the id of the requested scan which can be used to stop the scan.
3779 */
3780 @Override
3781 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3782 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3784 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 return mNetworkScanRequestTracker.startNetworkScan(
3789 request, messenger, binder, getPhone(subId));
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
yinxu504e1392017-04-12 16:03:22 -07003793 }
3794
3795 /**
3796 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003797 *
3798 * @param subId id of the subscription
3799 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003800 */
3801 @Override
3802 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3804 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
3811 }
yinxu504e1392017-04-12 16:03:22 -07003812 }
3813
3814 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003815 * Get the calculated preferred network type.
3816 * Used for debugging incorrect network type.
3817 *
3818 * @return the preferred network type, defined in RILConstants.java.
3819 */
3820 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003821 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003823 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003824 return RILConstants.PREFERRED_NETWORK_MODE;
3825 }
3826
Malcolm Chend965c8b2018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 // FIXME: need to get SubId from somewhere.
3830 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
Junda Liu84d15a22014-07-02 11:21:04 -07003834 }
3835
3836 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003837 * Get the preferred network type.
3838 * Used for device configuration by some CDMA operators.
3839 *
3840 * @return the preferred network type, defined in RILConstants.java.
3841 */
3842 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003843 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3845 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003846
3847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 if (DBG) log("getPreferredNetworkType");
3850 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3851 int networkType = (result != null ? result[0] : -1);
3852 if (DBG) log("getPreferredNetworkType: " + networkType);
3853 return networkType;
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003857 }
3858
3859 /**
3860 * Set the preferred network type.
3861 * Used for device configuration by some CDMA operators.
3862 *
3863 * @param networkType the preferred network type, defined in RILConstants.java.
3864 * @return true on success; false on any failure.
3865 */
3866 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003867 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3869 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003870
3871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3874 Boolean success = (Boolean) sendRequest(
3875 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3876 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3877 if (success) {
3878 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3879 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3880 }
3881 return success;
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003884 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003885 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003886
3887 /**
Junda Liu475951f2014-11-07 16:45:03 -08003888 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003889 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003890 * tethering.
3891 *
3892 * @return 0: Not required. 1: required. 2: Not set.
3893 * @hide
3894 */
3895 @Override
3896 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003897 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3902 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003903 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003904 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3905 dunRequired = 1;
3906 }
3907 return dunRequired;
3908 } finally {
3909 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003910 }
Junda Liu475951f2014-11-07 16:45:03 -08003911 }
3912
3913 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003914 * Set mobile data enabled
3915 * Used by the user through settings etc to turn on/off mobile data
3916 *
3917 * @param enable {@code true} turn turn data on, else {@code false}
3918 */
3919 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003920 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3922 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003923
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 int phoneId = mSubscriptionController.getPhoneId(subId);
3927 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3928 Phone phone = PhoneFactory.getPhone(phoneId);
3929 if (phone != null) {
3930 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3931 phone.setUserDataEnabled(enable);
3932 } else {
3933 loge("setUserDataEnabled: no phone for subId=" + subId);
3934 }
3935 } finally {
3936 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003937 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003938 }
3939
3940 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003941 * Get the user enabled state of Mobile Data.
3942 *
3943 * TODO: remove and use isUserDataEnabled.
3944 * This can't be removed now because some vendor codes
3945 * calls through ITelephony directly while they should
3946 * use TelephonyManager.
3947 *
3948 * @return true on enabled
3949 */
3950 @Override
3951 public boolean getDataEnabled(int subId) {
3952 return isUserDataEnabled(subId);
3953 }
3954
3955 /**
3956 * Get whether mobile data is enabled per user setting.
3957 *
3958 * There are other factors deciding whether mobile data is actually enabled, but they are
3959 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003960 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003961 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003962 *
3963 * @return {@code true} if data is enabled else {@code false}
3964 */
3965 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003966 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003967 try {
3968 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3969 null);
3970 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3972 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003973 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003974
3975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 int phoneId = mSubscriptionController.getPhoneId(subId);
3978 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3979 Phone phone = PhoneFactory.getPhone(phoneId);
3980 if (phone != null) {
3981 boolean retVal = phone.isUserDataEnabled();
3982 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3983 return retVal;
3984 } else {
3985 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3986 return false;
3987 }
3988 } finally {
3989 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003990 }
3991 }
3992
3993 /**
3994 * Get whether mobile data is enabled.
3995 *
3996 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3997 * whether mobile data is actually enabled.
3998 *
3999 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4000 *
4001 * @return {@code true} if data is enabled else {@code false}
4002 */
4003 @Override
4004 public boolean isDataEnabled(int subId) {
4005 try {
4006 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4007 null);
4008 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4010 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004011 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004012
4013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 int phoneId = mSubscriptionController.getPhoneId(subId);
4016 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4017 Phone phone = PhoneFactory.getPhone(phoneId);
4018 if (phone != null) {
4019 boolean retVal = phone.isDataEnabled();
4020 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4021 return retVal;
4022 } else {
4023 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4024 return false;
4025 }
4026 } finally {
4027 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004028 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004029 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004030
4031 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004032 public int getCarrierPrivilegeStatus(int subId) {
4033 final Phone phone = getPhone(subId);
4034 if (phone == null) {
4035 loge("getCarrierPrivilegeStatus: Invalid subId");
4036 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4037 }
4038 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004039 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004040 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004041 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4042 }
4043 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004044 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004045 }
Junda Liu29340342014-07-10 15:23:27 -07004046
4047 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004048 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4049 final Phone phone = getPhone(subId);
4050 if (phone == null) {
4051 loge("getCarrierPrivilegeStatus: Invalid subId");
4052 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4053 }
4054 UiccProfile profile =
4055 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4056 if (profile == null) {
4057 loge("getCarrierPrivilegeStatus: No UICC");
4058 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4059 }
4060 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4061 }
4062
4063 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004064 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004065 if (TextUtils.isEmpty(pkgName))
4066 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004067 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004068 if (card == null) {
4069 loge("checkCarrierPrivilegesForPackage: No UICC");
4070 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4071 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004072 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4073 }
4074
4075 @Override
4076 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004077 if (TextUtils.isEmpty(pkgName))
4078 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004079 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4080 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4081 UiccCard card = UiccController.getInstance().getUiccCard(i);
4082 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004083 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004084 continue;
4085 }
4086
4087 result = card.getCarrierPrivilegeStatus(
4088 mPhone.getContext().getPackageManager(), pkgName);
4089 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4090 break;
4091 }
4092 }
4093
4094 return result;
Junda Liu29340342014-07-10 15:23:27 -07004095 }
Derek Tan89e89d42014-07-08 17:00:10 -07004096
4097 @Override
Junda Liue64de782015-04-16 17:19:16 -07004098 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4099 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4100 loge("phoneId " + phoneId + " is not valid.");
4101 return null;
4102 }
4103 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004104 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004105 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004106 return null ;
4107 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004108 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004109 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004110 }
4111
Amith Yamasani6e118872016-02-19 12:53:51 -08004112 @Override
4113 public List<String> getPackagesWithCarrierPrivileges() {
4114 PackageManager pm = mPhone.getContext().getPackageManager();
4115 List<String> privilegedPackages = new ArrayList<>();
4116 List<PackageInfo> packages = null;
4117 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4118 UiccCard card = UiccController.getInstance().getUiccCard(i);
4119 if (card == null) {
4120 // No UICC in that slot.
4121 continue;
4122 }
4123 if (card.hasCarrierPrivilegeRules()) {
4124 if (packages == null) {
4125 // Only check packages in user 0 for now
4126 packages = pm.getInstalledPackagesAsUser(
4127 PackageManager.MATCH_DISABLED_COMPONENTS
4128 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4129 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4130 }
4131 for (int p = packages.size() - 1; p >= 0; p--) {
4132 PackageInfo pkgInfo = packages.get(p);
4133 if (pkgInfo != null && pkgInfo.packageName != null
4134 && card.getCarrierPrivilegeStatus(pkgInfo)
4135 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4136 privilegedPackages.add(pkgInfo.packageName);
4137 }
4138 }
4139 }
4140 }
4141 return privilegedPackages;
4142 }
4143
Wink Savilleb564aae2014-10-23 10:18:09 -07004144 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004145 final Phone phone = getPhone(subId);
4146 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004147 if (card == null) {
4148 loge("getIccId: No UICC");
4149 return null;
4150 }
4151 String iccId = card.getIccId();
4152 if (TextUtils.isEmpty(iccId)) {
4153 loge("getIccId: ICC ID is null or empty.");
4154 return null;
4155 }
4156 return iccId;
4157 }
4158
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004159 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004160 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4161 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004162 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4163 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004164
Malcolm Chend965c8b2018-02-28 15:00:40 -08004165 final long identity = Binder.clearCallingIdentity();
4166 try {
4167 final String iccId = getIccId(subId);
4168 final Phone phone = getPhone(subId);
4169 if (phone == null) {
4170 return false;
4171 }
4172 final String subscriberId = phone.getSubscriberId();
4173
4174 if (DBG_MERGE) {
4175 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4176 + subscriberId + " to " + number);
4177 }
4178
4179 if (TextUtils.isEmpty(iccId)) {
4180 return false;
4181 }
4182
4183 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4184
4185 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4186 if (alphaTag == null) {
4187 editor.remove(alphaTagPrefKey);
4188 } else {
4189 editor.putString(alphaTagPrefKey, alphaTag);
4190 }
4191
4192 // Record both the line number and IMSI for this ICCID, since we need to
4193 // track all merged IMSIs based on line number
4194 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4195 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4196 if (number == null) {
4197 editor.remove(numberPrefKey);
4198 editor.remove(subscriberPrefKey);
4199 } else {
4200 editor.putString(numberPrefKey, number);
4201 editor.putString(subscriberPrefKey, subscriberId);
4202 }
4203
4204 editor.commit();
4205 return true;
4206 } finally {
4207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004208 }
Derek Tan7226c842014-07-02 17:42:23 -07004209 }
4210
4211 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004212 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004213 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004215 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004216 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004217 return null;
4218 }
Derek Tan97ebb422014-09-05 16:55:38 -07004219
Malcolm Chend965c8b2018-02-28 15:00:40 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 String iccId = getIccId(subId);
4223 if (iccId != null) {
4224 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4225 if (DBG_MERGE) {
4226 log("getLine1NumberForDisplay returning "
4227 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4228 }
4229 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004230 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004231 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4232 return null;
4233 } finally {
4234 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004235 }
Derek Tan7226c842014-07-02 17:42:23 -07004236 }
4237
4238 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004239 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004241 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004242 return null;
4243 }
Derek Tan97ebb422014-09-05 16:55:38 -07004244
Malcolm Chend965c8b2018-02-28 15:00:40 -08004245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 String iccId = getIccId(subId);
4248 if (iccId != null) {
4249 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4250 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4251 }
4252 return null;
4253 } finally {
4254 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004255 }
Derek Tan7226c842014-07-02 17:42:23 -07004256 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004257
4258 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004259 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004260 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4261 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004263 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4264 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004265 return null;
4266 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004267
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004268 final long identity = Binder.clearCallingIdentity();
4269 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004270 final Context context = mPhone.getContext();
4271 final TelephonyManager tele = TelephonyManager.from(context);
4272 final SubscriptionManager sub = SubscriptionManager.from(context);
4273
4274 // Figure out what subscribers are currently active
4275 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4276 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4277 // the process, where TelephonyManager was instantiated.
4278 // Otherwise AppOps check will fail.
4279
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004280 final int[] subIds = sub.getActiveSubscriptionIdList();
4281 for (int subId : subIds) {
4282 activeSubscriberIds.add(tele.getSubscriberId(subId));
4283 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004284
4285 // First pass, find a number override for an active subscriber
4286 String mergeNumber = null;
4287 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4288 for (String key : prefs.keySet()) {
4289 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4290 final String subscriberId = (String) prefs.get(key);
4291 if (activeSubscriberIds.contains(subscriberId)) {
4292 final String iccId = key.substring(
4293 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4294 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4295 mergeNumber = (String) prefs.get(numberKey);
4296 if (DBG_MERGE) {
4297 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4298 + " for active subscriber " + subscriberId);
4299 }
4300 if (!TextUtils.isEmpty(mergeNumber)) {
4301 break;
4302 }
4303 }
4304 }
4305 }
4306
4307 // Shortcut when no active merged subscribers
4308 if (TextUtils.isEmpty(mergeNumber)) {
4309 return null;
4310 }
4311
4312 // Second pass, find all subscribers under that line override
4313 final ArraySet<String> result = new ArraySet<>();
4314 for (String key : prefs.keySet()) {
4315 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4316 final String number = (String) prefs.get(key);
4317 if (mergeNumber.equals(number)) {
4318 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4319 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4320 final String subscriberId = (String) prefs.get(subscriberKey);
4321 if (!TextUtils.isEmpty(subscriberId)) {
4322 result.add(subscriberId);
4323 }
4324 }
4325 }
4326 }
4327
4328 final String[] resultArray = result.toArray(new String[result.size()]);
4329 Arrays.sort(resultArray);
4330 if (DBG_MERGE) {
4331 Slog.d(LOG_TAG,
4332 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4333 }
4334 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004335 } finally {
4336 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004337 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004338 }
4339
4340 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004341 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004342 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4343 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004344
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 final Phone phone = getPhone(subId);
4348 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
4351 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004352 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004353
4354 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004355 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004356 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4357 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004358 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004359
4360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 final Phone phone = getPhone(subId);
4363 if (phone == null) {
4364 return false;
4365 }
4366 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4367 cdmaNonRoamingList);
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004370 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004371 }
4372
4373 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004374 @Deprecated
4375 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4376 enforceModifyPermission();
4377
4378 int returnValue = 0;
4379 try {
vagdevie435a3e2018-08-15 16:01:53 -07004380 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004381 if(result.exception == null) {
4382 if (result.result != null) {
4383 byte[] responseData = (byte[])(result.result);
4384 if(responseData.length > oemResp.length) {
4385 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4386 responseData.length + "bytes. Buffer Size is " +
4387 oemResp.length + "bytes.");
4388 }
4389 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4390 returnValue = responseData.length;
4391 }
4392 } else {
4393 CommandException ex = (CommandException) result.exception;
4394 returnValue = ex.getCommandError().ordinal();
4395 if(returnValue > 0) returnValue *= -1;
4396 }
4397 } catch (RuntimeException e) {
4398 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4399 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4400 if(returnValue > 0) returnValue *= -1;
4401 }
4402
4403 return returnValue;
4404 }
4405
4406 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004407 public void setRadioCapability(RadioAccessFamily[] rafs) {
4408 try {
4409 ProxyController.getInstance().setRadioCapability(rafs);
4410 } catch (RuntimeException e) {
4411 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4412 }
4413 }
4414
4415 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004416 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004417 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004418 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004419 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004420 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004421 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004422 final long identity = Binder.clearCallingIdentity();
4423 try {
chen xufeeed752018-10-26 14:17:57 -07004424 TelephonyPermissions
4425 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4426 mApp, phone.getSubId(), "getRadioAccessFamily");
4427 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
chen xufeeed752018-10-26 14:17:57 -07004431 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004432 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004433
4434 @Override
4435 public void enableVideoCalling(boolean enable) {
4436 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004437
4438 final long identity = Binder.clearCallingIdentity();
4439 try {
4440 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004444 }
4445
4446 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004447 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4449 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4450 return false;
4451 }
Svet Ganovb320e182015-04-16 12:30:10 -07004452
Malcolm Chend965c8b2018-02-28 15:00:40 -08004453 final long identity = Binder.clearCallingIdentity();
4454 try {
4455 // Check the user preference and the system-level IMS setting. Even if the user has
4456 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4457 // In the long run, we may instead need to check if there exists a connection service
4458 // which can support video calling.
4459 ImsManager imsManager =
4460 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4461 return imsManager.isVtEnabledByPlatform()
4462 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4463 && imsManager.isVtEnabledByUser();
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004467 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004468
Andrew Leea1239f22015-03-02 17:44:07 -08004469 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004470 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4472 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4473 return false;
4474 }
4475
4476 final long identity = Binder.clearCallingIdentity();
4477 try {
4478 CarrierConfigManager configManager =
4479 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4480 return configManager.getConfigForSubId(mPhone.getSubId())
4481 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
Andrew Leea1239f22015-03-02 17:44:07 -08004485 }
4486
4487 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004488 public boolean isWorldPhone(int subId, String callingPackage) {
4489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4490 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4491 return false;
4492 }
4493
4494 final long identity = Binder.clearCallingIdentity();
4495 try {
4496 CarrierConfigManager configManager =
4497 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4498 return configManager.getConfigForSubId(mPhone.getSubId())
4499 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
Andrew Leea1239f22015-03-02 17:44:07 -08004503 }
4504
Andrew Lee9431b832015-03-09 18:46:45 -07004505 @Override
4506 public boolean isTtyModeSupported() {
4507 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004508 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004509 }
4510
4511 @Override
4512 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004513 final long identity = Binder.clearCallingIdentity();
4514 try {
4515 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
Andrew Lee9431b832015-03-09 18:46:45 -07004519 }
4520
Hall Liuf6668912018-10-31 17:05:23 -07004521 /**
4522 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4523 * support for the feature and device firmware support.
4524 *
4525 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4526 */
4527 @Override
4528 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004529 final long identity = Binder.clearCallingIdentity();
4530 try {
4531 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4532 mPhone.getSubId()).getBoolean(
4533 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4534 boolean isDeviceSupported =
4535 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4536 return isCarrierSupported && isDeviceSupported;
4537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
Hall Liu98187582018-01-22 19:15:32 -08004540 }
4541
Hall Liuf6668912018-10-31 17:05:23 -07004542 /**
4543 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4544 * both also support RTT.
4545 */
4546 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004547 final long identity = Binder.clearCallingIdentity();
4548 try {
Hall Liuf6668912018-10-31 17:05:23 -07004549 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004550 mPhone.getContext().getContentResolver(),
4551 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004555 }
4556
Sanket Padawe7310cc72015-01-14 09:53:20 -08004557 /**
4558 * Returns the unique device ID of phone, for example, the IMEI for
4559 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4560 *
4561 * <p>Requires Permission:
4562 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4563 */
4564 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004565 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004566 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004567 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004568 return null;
4569 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004570 int subId = phone.getSubId();
4571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4572 mApp, subId, callingPackage, "getDeviceId")) {
4573 return null;
4574 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004575
4576 final long identity = Binder.clearCallingIdentity();
4577 try {
4578 return phone.getDeviceId();
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004582 }
4583
Ping Sunc67b7c22016-03-02 19:16:45 +08004584 /**
4585 * {@hide}
4586 * Returns the IMS Registration Status on a particular subid
4587 *
4588 * @param subId
4589 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004590 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004591 Phone phone = getPhone(subId);
4592 if (phone != null) {
4593 return phone.isImsRegistered();
4594 } else {
4595 return false;
4596 }
4597 }
4598
Santos Cordon7a1885b2015-02-03 11:15:19 -08004599 @Override
4600 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004601 final long identity = Binder.clearCallingIdentity();
4602 try {
4603 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4604 } finally {
4605 Binder.restoreCallingIdentity(identity);
4606 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004607 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004608
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004609 /**
4610 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004611 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004612 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 Phone phone = getPhone(subId);
4616 if (phone != null) {
4617 return phone.isWifiCallingEnabled();
4618 } else {
4619 return false;
4620 }
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004623 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004624 }
4625
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004626 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004627 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004628 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004629 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 Phone phone = getPhone(subId);
4633 if (phone != null) {
4634 return phone.isVideoEnabled();
4635 } else {
4636 return false;
4637 }
4638 } finally {
4639 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004640 }
4641 }
4642
4643 /**
4644 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4645 * defined in {@link ImsRegistrationImplBase}.
4646 */
4647 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 Phone phone = getPhone(subId);
4651 if (phone != null) {
4652 return phone.getImsRegistrationTech();
4653 } else {
4654 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4655 }
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004658 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004659 }
4660
Stuart Scott8eef64f2015-04-08 15:13:54 -07004661 @Override
4662 public void factoryReset(int subId) {
4663 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004664 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4665 return;
4666 }
4667
Svet Ganovcc087f82015-05-12 20:35:54 -07004668 final long identity = Binder.clearCallingIdentity();
4669 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004670 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4671 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004672 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004673 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004674 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4675 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004676 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004677 }
4678 } finally {
4679 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004680 }
4681 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004682
4683 @Override
4684 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 // We query all subscriptions instead of just the active ones, because
4688 // this might be called early on in the provisioning flow when the
4689 // subscriptions potentially aren't active yet.
4690 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4691 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004692 return null;
4693 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004694
Malcolm Chend965c8b2018-02-28 15:00:40 -08004695 // This function may be called very early, say, from the setup wizard, at
4696 // which point we won't have a default subscription set. If that's the case
4697 // we just choose the first, which will be valid in "most cases".
4698 final int defaultSubId = getDefaultSubscription();
4699 SubscriptionInfo info = null;
4700 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4701 info = slist.get(0);
4702 } else {
4703 for (SubscriptionInfo item : slist) {
4704 if (item.getSubscriptionId() == defaultSubId) {
4705 info = item;
4706 break;
4707 }
4708 }
4709
4710 if (info == null) {
4711 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004712 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004713 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004714
Malcolm Chend965c8b2018-02-28 15:00:40 -08004715 // Try and fetch the locale from the carrier properties or from the SIM language
4716 // preferences (EF-PL and EF-LI)...
4717 final int mcc = info.getMcc();
4718 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4719 String simLanguage = null;
4720 if (defaultPhone != null) {
4721 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4722 if (localeFromDefaultSim != null) {
4723 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4724 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4725 return localeFromDefaultSim.toLanguageTag();
4726 } else {
4727 simLanguage = localeFromDefaultSim.getLanguage();
4728 }
4729 }
4730 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004731
Malcolm Chend965c8b2018-02-28 15:00:40 -08004732 // The SIM language preferences only store a language (e.g. fr = French), not an
4733 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4734 // the SIM and carrier preferences does not include a country we add the country
4735 // determined from the SIM MCC to provide an exact locale.
4736 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4737 simLanguage);
4738 if (mccLocale != null) {
4739 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4740 return mccLocale.toLanguageTag();
4741 }
4742
4743 if (DBG) log("No locale found - returning null");
4744 return null;
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004748 }
4749
4750 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004751 return mSubscriptionController.getAllSubInfoList(
4752 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004753 }
4754
Malcolm Chend965c8b2018-02-28 15:00:40 -08004755 /**
4756 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4757 */
4758 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4759 return mSubscriptionController.getActiveSubscriptionInfoList(
4760 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004761 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004762
Chenjie Yu1ba97252018-01-11 18:16:20 -08004763 private final ModemActivityInfo mLastModemActivityInfo =
4764 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4765
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004766 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004767 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4768 * representing the state of the modem.
4769 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004770 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4771 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004772 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004773 */
4774 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004775 public void requestModemActivityInfo(ResultReceiver result) {
4776 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004777 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004778
4779 final long identity = Binder.clearCallingIdentity();
4780 try {
4781 ModemActivityInfo ret = null;
4782 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004783 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4784 CMD_GET_MODEM_ACTIVITY_INFO,
4785 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004786 if (isModemActivityInfoValid(info)) {
4787 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4788 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4789 mergedTxTimeMs[i] =
4790 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4791 }
4792 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4793 mLastModemActivityInfo.setSleepTimeMillis(
4794 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4795 mLastModemActivityInfo.setIdleTimeMillis(
4796 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4797 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4798 mLastModemActivityInfo.setRxTimeMillis(
4799 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4800 mLastModemActivityInfo.setEnergyUsed(
4801 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004802 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004803 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4804 mLastModemActivityInfo.getSleepTimeMillis(),
4805 mLastModemActivityInfo.getIdleTimeMillis(),
4806 mLastModemActivityInfo.getTxTimeMillis(),
4807 mLastModemActivityInfo.getRxTimeMillis(),
4808 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004809 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004810 Bundle bundle = new Bundle();
4811 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4812 result.send(0, bundle);
4813 } finally {
4814 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004815 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004816 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004817
Siddharth Rayf5d29552018-06-17 15:02:38 -07004818 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4819 // less than total activity duration.
4820 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4821 if (info == null) {
4822 return false;
4823 }
4824 int activityDurationMs =
4825 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4826 int totalTxTimeMs = 0;
4827 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4828 totalTxTimeMs += info.getTxTimeMillis()[i];
4829 }
4830 return (info.isValid()
4831 && (info.getSleepTimeMillis() <= activityDurationMs)
4832 && (info.getIdleTimeMillis() <= activityDurationMs)
4833 && (info.getRxTimeMillis() <= activityDurationMs)
4834 && (totalTxTimeMs <= activityDurationMs));
4835 }
4836
Jack Yu85bd38a2015-11-09 11:34:32 -08004837 /**
4838 * {@hide}
4839 * Returns the service state information on specified subscription.
4840 */
4841 @Override
4842 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004844 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004845 return null;
4846 }
4847
Malcolm Chend965c8b2018-02-28 15:00:40 -08004848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 final Phone phone = getPhone(subId);
4851 if (phone == null) {
4852 return null;
4853 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004854
Malcolm Chend965c8b2018-02-28 15:00:40 -08004855 return phone.getServiceState();
4856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004859 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004860
4861 /**
4862 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4863 *
4864 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4865 * voicemail ringtone.
4866 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4867 * PhoneAccount.
4868 */
4869 @Override
4870 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004871 final long identity = Binder.clearCallingIdentity();
4872 try {
4873 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4874 if (phone == null) {
4875 phone = mPhone;
4876 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004877
Malcolm Chend965c8b2018-02-28 15:00:40 -08004878 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004882 }
4883
4884 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004885 * Sets the per-account voicemail ringtone.
4886 *
4887 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4888 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4889 *
4890 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4891 * voicemail ringtone.
4892 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4893 * PhoneAccount.
4894 */
4895 @Override
4896 public void setVoicemailRingtoneUri(String callingPackage,
4897 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4898 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4899 if (!TextUtils.equals(callingPackage,
4900 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4902 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4903 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004904 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004905
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4909 if (phone == null) {
4910 phone = mPhone;
4911 }
4912 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4913 } finally {
4914 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004915 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004916 }
4917
4918 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004919 * Returns whether vibration is set for voicemail notification in Phone settings.
4920 *
4921 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4922 * voicemail vibration setting.
4923 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4924 */
4925 @Override
4926 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
4929 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4930 if (phone == null) {
4931 phone = mPhone;
4932 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004933
Malcolm Chend965c8b2018-02-28 15:00:40 -08004934 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004938 }
4939
Youhan Wange64578a2016-05-02 15:32:42 -07004940 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004941 * Sets the per-account voicemail vibration.
4942 *
4943 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4944 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4945 *
4946 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4947 * voicemail vibration setting.
4948 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4949 * specific PhoneAccount.
4950 */
4951 @Override
4952 public void setVoicemailVibrationEnabled(String callingPackage,
4953 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4954 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4955 if (!TextUtils.equals(callingPackage,
4956 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4958 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4959 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004960 }
4961
Malcolm Chend965c8b2018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4965 if (phone == null) {
4966 phone = mPhone;
4967 }
4968 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004971 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004972 }
4973
4974 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004975 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4976 *
4977 * @throws SecurityException if the caller does not have the required permission
4978 */
Brad Ebinger4c460712018-10-01 10:40:55 -07004979 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004980 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07004981 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004982 }
4983
4984 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004985 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4986 * permission.
4987 *
4988 * @throws SecurityException if the caller does not have the required permission
4989 */
4990 private void enforceSendSmsPermission() {
4991 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4992 }
4993
4994 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004995 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004996 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004997 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004998 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004999 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005000 final long identity = Binder.clearCallingIdentity();
5001 try {
5002 ComponentName componentName =
5003 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5004 if (componentName == null) {
5005 throw new SecurityException(
5006 "Caller not current active visual voicemail package[null]");
5007 }
5008 String vvmPackage = componentName.getPackageName();
5009 if (!callingPackage.equals(vvmPackage)) {
5010 throw new SecurityException("Caller not current active visual voicemail package["
5011 + vvmPackage + "]");
5012 }
5013 } finally {
5014 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005015 }
5016 }
5017
5018 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005019 * Return the application ID for the app type.
5020 *
5021 * @param subId the subscription ID that this request applies to.
5022 * @param appType the uicc app type.
5023 * @return Application ID for specificied app type, or null if no uicc.
5024 */
5025 @Override
5026 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005027 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005028 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005029
5030 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005031 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005032 if (phone == null) {
5033 return null;
5034 }
5035 String aid = null;
5036 try {
5037 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5038 .getApplicationByType(appType).getAid();
5039 } catch (Exception e) {
5040 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5041 }
5042 return aid;
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005045 }
Youhan Wange64578a2016-05-02 15:32:42 -07005046 }
5047
Youhan Wang4001d252016-05-11 10:29:41 -07005048 /**
5049 * Return the Electronic Serial Number.
5050 *
5051 * @param subId the subscription ID that this request applies to.
5052 * @return ESN or null if error.
5053 */
5054 @Override
5055 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005056 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005057 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005058
5059 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005060 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005061 if (phone == null) {
5062 return null;
5063 }
5064 String esn = null;
5065 try {
5066 esn = phone.getEsn();
5067 } catch (Exception e) {
5068 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5069 }
5070 return esn;
5071 } finally {
5072 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005073 }
Youhan Wang4001d252016-05-11 10:29:41 -07005074 }
5075
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005076 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005077 * Return the Preferred Roaming List Version.
5078 *
5079 * @param subId the subscription ID that this request applies to.
5080 * @return PRLVersion or null if error.
5081 */
5082 @Override
5083 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005084 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005085 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005086
5087 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005088 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005089 if (phone == null) {
5090 return null;
5091 }
5092 String cdmaPrlVersion = null;
5093 try {
5094 cdmaPrlVersion = phone.getCdmaPrlVersion();
5095 } catch (Exception e) {
5096 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5097 }
5098 return cdmaPrlVersion;
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005101 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005102 }
5103
5104 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005105 * Get snapshot of Telephony histograms
5106 * @return List of Telephony histograms
5107 * @hide
5108 */
5109 @Override
5110 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5112 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005113
5114 final long identity = Binder.clearCallingIdentity();
5115 try {
5116 return RIL.getTelephonyRILTimingHistograms();
5117 } finally {
5118 Binder.restoreCallingIdentity(identity);
5119 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005120 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005121
5122 /**
5123 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005124 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005125 * Require system privileges. In the future we may add this to carrier APIs.
5126 *
5127 * @return The number of carriers set successfully, should match length of carriers
5128 */
5129 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005130 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005131 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005132 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005133
Meng Wang9b7c4e92017-02-17 11:41:27 -08005134 if (carriers == null) {
5135 throw new NullPointerException("carriers cannot be null");
5136 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005137
Malcolm Chend965c8b2018-02-28 15:00:40 -08005138 final long identity = Binder.clearCallingIdentity();
5139 try {
5140 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005141 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5142 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143 return retVal[0];
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005147 }
5148
5149 /**
5150 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005151 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005152 * Require system privileges. In the future we may add this to carrier APIs.
5153 *
5154 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5155 * means all carriers are allowed.
5156 */
5157 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005158 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005159 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005160 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005161
5162 final long identity = Binder.clearCallingIdentity();
5163 try {
5164 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005165 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5166 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005167 } finally {
5168 Binder.restoreCallingIdentity(identity);
5169 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005170 }
5171
fionaxu59545b42016-05-25 15:53:37 -07005172 /**
5173 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5174 * @param subId the subscription ID that this action applies to.
5175 * @param enabled control enable or disable metered apns.
5176 * {@hide}
5177 */
5178 @Override
5179 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5180 enforceModifyPermission();
5181 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005182
5183 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005184 if (phone == null) {
5185 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5186 return;
5187 }
5188 try {
5189 phone.carrierActionSetMeteredApnsEnabled(enabled);
5190 } catch (Exception e) {
5191 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005194 }
5195 }
5196
5197 /**
5198 * Action set from carrier signalling broadcast receivers to enable/disable radio
5199 * @param subId the subscription ID that this action applies to.
5200 * @param enabled control enable or disable radio.
5201 * {@hide}
5202 */
5203 @Override
5204 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5205 enforceModifyPermission();
5206 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207
5208 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005209 if (phone == null) {
5210 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5211 return;
5212 }
5213 try {
5214 phone.carrierActionSetRadioEnabled(enabled);
5215 } catch (Exception e) {
5216 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005217 } finally {
5218 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005219 }
5220 }
5221
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005222 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005223 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5224 * network status based on which carrier apps could apply actions accordingly,
5225 * enable/disable default url handler for example.
5226 *
5227 * @param subId the subscription ID that this action applies to.
5228 * @param report control start/stop reporting the default network status.
5229 * {@hide}
5230 */
5231 @Override
5232 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5233 enforceModifyPermission();
5234 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005235
5236 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005237 if (phone == null) {
5238 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5239 return;
5240 }
5241 try {
5242 phone.carrierActionReportDefaultNetworkStatus(report);
5243 } catch (Exception e) {
5244 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005247 }
5248 }
5249
5250 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005251 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5252 * bug report is being generated.
5253 */
5254 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005255 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005256 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5257 != PackageManager.PERMISSION_GRANTED) {
5258 writer.println("Permission Denial: can't dump Phone from pid="
5259 + Binder.getCallingPid()
5260 + ", uid=" + Binder.getCallingUid()
5261 + "without permission "
5262 + android.Manifest.permission.DUMP);
5263 return;
5264 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005265 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005266 }
Jack Yueb89b242016-06-22 13:27:47 -07005267
Brad Ebingerdac2f002018-04-03 15:17:52 -07005268 @Override
5269 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5270 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5271 throws RemoteException {
5272 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5273 }
5274
Jack Yueb89b242016-06-22 13:27:47 -07005275 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005276 * Get aggregated video call data usage since boot.
5277 *
5278 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5279 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005280 * {@hide}
5281 */
5282 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005283 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005284 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5285 null);
5286
Malcolm Chend965c8b2018-02-28 15:00:40 -08005287 final long identity = Binder.clearCallingIdentity();
5288 try {
5289 // NetworkStatsService keeps tracking the active network interface and identity. It
5290 // records the delta with the corresponding network identity.
5291 // We just return the total video call data usage snapshot since boot.
5292 Phone phone = getPhone(subId);
5293 if (phone != null) {
5294 return phone.getVtDataUsage(perUidStats);
5295 }
5296 return null;
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005299 }
Jack Yueb89b242016-06-22 13:27:47 -07005300 }
Jack Yu75ab2952016-07-08 14:29:33 -07005301
5302 /**
5303 * Policy control of data connection. Usually used when data limit is passed.
5304 * @param enabled True if enabling the data, otherwise disabling.
5305 * @param subId Subscription index
5306 * {@hide}
5307 */
5308 @Override
5309 public void setPolicyDataEnabled(boolean enabled, int subId) {
5310 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005311
5312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 Phone phone = getPhone(subId);
5315 if (phone != null) {
5316 phone.setPolicyDataEnabled(enabled);
5317 }
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005320 }
5321 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005322
5323 /**
5324 * Get Client request stats
5325 * @return List of Client Request Stats
5326 * @hide
5327 */
5328 @Override
5329 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005331 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005332 return null;
5333 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005334 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005335
Malcolm Chend965c8b2018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 if (phone != null) {
5339 return phone.getClientRequestStats();
5340 }
5341
5342 return null;
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
5345 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005346 }
5347
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005348 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005349 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005350 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005351 }
Jack Yueb4124c2017-02-16 15:32:43 -08005352
5353 /**
Grace Chen70990072017-03-24 17:21:30 -07005354 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005355 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005356 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005357 * @param state State of SIM (power down, power up, pass through)
5358 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5359 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5360 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005361 *
5362 **/
5363 @Override
Grace Chen70990072017-03-24 17:21:30 -07005364 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005365 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005366 Phone phone = PhoneFactory.getPhone(slotIndex);
5367
vagdevie435a3e2018-08-15 16:01:53 -07005368 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5369
Malcolm Chend965c8b2018-02-28 15:00:40 -08005370 final long identity = Binder.clearCallingIdentity();
5371 try {
5372 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005373 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005374 }
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005377 }
5378 }
Shuo Qiandd210312017-04-12 22:11:33 +00005379
Tyler Gunn65d45c22017-06-05 11:22:26 -07005380 private boolean isUssdApiAllowed(int subId) {
5381 CarrierConfigManager configManager =
5382 (CarrierConfigManager) mPhone.getContext().getSystemService(
5383 Context.CARRIER_CONFIG_SERVICE);
5384 if (configManager == null) {
5385 return false;
5386 }
5387 PersistableBundle pb = configManager.getConfigForSubId(subId);
5388 if (pb == null) {
5389 return false;
5390 }
5391 return pb.getBoolean(
5392 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5393 }
5394
Shuo Qiandd210312017-04-12 22:11:33 +00005395 /**
5396 * Check if phone is in emergency callback mode
5397 * @return true if phone is in emergency callback mode
5398 * @param subId sub id
5399 */
goneil9c5f4872017-12-05 14:07:56 -08005400 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005401 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005402 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005403 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005404
5405 final long identity = Binder.clearCallingIdentity();
5406 try {
5407 if (phone != null) {
5408 return phone.isInEcm();
5409 } else {
5410 return false;
5411 }
5412 } finally {
5413 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005414 }
5415 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005416
5417 /**
5418 * Get the current signal strength information for the given subscription.
5419 * Because this information is not updated when the device is in a low power state
5420 * it should not be relied-upon to be current.
5421 * @param subId Subscription index
5422 * @return the most recent cached signal strength info from the modem
5423 */
5424 @Override
5425 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
5428 Phone p = getPhone(subId);
5429 if (p == null) {
5430 return null;
5431 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005432
Malcolm Chend965c8b2018-02-28 15:00:40 -08005433 return p.getSignalStrength();
5434 } finally {
5435 Binder.restoreCallingIdentity(identity);
5436 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005437 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005438
Pengquan Meng9140aec2018-08-22 14:49:57 -07005439 /**
chen xu907e5a22018-10-11 13:21:04 -07005440 * Get the current modem radio state for the given slot.
5441 * @param slotIndex slot index.
5442 * @param callingPackage the name of the package making the call.
5443 * @return the current radio power state from the modem
5444 */
5445 @Override
5446 public int getRadioPowerState(int slotIndex, String callingPackage) {
5447 Phone phone = PhoneFactory.getPhone(slotIndex);
5448 if (phone != null) {
5449 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5450 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5451 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5452 }
5453
5454 final long identity = Binder.clearCallingIdentity();
5455 try {
5456 return phone.getRadioPowerState();
5457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
5460 }
5461 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5462 }
5463
5464 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005465 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5466 *
5467 * <p>Requires one of the following permissions:
5468 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5469 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5470 * privileges.
5471 *
5472 * @param subId subscription id
5473 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5474 * {@code false}.
5475 */
5476 @Override
5477 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005478 boolean isEnabled = false;
5479 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005480 try {
5481 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005482 null /* message */);
5483 Phone phone = getPhone(subId);
5484 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005485 } catch (Exception e) {
5486 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5487 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005488 } finally {
5489 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005490 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005491 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005492 }
5493
5494
5495 /**
5496 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5497 *
5498 * <p> Requires permission:
5499 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5500 * privileges.
5501 *
5502 * @param subId subscription id
5503 * @param isEnabled {@code true} means enable, {@code false} means disable.
5504 */
5505 @Override
5506 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5510 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005511
Pengquan Meng0c05b502018-09-06 09:59:22 -07005512 Phone phone = getPhone(subId);
5513 if (phone != null) {
5514 phone.setDataRoamingEnabled(isEnabled);
5515 }
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005518 }
5519 }
5520
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005521 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005522 public boolean isManualNetworkSelectionAllowed(int subId) {
5523 boolean isAllowed = true;
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5527 mApp, subId, "isManualNetworkSelectionAllowed");
5528 Phone phone = getPhone(subId);
5529 if (phone != null) {
5530 isAllowed = phone.isCspPlmnEnabled();
5531 }
5532 } finally {
5533 Binder.restoreCallingIdentity(identity);
5534 }
5535 return isAllowed;
5536 }
5537
5538 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005539 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005540 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005541
Malcolm Chend965c8b2018-02-28 15:00:40 -08005542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5545 if (slots == null) {
5546 Rlog.i(LOG_TAG, "slots is null.");
5547 return null;
5548 }
5549
5550 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5551 for (int i = 0; i < slots.length; i++) {
5552 UiccSlot slot = slots[i];
5553 if (slot == null) {
5554 continue;
5555 }
5556
5557 String cardId;
5558 UiccCard card = slot.getUiccCard();
5559 if (card != null) {
5560 cardId = card.getCardId();
5561 } else {
5562 cardId = slot.getIccId();
5563 }
5564
5565 int cardState = 0;
5566 switch (slot.getCardState()) {
5567 case CARDSTATE_ABSENT:
5568 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5569 break;
5570 case CARDSTATE_PRESENT:
5571 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5572 break;
5573 case CARDSTATE_ERROR:
5574 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5575 break;
5576 case CARDSTATE_RESTRICTED:
5577 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5578 break;
5579 default:
5580 break;
5581
5582 }
5583
5584 infos[i] = new UiccSlotInfo(
5585 slot.isActive(),
5586 slot.isEuicc(),
5587 cardId,
5588 cardState,
5589 slot.getPhoneId(),
5590 slot.isExtendedApduSupported());
5591 }
5592 return infos;
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005595 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005596 }
5597
5598 @Override
5599 public boolean switchSlots(int[] physicalSlots) {
5600 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005601
5602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005608 }
Jack Yu4c988042018-02-27 15:30:01 -08005609
5610 @Override
5611 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5612 enforceModifyPermission();
5613 final Phone phone = getPhone(subId);
5614 if (phone == null) {
5615 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5616 return;
5617 }
5618
Malcolm Chend965c8b2018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 phone.setRadioIndicationUpdateMode(filters, mode);
5622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
Jack Yu4c988042018-02-27 15:30:01 -08005625 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005626
5627 /**
goneil47ffb6e2018-04-06 15:40:58 -07005628 * A test API to reload the UICC profile.
5629 *
5630 * <p>Requires that the calling app has permission
5631 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5632 * @hide
5633 */
5634 @Override
5635 public void refreshUiccProfile(int subId) {
5636 enforceModifyPermission();
5637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 Phone phone = getPhone(subId);
5641 if (phone == null) {
5642 return;
5643 }
5644 UiccCard uiccCard = phone.getUiccCard();
5645 if (uiccCard == null) {
5646 return;
5647 }
5648 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5649 if (uiccProfile == null) {
5650 return;
5651 }
5652 uiccProfile.refresh();
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
5656 }
5657
5658 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005659 * Returns false if the mobile data is disabled by default, otherwise return true.
5660 */
5661 private boolean getDefaultDataEnabled() {
5662 return "true".equalsIgnoreCase(
5663 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5664 }
5665
5666 /**
5667 * Returns true if the data roaming is enabled by default, i.e the system property
5668 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5669 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5670 */
5671 private boolean getDefaultDataRoamingEnabled(int subId) {
5672 final CarrierConfigManager configMgr = (CarrierConfigManager)
5673 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5674 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5675 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5676 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5677 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5678 return isDataRoamingEnabled;
5679 }
5680
5681 /**
5682 * Returns the default network type for the given {@code subId}, if the default network type is
5683 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5684 */
5685 private int getDefaultNetworkType(int subId) {
5686 return Integer.parseInt(
5687 TelephonyManager.getTelephonyProperty(
5688 mSubscriptionController.getPhoneId(subId),
5689 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5690 String.valueOf(Phone.PREFERRED_NT_MODE)));
5691 }
fionaxua13278b2018-03-21 00:08:13 -07005692
5693 @Override
5694 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5695 gid1, String gid2, String plmn, String spn) {
5696 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005697
5698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 final Phone phone = getPhone(subId);
5701 if (phone == null) {
5702 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5703 return;
5704 }
5705 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005708 }
fionaxua13278b2018-03-21 00:08:13 -07005709 }
5710
5711 @Override
5712 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005713 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005714
5715 final long identity = Binder.clearCallingIdentity();
5716 try {
5717 final Phone phone = getPhone(subId);
5718 if (phone == null) {
5719 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5720 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5721 }
5722 return phone.getCarrierIdListVersion();
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005725 }
fionaxua13278b2018-03-21 00:08:13 -07005726 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005727
5728 @Override
5729 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5731 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5732 return -1;
5733 }
5734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
5741 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005742
5743 @Override
5744 public int getCdmaRoamingMode(int subId) {
5745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5746 mApp, subId, "getCdmaRoamingMode");
5747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
5750 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
5754 }
5755
5756 @Override
5757 public boolean setCdmaRoamingMode(int subId, int mode) {
5758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5759 mApp, subId, "setCdmaRoamingMode");
5760
5761 final long identity = Binder.clearCallingIdentity();
5762 try {
5763 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
5766 }
5767 }
5768
5769 @Override
5770 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5772 mApp, subId, "setCdmaSubscriptionMode");
5773
5774 final long identity = Binder.clearCallingIdentity();
5775 try {
5776 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5777 } finally {
5778 Binder.restoreCallingIdentity(identity);
5779 }
5780 }
chen xu7ee67862018-10-30 22:27:10 -07005781
sqian2fff4a32018-11-05 14:18:37 -08005782 private void ensureUserRunning(int userId) {
5783 if (!mUserManager.isUserRunning(userId)) {
5784 throw new IllegalStateException("User " + userId + " does not exist or not running");
5785 }
5786 }
5787
5788 /**
5789 * Returns a list of SMS apps on a given user.
5790 *
5791 * Only the shell user (UID 2000 or 0) can call it.
5792 * Target user must be running.
5793 */
5794 @Override
5795 public String[] getSmsApps(int userId) {
5796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5797 ensureUserRunning(userId);
5798
5799 final Collection<SmsApplicationData> apps =
5800 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5801
5802 String[] ret = new String[apps.size()];
5803 int i = 0;
5804 for (SmsApplicationData app : apps) {
5805 ret[i++] = app.mPackageName;
5806 }
5807 return ret;
5808 }
5809
5810 /**
5811 * Returns the default SMS app package name on a given user.
5812 *
5813 * Only the shell user (UID 2000 or 0) can call it.
5814 * Target user must be running.
5815 */
5816 @Override
5817 public String getDefaultSmsApp(int userId) {
5818 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5819 ensureUserRunning(userId);
5820
5821 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5822 /* updateIfNeeded= */ true, userId);
5823 return cn == null ? null : cn.getPackageName();
5824 }
5825
5826 /**
5827 * Set a package as the default SMS app on a given user.
5828 *
5829 * Only the shell user (UID 2000 or 0) can call it.
5830 * Target user must be running.
5831 */
5832 @Override
5833 public void setDefaultSmsApp(int userId, String packageName) {
5834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5835 ensureUserRunning(userId);
5836
5837 boolean found = false;
5838 for (String pkg : getSmsApps(userId)) {
5839 if (TextUtils.equals(packageName, pkg)) {
5840 found = true;
5841 break;
5842 }
5843 }
5844 if (!found) {
5845 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5846 }
5847
5848 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5849 }
5850
chen xu7ee67862018-10-30 22:27:10 -07005851 @Override
sqian04b86072018-11-07 14:02:21 -08005852 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5853 String callingPackage) {
5854 // TODO connect with internal content
5855 return null;
5856 }
5857
5858 @Override
5859 public boolean isCurrentEmergencyNumber(String number) {
5860 // TODO connect with internal content
5861 return false;
5862 }
5863
5864 @Override
chen xu7ee67862018-10-30 22:27:10 -07005865 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5866 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5867 Phone phone = getPhone(subId);
5868 if (phone == null) {
5869 return null;
5870 }
5871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 UiccProfile profile = UiccController.getInstance()
5874 .getUiccProfileForPhone(phone.getPhoneId());
5875 if (profile != null) {
5876 return profile.getCertsFromCarrierPrivilegeAccessRules();
5877 }
5878 } finally {
5879 Binder.restoreCallingIdentity(identity);
5880 }
5881 return null;
5882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005883}