blob: e58d60cc246c718a6801cb904c91318bd64519f1 [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
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
87import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070089import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080090import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070091import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080092import android.telephony.ims.aidl.IImsMmTelFeature;
93import android.telephony.ims.aidl.IImsRcsFeature;
94import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070095import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080096import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800102
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700104import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800105import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700107import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700108import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800109import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800113import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700116import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100117import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700118import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700121import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800122import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700123import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700124import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700125import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700126import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700127import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700129import com.android.internal.telephony.SmsApplication;
130import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800131import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800132import com.android.internal.telephony.TelephonyPermissions;
sqianf4ca7ed2019-01-15 18:32:07 -0800133import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700134import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.uicc.IccIoResult;
136import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800137import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700138import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800139import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800141import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000142import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700143import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800144import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700145import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800146import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700147import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700148import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800149
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700150import java.io.FileDescriptor;
151import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800152import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800154import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700155import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800156import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800158import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100159import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160import java.util.Map;
sqianf4ca7ed2019-01-15 18:32:07 -0800161import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162
163/**
164 * Implementation of the ITelephony interface.
165 */
Santos Cordon117fee72014-05-16 17:56:12 -0700166public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 private static final String LOG_TAG = "PhoneInterfaceManager";
168 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
169 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800170 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171
172 // Message codes used with mMainThreadHandler
173 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700174 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
175 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176 private static final int CMD_OPEN_CHANNEL = 9;
177 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
178 private static final int CMD_CLOSE_CHANNEL = 11;
179 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800180 private static final int CMD_NV_READ_ITEM = 13;
181 private static final int EVENT_NV_READ_ITEM_DONE = 14;
182 private static final int CMD_NV_WRITE_ITEM = 15;
183 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
184 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
185 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700186 private static final int CMD_RESET_MODEM_CONFIG = 19;
187 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800188 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
189 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
190 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
191 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800192 private static final int CMD_SEND_ENVELOPE = 25;
193 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000194 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
195 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700196 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
197 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
198 private static final int CMD_EXCHANGE_SIM_IO = 31;
199 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800200 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
201 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700202 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
203 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700204 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
205 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
207 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
208 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
209 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700210 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
211 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
212 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
213 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700214 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800215 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
216 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000217 private static final int CMD_SWITCH_SLOTS = 50;
218 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700219 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
220 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
221 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
222 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
223 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
224 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
225 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
226 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700227 private static final int CMD_GET_ALL_CELL_INFO = 60;
228 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
229 private static final int CMD_GET_CELL_LOCATION = 62;
230 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700231 private static final int CMD_MODEM_REBOOT = 64;
232 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700233 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
234 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800236 // Parameters of select command.
237 private static final int SELECT_COMMAND = 0xA4;
238 private static final int SELECT_P1 = 0x04;
239 private static final int SELECT_P2 = 0;
240 private static final int SELECT_P3 = 0x10;
241
Pengquan Meng85728fb2018-03-12 16:31:21 -0700242 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
243 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
244 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
245
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 /** The singleton instance. */
247 private static PhoneInterfaceManager sInstance;
248
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800250 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700251 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private AppOpsManager mAppOps;
253 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800254 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800255 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700256 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
Derek Tan97ebb422014-09-05 16:55:38 -0700258 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
259 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800260 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700261
Derek Tan740e1672017-06-27 14:56:27 -0700262 // The AID of ISD-R.
263 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
264
yinxub1bed742017-04-17 11:45:04 -0700265 private NetworkScanRequestTracker mNetworkScanRequestTracker;
266
David Kelly5e06a7f2018-03-12 14:10:59 +0000267 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
268 private static final int MANUFACTURER_CODE_LENGTH = 8;
269
Derek Tan89e89d42014-07-08 17:00:10 -0700270 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700271 * A request object to use for transmitting data to an ICC.
272 */
273 private static final class IccAPDUArgument {
274 public int channel, cla, command, p1, p2, p3;
275 public String data;
276
277 public IccAPDUArgument(int channel, int cla, int command,
278 int p1, int p2, int p3, String data) {
279 this.channel = channel;
280 this.cla = cla;
281 this.command = command;
282 this.p1 = p1;
283 this.p2 = p2;
284 this.p3 = p3;
285 this.data = data;
286 }
287 }
288
289 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700290 * A request object to use for transmitting data to an ICC.
291 */
292 private static final class ManualNetworkSelectionArgument {
293 public OperatorInfo operatorInfo;
294 public boolean persistSelection;
295
296 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
297 this.operatorInfo = operatorInfo;
298 this.persistSelection = persistSelection;
299 }
300 }
301
302 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
304 * request after sending. The main thread will notify the request when it is complete.
305 */
306 private static final class MainThreadRequest {
307 /** The argument to use for the request */
308 public Object argument;
309 /** The result of the request that is run on the main thread */
310 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800311 // The subscriber id that this request applies to. Defaults to
312 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
313 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314
Nathan Harold92bed182018-10-12 18:16:49 -0700315 // In cases where subId is unavailable, the caller needs to specify the phone.
316 public Phone phone;
317
vagdeviaf9a5b92018-08-15 16:01:53 -0700318 public WorkSource workSource;
319
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 public MainThreadRequest(Object argument) {
321 this.argument = argument;
322 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800323
Nathan Harold92bed182018-10-12 18:16:49 -0700324 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
325 this.argument = argument;
326 if (phone != null) {
327 this.phone = phone;
328 }
329 this.workSource = workSource;
330 }
331
vagdeviaf9a5b92018-08-15 16:01:53 -0700332 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800333 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800334 if (subId != null) {
335 this.subId = subId;
336 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700337 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 }
340
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800341 private static final class IncomingThirdPartyCallArgs {
342 public final ComponentName component;
343 public final String callId;
344 public final String callerDisplayName;
345
346 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
347 String callerDisplayName) {
348 this.component = component;
349 this.callId = callId;
350 this.callerDisplayName = callerDisplayName;
351 }
352 }
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 /**
355 * A handler that processes messages on the main thread in the phone process. Since many
356 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
357 * inbound binder threads to the main thread in the phone process. The Binder thread
358 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
359 * on, which will be notified when the operation completes and will contain the result of the
360 * request.
361 *
362 * <p>If a MainThreadRequest object is provided in the msg.obj field,
363 * note that request.result must be set to something non-null for the calling thread to
364 * unblock.
365 */
366 private final class MainThreadHandler extends Handler {
367 @Override
368 public void handleMessage(Message msg) {
369 MainThreadRequest request;
370 Message onCompleted;
371 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800372 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700373 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800374 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
376 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700377 case CMD_HANDLE_USSD_REQUEST: {
378 request = (MainThreadRequest) msg.obj;
379 final Phone phone = getPhoneFromRequest(request);
380 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
381 String ussdRequest = ussdObject.first;
382 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700383
Pengquan Menga1bb6272018-09-06 09:59:22 -0700384 if (!isUssdApiAllowed(request.subId)) {
385 // Carrier does not support use of this API, return failure.
386 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
387 UssdResponse response = new UssdResponse(ussdRequest, null);
388 Bundle returnData = new Bundle();
389 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
390 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700391
Pengquan Menga1bb6272018-09-06 09:59:22 -0700392 request.result = true;
393 notifyRequester(request);
394 return;
395 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700396
Pengquan Menga1bb6272018-09-06 09:59:22 -0700397 try {
398 request.result = phone != null
399 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
400 } catch (CallStateException cse) {
401 request.result = false;
402 }
403 // Wake up the requesting thread
404 notifyRequester(request);
405 break;
pkanwar32d516d2016-10-14 19:37:38 -0700406 }
407
Yorke Lee716f67e2015-06-17 15:39:16 -0700408 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700410 final Phone phone = getPhoneFromRequest(request);
411 request.result = phone != null ?
412 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
413 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700415 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800422 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700423 if (uiccCard == null) {
424 loge("iccTransmitApduLogicalChannel: No UICC");
425 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
429 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 iccArgument.channel, iccArgument.cla, iccArgument.command,
432 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700434 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 break;
436
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 ar = (AsyncResult) msg.obj;
439 request = (MainThreadRequest) ar.userObj;
440 if (ar.exception == null && ar.result != null) {
441 request.result = ar.result;
442 } else {
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
444 if (ar.result == null) {
445 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800446 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800448 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 } else {
450 loge("iccTransmitApduLogicalChannel: Unknown exception");
451 }
452 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 break;
455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
457 request = (MainThreadRequest) msg.obj;
458 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800459 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 if (uiccCard == null) {
461 loge("iccTransmitApduBasicChannel: No UICC");
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700463 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 } else {
465 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
466 request);
467 uiccCard.iccTransmitApduBasicChannel(
468 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
469 iccArgument.p3, iccArgument.data, onCompleted);
470 }
471 break;
472
473 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
474 ar = (AsyncResult) msg.obj;
475 request = (MainThreadRequest) ar.userObj;
476 if (ar.exception == null && ar.result != null) {
477 request.result = ar.result;
478 } else {
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
480 if (ar.result == null) {
481 loge("iccTransmitApduBasicChannel: Empty response");
482 } else if (ar.exception instanceof CommandException) {
483 loge("iccTransmitApduBasicChannel: CommandException: " +
484 ar.exception);
485 } else {
486 loge("iccTransmitApduBasicChannel: Unknown exception");
487 }
488 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 break;
491
492 case CMD_EXCHANGE_SIM_IO:
493 request = (MainThreadRequest) msg.obj;
494 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800495 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 if (uiccCard == null) {
497 loge("iccExchangeSimIO: No UICC");
498 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 } else {
501 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
502 request);
503 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
504 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
505 iccArgument.data, onCompleted);
506 }
507 break;
508
509 case EVENT_EXCHANGE_SIM_IO_DONE:
510 ar = (AsyncResult) msg.obj;
511 request = (MainThreadRequest) ar.userObj;
512 if (ar.exception == null && ar.result != null) {
513 request.result = ar.result;
514 } else {
515 request.result = new IccIoResult(0x6f, 0, (byte[])null);
516 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 break;
519
Derek Tan4d5e5c12014-02-04 11:54:58 -0800520 case CMD_SEND_ENVELOPE:
521 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 if (uiccCard == null) {
524 loge("sendEnvelopeWithStatus: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
529 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
530 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800531 break;
532
533 case EVENT_SEND_ENVELOPE_DONE:
534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 if (ar.exception == null && ar.result != null) {
537 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
540 if (ar.result == null) {
541 loge("sendEnvelopeWithStatus: Empty response");
542 } else if (ar.exception instanceof CommandException) {
543 loge("sendEnvelopeWithStatus: CommandException: " +
544 ar.exception);
545 } else {
546 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
547 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 break;
551
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 case CMD_OPEN_CHANNEL:
553 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800555 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 if (uiccCard == null) {
557 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800558 request.result = new IccOpenLogicalChannelResponse(-1,
559 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800563 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
564 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 break;
567
568 case EVENT_OPEN_CHANNEL_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 int[] result = (int[]) ar.result;
574 int channelId = result[0];
575 byte[] selectResponse = null;
576 if (result.length > 1) {
577 selectResponse = new byte[result.length - 1];
578 for (int i = 1; i < result.length; ++i) {
579 selectResponse[i - 1] = (byte) result[i];
580 }
581 }
582 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 if (ar.result == null) {
586 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 if (ar.exception != null) {
589 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
590 }
591
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700593 if (ar.exception instanceof CommandException) {
594 CommandException.Error error =
595 ((CommandException) (ar.exception)).getCommandError();
596 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700598 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 }
601 }
602 openChannelResp = new IccOpenLogicalChannelResponse(
603 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700605 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
609 case CMD_CLOSE_CHANNEL:
610 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800611 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 if (uiccCard == null) {
613 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900614 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700616 } else {
617 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
618 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
619 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
622 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800623 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
624 break;
625
626 case CMD_NV_READ_ITEM:
627 request = (MainThreadRequest) msg.obj;
628 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800629 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
630 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800631 break;
632
633 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 ar = (AsyncResult) msg.obj;
635 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800636 if (ar.exception == null && ar.result != null) {
637 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800639 request.result = "";
640 if (ar.result == null) {
641 loge("nvReadItem: Empty response");
642 } else if (ar.exception instanceof CommandException) {
643 loge("nvReadItem: CommandException: " +
644 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800646 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
648 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
Jake Hambye994d462014-02-03 13:10:13 -0800652 case CMD_NV_WRITE_ITEM:
653 request = (MainThreadRequest) msg.obj;
654 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
655 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800656 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700657 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
660 case EVENT_NV_WRITE_ITEM_DONE:
661 handleNullReturnEvent(msg, "nvWriteItem");
662 break;
663
664 case CMD_NV_WRITE_CDMA_PRL:
665 request = (MainThreadRequest) msg.obj;
666 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800667 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800668 break;
669
670 case EVENT_NV_WRITE_CDMA_PRL_DONE:
671 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
672 break;
673
chen xu6dac5ab2018-10-26 17:39:23 -0700674 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800675 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700676 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800677 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800678 break;
679
chen xu6dac5ab2018-10-26 17:39:23 -0700680 case EVENT_RESET_MODEM_CONFIG_DONE:
681 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800682 break;
683
Jake Hamby7c27be32014-03-03 13:25:59 -0800684 case CMD_GET_PREFERRED_NETWORK_TYPE:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700687 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800688 break;
689
690 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result; // Integer
695 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800696 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 if (ar.result == null) {
698 loge("getPreferredNetworkType: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("getPreferredNetworkType: CommandException: " +
701 ar.exception);
702 } else {
703 loge("getPreferredNetworkType: Unknown exception");
704 }
705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 break;
708
709 case CMD_SET_PREFERRED_NETWORK_TYPE:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
712 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700713 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 break;
715
716 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
717 handleNullReturnEvent(msg, "setPreferredNetworkType");
718 break;
719
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000720 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
721 request = (MainThreadRequest)msg.obj;
722 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000724 break;
725
726 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
727 ar = (AsyncResult)msg.obj;
728 request = (MainThreadRequest)ar.userObj;
729 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700730 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000731 break;
732
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800733 case CMD_SET_VOICEMAIL_NUMBER:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
736 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800737 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
738 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800739 break;
740
741 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
742 handleNullReturnEvent(msg, "setVoicemailNumber");
743 break;
744
Stuart Scott54788802015-03-30 13:18:01 -0700745 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
748 request);
749 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
750 break;
751
752 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
753 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
754 break;
755
Shishir Agrawal302c8692015-06-19 13:49:39 -0700756 case CMD_PERFORM_NETWORK_SCAN:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
759 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
760 break;
761
762 case EVENT_PERFORM_NETWORK_SCAN_DONE:
763 ar = (AsyncResult) msg.obj;
764 request = (MainThreadRequest) ar.userObj;
765 CellNetworkScanResult cellScanResult;
766 if (ar.exception == null && ar.result != null) {
767 cellScanResult = new CellNetworkScanResult(
768 CellNetworkScanResult.STATUS_SUCCESS,
769 (List<OperatorInfo>) ar.result);
770 } else {
771 if (ar.result == null) {
772 loge("getCellNetworkScanResults: Empty response");
773 }
774 if (ar.exception != null) {
775 loge("getCellNetworkScanResults: Exception: " + ar.exception);
776 }
777 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
778 if (ar.exception instanceof CommandException) {
779 CommandException.Error error =
780 ((CommandException) (ar.exception)).getCommandError();
781 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
782 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
783 } else if (error == CommandException.Error.GENERIC_FAILURE) {
784 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
785 }
786 }
787 cellScanResult = new CellNetworkScanResult(errorCode, null);
788 }
789 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700790 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 break;
792
793 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
794 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700795 ManualNetworkSelectionArgument selArg =
796 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
798 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700799 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
800 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700801 break;
802
803 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 if (ar.exception == null) {
807 request.result = true;
808 } else {
809 request.result = false;
810 loge("setNetworkSelectionModeManual " + ar.exception);
811 }
812 notifyRequester(request);
813 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 break;
815
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700816 case CMD_GET_MODEM_ACTIVITY_INFO:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800819 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700820 break;
821
822 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null && ar.result != null) {
826 request.result = ar.result;
827 } else {
828 if (ar.result == null) {
829 loge("queryModemActivityInfo: Empty response");
830 } else if (ar.exception instanceof CommandException) {
831 loge("queryModemActivityInfo: CommandException: " +
832 ar.exception);
833 } else {
834 loge("queryModemActivityInfo: Unknown exception");
835 }
836 }
Amit Mahajand4766222016-01-28 15:28:28 -0800837 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
838 if (request.result == null) {
839 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
840 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700841 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 break;
843
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 case CMD_SET_ALLOWED_CARRIERS:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800847 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700848 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700849 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700850 break;
851
852 case EVENT_SET_ALLOWED_CARRIERS_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 if (ar.result == null) {
859 loge("setAllowedCarriers: Empty response");
860 } else if (ar.exception instanceof CommandException) {
861 loge("setAllowedCarriers: CommandException: " +
862 ar.exception);
863 } else {
864 loge("setAllowedCarriers: Unknown exception");
865 }
866 }
867 // Result cannot be null. Return -1 on error.
868 if (request.result == null) {
869 request.result = new int[]{-1};
870 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700871 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 break;
873
874 case CMD_GET_ALLOWED_CARRIERS:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800877 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 break;
879
880 case EVENT_GET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
886 if (ar.result == null) {
887 loge("getAllowedCarriers: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("getAllowedCarriers: CommandException: " +
890 ar.exception);
891 } else {
892 loge("getAllowedCarriers: Unknown exception");
893 }
894 }
895 // Result cannot be null. Return empty list of CarrierIdentifier.
896 if (request.result == null) {
897 request.result = new ArrayList<CarrierIdentifier>(0);
898 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700899 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700900 break;
901
Nathan Haroldb3014052017-01-25 15:57:32 -0800902 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
903 ar = (AsyncResult) msg.obj;
904 request = (MainThreadRequest) ar.userObj;
905 if (ar.exception == null && ar.result != null) {
906 request.result = ar.result;
907 } else {
908 request.result = new IllegalArgumentException(
909 "Failed to retrieve Forbidden Plmns");
910 if (ar.result == null) {
911 loge("getForbiddenPlmns: Empty response");
912 } else {
913 loge("getForbiddenPlmns: Unknown exception");
914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 break;
918
919 case CMD_GET_FORBIDDEN_PLMNS:
920 request = (MainThreadRequest) msg.obj;
921 uiccCard = getUiccCardFromRequest(request);
922 if (uiccCard == null) {
923 loge("getForbiddenPlmns() UiccCard is null");
924 request.result = new IllegalArgumentException(
925 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800927 break;
928 }
929 Integer appType = (Integer) request.argument;
930 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
931 if (uiccApp == null) {
932 loge("getForbiddenPlmns() no app with specified type -- "
933 + appType);
934 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800936 break;
937 } else {
938 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
939 + " specified type -- " + appType);
940 }
941 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
942 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
943 onCompleted);
944 break;
945
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000946 case CMD_SWITCH_SLOTS:
947 request = (MainThreadRequest) msg.obj;
948 int[] physicalSlots = (int[]) request.argument;
949 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
950 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
951 break;
952
953 case EVENT_SWITCH_SLOTS_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 notifyRequester(request);
958 break;
959 case CMD_GET_NETWORK_SELECTION_MODE:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
962 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
963 break;
964
965 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 if (ar.exception != null) {
969 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
970 } else {
971 int mode = ((int[]) ar.result)[0];
972 if (mode == 0) {
973 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
974 } else {
975 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
976 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000977 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700978 notifyRequester(request);
979 break;
980 case CMD_GET_CDMA_ROAMING_MODE:
981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
983 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
984 break;
985 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 if (ar.exception != null) {
989 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
990 } else {
991 request.result = ((int[]) ar.result)[0];
992 }
993 notifyRequester(request);
994 break;
995 case CMD_SET_CDMA_ROAMING_MODE:
996 request = (MainThreadRequest) msg.obj;
997 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
998 int mode = (int) request.argument;
999 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1000 break;
1001 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 request.result = ar.exception == null;
1005 notifyRequester(request);
1006 break;
1007 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1010 int subscriptionMode = (int) request.argument;
1011 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1012 break;
1013 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 request.result = ar.exception == null;
1017 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001018 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 case CMD_GET_ALL_CELL_INFO:
1020 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001021 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001022 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001023 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001024 case EVENT_GET_ALL_CELL_INFO_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001027 // If a timeout occurs, the response will be null
1028 request.result = (ar.exception == null && ar.result != null)
1029 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001030 synchronized (request) {
1031 request.notifyAll();
1032 }
1033 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001034 case CMD_REQUEST_CELL_INFO_UPDATE:
1035 request = (MainThreadRequest) msg.obj;
1036 request.phone.requestCellInfoUpdate(request.workSource,
1037 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1038 break;
1039 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1043 try {
1044 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001045 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001046 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1047 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001048 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001049 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001050 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001051 } else {
1052 // use the result as returned
1053 cb.onCellInfo((List<CellInfo>) ar.result);
1054 }
1055 } catch (RemoteException re) {
1056 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1057 }
1058 break;
1059 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 request = (MainThreadRequest) msg.obj;
1061 WorkSource ws = (WorkSource) request.argument;
1062 Phone phone = getPhoneFromRequest(request);
1063 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1064 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null) {
1069 request.result = ar.result;
1070 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1073 ? new CdmaCellLocation() : new GsmCellLocation();
1074 }
1075
1076 synchronized (request) {
1077 request.notifyAll();
1078 }
1079 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001080 case CMD_MODEM_REBOOT:
1081 request = (MainThreadRequest) msg.obj;
1082 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001083 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001084 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001085 case EVENT_CMD_MODEM_REBOOT_DONE:
1086 handleNullReturnEvent(msg, "rebootModem");
1087 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001088 default:
1089 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1090 break;
1091 }
1092 }
Jake Hambye994d462014-02-03 13:10:13 -08001093
Pengquan Menga1bb6272018-09-06 09:59:22 -07001094 private void notifyRequester(MainThreadRequest request) {
1095 synchronized (request) {
1096 request.notifyAll();
1097 }
1098 }
1099
Jake Hambye994d462014-02-03 13:10:13 -08001100 private void handleNullReturnEvent(Message msg, String command) {
1101 AsyncResult ar = (AsyncResult) msg.obj;
1102 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null) {
1104 request.result = true;
1105 } else {
1106 request.result = false;
1107 if (ar.exception instanceof CommandException) {
1108 loge(command + ": CommandException: " + ar.exception);
1109 } else {
1110 loge(command + ": Unknown exception");
1111 }
1112 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001113 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001115 }
1116
1117 /**
1118 * Posts the specified command to be executed on the main thread,
1119 * waits for the request to complete, and returns the result.
1120 * @see #sendRequestAsync
1121 */
1122 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001123 return sendRequest(
1124 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001125 }
1126
1127 /**
1128 * Posts the specified command to be executed on the main thread,
1129 * waits for the request to complete, and returns the result.
1130 * @see #sendRequestAsync
1131 */
1132 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1133 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001134 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001135 }
1136
1137 /**
1138 * Posts the specified command to be executed on the main thread,
1139 * waits for the request to complete, and returns the result.
1140 * @see #sendRequestAsync
1141 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001142 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001143 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001144 }
1145
1146 /**
1147 * Posts the specified command to be executed on the main thread,
1148 * waits for the request to complete, and returns the result.
1149 * @see #sendRequestAsync
1150 */
Nathan Harold92bed182018-10-12 18:16:49 -07001151 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1152 return sendRequest(command, argument, subId, null, workSource);
1153 }
1154
1155 /**
1156 * Posts the specified command to be executed on the main thread,
1157 * waits for the request to complete, and returns the result.
1158 * @see #sendRequestAsync
1159 */
1160 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1161 return sendRequest(
1162 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1163 }
1164
1165 /**
1166 * Posts the specified command to be executed on the main thread,
1167 * waits for the request to complete, and returns the result.
1168 * @see #sendRequestAsync
1169 */
1170 private Object sendRequest(
1171 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1173 throw new RuntimeException("This method will deadlock if called from the main thread.");
1174 }
1175
Nathan Harold92bed182018-10-12 18:16:49 -07001176 MainThreadRequest request = null;
1177 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1178 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1179 } else if (phone != null) {
1180 request = new MainThreadRequest(argument, phone, workSource);
1181 } else {
1182 request = new MainThreadRequest(argument, subId, workSource);
1183 }
1184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 Message msg = mMainThreadHandler.obtainMessage(command, request);
1186 msg.sendToTarget();
1187
1188 // Wait for the request to complete
1189 synchronized (request) {
1190 while (request.result == null) {
1191 try {
1192 request.wait();
1193 } catch (InterruptedException e) {
1194 // Do nothing, go back and wait until the request is complete
1195 }
1196 }
1197 }
1198 return request.result;
1199 }
1200
1201 /**
1202 * Asynchronous ("fire and forget") version of sendRequest():
1203 * Posts the specified command to be executed on the main thread, and
1204 * returns immediately.
1205 * @see #sendRequest
1206 */
1207 private void sendRequestAsync(int command) {
1208 mMainThreadHandler.sendEmptyMessage(command);
1209 }
1210
1211 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001212 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001213 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001214 */
1215 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001216 sendRequestAsync(command, argument, null, null);
1217 }
1218
1219 /**
1220 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1221 * @see {@link #sendRequest(int,Object)}
1222 */
1223 private void sendRequestAsync(
1224 int command, Object argument, Phone phone, WorkSource workSource) {
1225 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001226 Message msg = mMainThreadHandler.obtainMessage(command, request);
1227 msg.sendToTarget();
1228 }
1229
1230 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 * Initialize the singleton PhoneInterfaceManager instance.
1232 * This is only done once, at startup, from PhoneApp.onCreate().
1233 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001234 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 synchronized (PhoneInterfaceManager.class) {
1236 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001237 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238 } else {
1239 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1240 }
1241 return sInstance;
1242 }
1243 }
1244
1245 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001246 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001249 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1251 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001252 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001253 mTelephonySharedPreferences =
1254 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001255 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001256 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 publish();
1259 }
1260
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001261 private Phone getDefaultPhone() {
1262 Phone thePhone = getPhone(getDefaultSubscription());
1263 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1264 }
1265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 private void publish() {
1267 if (DBG) log("publish: " + this);
1268
1269 ServiceManager.addService("phone", this);
1270 }
1271
Stuart Scott584921c2015-01-15 17:10:34 -08001272 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001273 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001274 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001275 }
1276
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001277 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1278 Phone phone = getPhoneFromRequest(request);
1279 return phone == null ? null :
1280 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1281 }
1282
Wink Saville36469e72014-06-11 15:17:00 -07001283 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001284 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001285 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287
1288 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001289 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001290 }
1291
Wink Savilleb564aae2014-10-23 10:18:09 -07001292 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 if (DBG) log("dial: " + number);
1294 // No permission check needed here: This is just a wrapper around the
1295 // ACTION_DIAL intent, which is available to any app since it puts up
1296 // the UI before it does anything.
1297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001298 final long identity = Binder.clearCallingIdentity();
1299 try {
1300 String url = createTelUrl(number);
1301 if (url == null) {
1302 return;
1303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001305 // PENDING: should we just silently fail if phone is offhook or ringing?
1306 PhoneConstants.State state = mCM.getState(subId);
1307 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1308 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1309 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1310 mApp.startActivity(intent);
1311 }
1312 } finally {
1313 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 }
1315 }
1316
1317 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001318 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001319 }
1320
Wink Savilleb564aae2014-10-23 10:18:09 -07001321 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 if (DBG) log("call: " + number);
1323
1324 // This is just a wrapper around the ACTION_CALL intent, but we still
1325 // need to do a permission check since we're calling startActivity()
1326 // from the context of the phone app.
1327 enforceCallPermission();
1328
1329 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1330 != AppOpsManager.MODE_ALLOWED) {
1331 return;
1332 }
1333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001334 final long identity = Binder.clearCallingIdentity();
1335 try {
1336 String url = createTelUrl(number);
1337 if (url == null) {
1338 return;
1339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001341 boolean isValid = false;
1342 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1343 if (slist != null) {
1344 for (SubscriptionInfo subInfoRecord : slist) {
1345 if (subInfoRecord.getSubscriptionId() == subId) {
1346 isValid = true;
1347 break;
1348 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001349 }
Wink Saville08874612014-08-31 19:19:58 -07001350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001351 if (!isValid) {
1352 return;
1353 }
Wink Saville08874612014-08-31 19:19:58 -07001354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001355 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1356 intent.putExtra(SUBSCRIPTION_KEY, subId);
1357 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1358 mApp.startActivity(intent);
1359 } finally {
1360 Binder.restoreCallingIdentity(identity);
1361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 }
1363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001366 }
1367
Wink Savilleb564aae2014-10-23 10:18:09 -07001368 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001369 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001370 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1371 }
1372
1373 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001379 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1380 }
1381
1382 /** {@hide} */
1383 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001384 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001385 }
1386
Wink Savilleb564aae2014-10-23 10:18:09 -07001387 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001389
1390 final long identity = Binder.clearCallingIdentity();
1391 try {
1392 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1393 checkSimPin.start();
1394 return checkSimPin.unlockSim(null, pin);
1395 } finally {
1396 Binder.restoreCallingIdentity(identity);
1397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 }
1399
Wink Saville9de0f752013-10-22 19:04:03 -07001400 /** {@hide} */
1401 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001402 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001403 }
1404
Wink Savilleb564aae2014-10-23 10:18:09 -07001405 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001407
1408 final long identity = Binder.clearCallingIdentity();
1409 try {
1410 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1411 checkSimPuk.start();
1412 return checkSimPuk.unlockSim(puk, pin);
1413 } finally {
1414 Binder.restoreCallingIdentity(identity);
1415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 }
1417
1418 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001419 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 * a synchronous one.
1421 */
1422 private static class UnlockSim extends Thread {
1423
1424 private final IccCard mSimCard;
1425
1426 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001427 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1428 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429
1430 // For replies from SimCard interface
1431 private Handler mHandler;
1432
1433 // For async handler to identify request type
1434 private static final int SUPPLY_PIN_COMPLETE = 100;
1435
1436 public UnlockSim(IccCard simCard) {
1437 mSimCard = simCard;
1438 }
1439
1440 @Override
1441 public void run() {
1442 Looper.prepare();
1443 synchronized (UnlockSim.this) {
1444 mHandler = new Handler() {
1445 @Override
1446 public void handleMessage(Message msg) {
1447 AsyncResult ar = (AsyncResult) msg.obj;
1448 switch (msg.what) {
1449 case SUPPLY_PIN_COMPLETE:
1450 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1451 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001452 mRetryCount = msg.arg1;
1453 if (ar.exception != null) {
1454 if (ar.exception instanceof CommandException &&
1455 ((CommandException)(ar.exception)).getCommandError()
1456 == CommandException.Error.PASSWORD_INCORRECT) {
1457 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1458 } else {
1459 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1460 }
1461 } else {
1462 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 mDone = true;
1465 UnlockSim.this.notifyAll();
1466 }
1467 break;
1468 }
1469 }
1470 };
1471 UnlockSim.this.notifyAll();
1472 }
1473 Looper.loop();
1474 }
1475
1476 /*
1477 * Use PIN or PUK to unlock SIM card
1478 *
1479 * If PUK is null, unlock SIM card with PIN
1480 *
1481 * If PUK is not null, unlock SIM card with PUK and set PIN code
1482 */
Wink Saville9de0f752013-10-22 19:04:03 -07001483 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484
1485 while (mHandler == null) {
1486 try {
1487 wait();
1488 } catch (InterruptedException e) {
1489 Thread.currentThread().interrupt();
1490 }
1491 }
1492 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1493
1494 if (puk == null) {
1495 mSimCard.supplyPin(pin, callback);
1496 } else {
1497 mSimCard.supplyPuk(puk, pin, callback);
1498 }
1499
1500 while (!mDone) {
1501 try {
1502 Log.d(LOG_TAG, "wait for done");
1503 wait();
1504 } catch (InterruptedException e) {
1505 // Restore the interrupted status
1506 Thread.currentThread().interrupt();
1507 }
1508 }
1509 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001510 int[] resultArray = new int[2];
1511 resultArray[0] = mResult;
1512 resultArray[1] = mRetryCount;
1513 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514 }
1515 }
1516
1517 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001518 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001519
1520 }
1521
Wink Savilleb564aae2014-10-23 10:18:09 -07001522 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523 // No permission check needed here: this call is harmless, and it's
1524 // needed for the ServiceState.requestStateUpdate() call (which is
1525 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001526 final long identity = Binder.clearCallingIdentity();
1527 try {
1528 final Phone phone = getPhone(subId);
1529 if (phone != null) {
1530 phone.updateServiceLocation();
1531 }
1532 } finally {
1533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001537 @Override
1538 public boolean isRadioOn(String callingPackage) {
1539 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001540 }
1541
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001542 @Override
1543 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001545 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001546 return false;
1547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001548
1549 final long identity = Binder.clearCallingIdentity();
1550 try {
1551 return isRadioOnForSubscriber(subId);
1552 } finally {
1553 Binder.restoreCallingIdentity(identity);
1554 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001555 }
1556
1557 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 final Phone phone = getPhone(subId);
1561 if (phone != null) {
1562 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1563 } else {
1564 return false;
1565 }
1566 } finally {
1567 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
1571 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001572 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 }
Wink Saville36469e72014-06-11 15:17:00 -07001574
Wink Savilleb564aae2014-10-23 10:18:09 -07001575 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001577
1578 final long identity = Binder.clearCallingIdentity();
1579 try {
1580 final Phone phone = getPhone(subId);
1581 if (phone != null) {
1582 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1583 }
1584 } finally {
1585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 }
Wink Saville36469e72014-06-11 15:17:00 -07001587 }
1588
1589 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001590 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001591 }
1592
Wink Savilleb564aae2014-10-23 10:18:09 -07001593 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001594 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001595
1596 final long identity = Binder.clearCallingIdentity();
1597 try {
1598 final Phone phone = getPhone(subId);
1599 if (phone == null) {
1600 return false;
1601 }
1602 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1603 toggleRadioOnOffForSubscriber(subId);
1604 }
1605 return true;
1606 } finally {
1607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 }
Wink Saville36469e72014-06-11 15:17:00 -07001610
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001611 public boolean needMobileRadioShutdown() {
1612 /*
1613 * If any of the Radios are available, it will need to be
1614 * shutdown. So return true if any Radio is available.
1615 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001616 final long identity = Binder.clearCallingIdentity();
1617 try {
1618 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1619 Phone phone = PhoneFactory.getPhone(i);
1620 if (phone != null && phone.isRadioAvailable()) return true;
1621 }
1622 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1623 return false;
1624 } finally {
1625 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001626 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 }
1628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001629 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001630 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001631 enforceModifyPermission();
1632
1633 final long identity = Binder.clearCallingIdentity();
1634 try {
1635 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1636 logv("Shutting down Phone " + i);
1637 shutdownRadioUsingPhoneId(i);
1638 }
1639 } finally {
1640 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001641 }
1642 }
1643
1644 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001645 Phone phone = PhoneFactory.getPhone(phoneId);
1646 if (phone != null && phone.isRadioAvailable()) {
1647 phone.shutdownRadio();
1648 }
1649 }
1650
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001653
1654 final long identity = Binder.clearCallingIdentity();
1655 try {
1656 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1657 if (defaultPhone != null) {
1658 defaultPhone.setRadioPower(turnOn);
1659 return true;
1660 } else {
1661 loge("There's no default phone.");
1662 return false;
1663 }
1664 } finally {
1665 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001666 }
Wink Saville36469e72014-06-11 15:17:00 -07001667 }
1668
Wink Savilleb564aae2014-10-23 10:18:09 -07001669 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001671
1672 final long identity = Binder.clearCallingIdentity();
1673 try {
1674 final Phone phone = getPhone(subId);
1675 if (phone != null) {
1676 phone.setRadioPower(turnOn);
1677 return true;
1678 } else {
1679 return false;
1680 }
1681 } finally {
1682 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 }
1685
Wink Saville36469e72014-06-11 15:17:00 -07001686 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 public boolean enableDataConnectivity() {
1689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001690
1691 final long identity = Binder.clearCallingIdentity();
1692 try {
1693 int subId = mSubscriptionController.getDefaultDataSubId();
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001696 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001697 return true;
1698 } else {
1699 return false;
1700 }
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
Wink Saville36469e72014-06-11 15:17:00 -07001706 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 public boolean disableDataConnectivity() {
1709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710
1711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 int subId = mSubscriptionController.getDefaultDataSubId();
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001716 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 return true;
1718 } else {
1719 return false;
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Sanket Padawe356d7632015-06-22 14:03:32 -07001726 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001727 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 final Phone phone = getPhone(subId);
1731 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001732 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 } else {
1734 return false;
1735 }
1736 } finally {
1737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 }
1740
1741 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001742 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001743 }
1744
pkanwarae03a6b2016-11-06 20:37:09 -08001745 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746 enforceCallPermission();
1747
1748 final long identity = Binder.clearCallingIdentity();
1749 try {
1750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1751 return;
1752 }
1753 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1754 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
1757 }
pkanwar32d516d2016-10-14 19:37:38 -07001758 };
1759
Wink Savilleb564aae2014-10-23 10:18:09 -07001760 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762
1763 final long identity = Binder.clearCallingIdentity();
1764 try {
1765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1766 return false;
1767 }
1768 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1769 } finally {
1770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001775 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001776 }
1777
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001778 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 final long identity = Binder.clearCallingIdentity();
1780 try {
1781 Phone phone = PhoneFactory.getPhone(slotIndex);
1782 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1783 PhoneConstantConversions.convertCallState(phone.getState());
1784 } finally {
1785 Binder.restoreCallingIdentity(identity);
1786 }
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 getDataState() {
Malcolm Chenaa4a8532018-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 PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1796 } else {
1797 return PhoneConstantConversions.convertDataState(
1798 PhoneConstants.DataState.DISCONNECTED);
1799 }
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001802 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 }
1804
Sanket Padawe356d7632015-06-22 14:03:32 -07001805 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001807 final long identity = Binder.clearCallingIdentity();
1808 try {
1809 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1810 if (phone != null) {
1811 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1812 } else {
1813 return TelephonyManager.DATA_ACTIVITY_NONE;
1814 }
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
1820 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001821 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001822 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001823 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001824 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1825 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001826 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001829 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001830 final long identity = Binder.clearCallingIdentity();
1831 try {
1832 if (DBG_LOC) log("getCellLocation: is active user");
1833 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001834 int subId = mSubscriptionController.getDefaultDataSubId();
1835 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1836 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837 return data;
1838 } finally {
1839 Binder.restoreCallingIdentity(identity);
1840 }
Svetoslav64fad262015-04-14 14:35:21 -07001841 }
1842
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001844 public String getNetworkCountryIsoForPhone(int phoneId) {
1845 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1846 // registered cell info, so return a NULL country instead.
1847 final long identity = Binder.clearCallingIdentity();
1848 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001849 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1850 // Get default phone in this case.
1851 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1852 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001853 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001854 // Todo: fix this when we can get the actual cellular network info when the device
1855 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001856 if (TelephonyManager.NETWORK_TYPE_IWLAN
1857 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1858 return "";
1859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860 Phone phone = PhoneFactory.getPhone(phoneId);
1861 if (phone != null) {
1862 ServiceStateTracker sst = phone.getServiceStateTracker();
1863 if (sst != null) {
1864 LocaleTracker lt = sst.getLocaleTracker();
1865 if (lt != null) {
1866 return lt.getCurrentCountry();
1867 }
1868 }
1869 }
1870 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001871 } finally {
1872 Binder.restoreCallingIdentity(identity);
1873 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001874 }
1875
1876 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001878 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001879 }
1880
Sanket Padawe356d7632015-06-22 14:03:32 -07001881 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001882 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 mApp.enforceCallingOrSelfPermission(
1884 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885
1886 final long identity = Binder.clearCallingIdentity();
1887 try {
1888 final Phone phone = getPhone(subId);
1889 if (phone != null) {
1890 phone.enableLocationUpdates();
1891 }
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 }
1896
1897 @Override
1898 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001899 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001903 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 mApp.enforceCallingOrSelfPermission(
1905 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001906
1907 final long identity = Binder.clearCallingIdentity();
1908 try {
1909 final Phone phone = getPhone(subId);
1910 if (phone != null) {
1911 phone.disableLocationUpdates();
1912 }
1913 } finally {
1914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
Nathan Harold31d7ff32018-10-15 20:20:30 -07001918 /**
1919 * Returns the target SDK version number for a given package name.
1920 *
1921 * @return target SDK if the package is found or INT_MAX.
1922 */
1923 private int getTargetSdk(String packageName) {
1924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001925 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1926 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001927 if (ai != null) return ai.targetSdkVersion;
1928 } catch (PackageManager.NameNotFoundException unexpected) {
1929 }
1930 return Integer.MAX_VALUE;
1931 }
1932
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 @Override
1934 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001935 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1936 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001937 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1938 throw new SecurityException(
1939 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1940 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1943 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1944 return null;
1945 }
Svetoslav64fad262015-04-14 14:35:21 -07001946
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001947 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948
Nathan Haroldf180aac2018-06-01 18:43:55 -07001949 List<CellInfo> info = getAllCellInfo(callingPackage);
1950 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951
Nathan Haroldf180aac2018-06-01 18:43:55 -07001952 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1953 for (CellInfo ci : info) {
1954 if (ci instanceof CellInfoGsm) {
1955 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1956 } else if (ci instanceof CellInfoWcdma) {
1957 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1958 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001960 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
1962
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001963 private List<CellInfo> getCachedCellInfo() {
1964 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1965 for (Phone phone : PhoneFactory.getPhones()) {
1966 List<CellInfo> info = phone.getAllCellInfo();
1967 if (info != null) cellInfos.addAll(info);
1968 }
1969 return cellInfos;
1970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971
1972 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001973 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001974 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001975 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001976 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001977 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001978 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
1980
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001981 final int targetSdk = getTargetSdk(callingPackage);
1982 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1983 return getCachedCellInfo();
1984 }
1985
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001986 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 final long identity = Binder.clearCallingIdentity();
1989 try {
1990 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1991 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001992 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001993 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001994 if (info != null) cellInfos.addAll(info);
1995 }
1996 return cellInfos;
1997 } finally {
1998 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000 }
2001
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002002 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002003 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2004 requestCellInfoUpdateInternal(
2005 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2006 }
2007
2008 @Override
2009 public void requestCellInfoUpdateWithWorkSource(
2010 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2011 enforceModifyPermission();
2012 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2013 }
2014
2015 private void requestCellInfoUpdateInternal(
2016 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002017 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002018 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002019 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2020 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002021 return;
2022 }
2023
2024 final Phone phone = getPhone(subId);
2025 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2026
2027 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2028 }
2029
2030 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002032 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034
2035 final long identity = Binder.clearCallingIdentity();
2036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002037 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 } finally {
2039 Binder.restoreCallingIdentity(identity);
2040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 }
2042
Shishir Agrawala9f32182016-04-12 12:00:16 -07002043 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002044 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002045 Phone phone = PhoneFactory.getPhone(slotIndex);
2046 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002047 return null;
2048 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002049 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002050 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2051 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002052 return null;
2053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 return phone.getImei();
2058 } finally {
2059 Binder.restoreCallingIdentity(identity);
2060 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002061 }
2062
2063 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002064 public String getTypeAllocationCodeForSlot(int slotIndex) {
2065 Phone phone = PhoneFactory.getPhone(slotIndex);
2066 String tac = null;
2067 if (phone != null) {
2068 String imei = phone.getImei();
2069 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2070 }
2071 return tac;
2072 }
2073
2074 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002075 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002076 Phone phone = PhoneFactory.getPhone(slotIndex);
2077 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002078 return null;
2079 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002080
Jeff Davidson913390f2018-02-23 17:11:49 -08002081 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002082 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2083 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002084 return null;
2085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086
2087 final long identity = Binder.clearCallingIdentity();
2088 try {
2089 return phone.getMeid();
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
2092 }
Jack Yu2af8d712017-03-15 17:14:14 -07002093 }
2094
2095 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002096 public String getManufacturerCodeForSlot(int slotIndex) {
2097 Phone phone = PhoneFactory.getPhone(slotIndex);
2098 String manufacturerCode = null;
2099 if (phone != null) {
2100 String meid = phone.getMeid();
2101 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2102 }
2103 return manufacturerCode;
2104 }
2105
2106 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002107 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002108 Phone phone = PhoneFactory.getPhone(slotIndex);
2109 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002110 return null;
2111 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002112 int subId = phone.getSubId();
2113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2114 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2115 return null;
2116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117
2118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 return phone.getDeviceSvn();
2121 } finally {
2122 Binder.restoreCallingIdentity(identity);
2123 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002124 }
2125
fionaxu43304da2017-11-27 22:51:16 -08002126 @Override
2127 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002128 final long identity = Binder.clearCallingIdentity();
2129 try {
2130 final Phone phone = getPhone(subId);
2131 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
2134 }
fionaxu43304da2017-11-27 22:51:16 -08002135 }
2136
2137 @Override
2138 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 final Phone phone = getPhone(subId);
2142 return phone == null ? null : phone.getCarrierName();
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
2145 }
fionaxu43304da2017-11-27 22:51:16 -08002146 }
2147
calvinpanffe225e2018-11-01 19:43:06 +08002148 @Override
chen xu25637222018-11-04 17:17:00 -08002149 public int getSubscriptionPreciseCarrierId(int subId) {
2150 final long identity = Binder.clearCallingIdentity();
2151 try {
2152 final Phone phone = getPhone(subId);
2153 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2154 : phone.getPreciseCarrierId();
2155 } finally {
2156 Binder.restoreCallingIdentity(identity);
2157 }
2158 }
2159
2160 @Override
2161 public String getSubscriptionPreciseCarrierName(int subId) {
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 final Phone phone = getPhone(subId);
2165 return phone == null ? null : phone.getPreciseCarrierName();
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
2169 }
2170
chen xu651eec72018-11-11 19:03:44 -08002171 @Override
chen xu864e11c2018-12-06 22:10:03 -08002172 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2173 if (!isSubscriptionMccMnc) {
2174 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2175 }
chen xu651eec72018-11-11 19:03:44 -08002176 final Phone phone = PhoneFactory.getPhone(slotIndex);
2177 if (phone == null) {
2178 return TelephonyManager.UNKNOWN_CARRIER_ID;
2179 }
2180 final long identity = Binder.clearCallingIdentity();
2181 try {
2182 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
2185 }
2186 }
2187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 //
2189 // Internal helper methods.
2190 //
2191
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002192 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2194 *
2195 * @throws SecurityException if the caller does not have the required permission
2196 */
2197 private void enforceModifyPermission() {
2198 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2199 }
2200
2201 /**
2202 * Make sure the caller has the CALL_PHONE permission.
2203 *
2204 * @throws SecurityException if the caller does not have the required permission
2205 */
2206 private void enforceCallPermission() {
2207 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2208 }
2209
Stuart Scott8eef64f2015-04-08 15:13:54 -07002210 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002211 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002212 "ConnectivityService");
2213 }
2214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 private String createTelUrl(String number) {
2216 if (TextUtils.isEmpty(number)) {
2217 return null;
2218 }
2219
Jake Hambye994d462014-02-03 13:10:13 -08002220 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 }
2222
Ihab Awadf9e92732013-12-05 18:02:52 -08002223 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2225 }
2226
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002227 private static void logv(String msg) {
2228 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2229 }
2230
Ihab Awadf9e92732013-12-05 18:02:52 -08002231 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2233 }
2234
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002235 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002237 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002238 }
2239
Sanket Padawe356d7632015-06-22 14:03:32 -07002240 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002241 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 final Phone phone = PhoneFactory.getPhone(slotIndex);
2245 if (phone == null) {
2246 return PhoneConstants.PHONE_TYPE_NONE;
2247 } else {
2248 return phone.getPhoneType();
2249 }
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
2255 /**
2256 * Returns the CDMA ERI icon index to display
2257 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002258 @Override
2259 public int getCdmaEriIconIndex(String callingPackage) {
2260 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002261 }
2262
Sanket Padawe356d7632015-06-22 14:03:32 -07002263 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002264 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002266 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002267 return -1;
2268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269
2270 final long identity = Binder.clearCallingIdentity();
2271 try {
2272 final Phone phone = getPhone(subId);
2273 if (phone != null) {
2274 return phone.getCdmaEriIconIndex();
2275 } else {
2276 return -1;
2277 }
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
2283 /**
2284 * Returns the CDMA ERI icon mode,
2285 * 0 - ON
2286 * 1 - FLASHING
2287 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002288 @Override
2289 public int getCdmaEriIconMode(String callingPackage) {
2290 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002291 }
2292
Sanket Padawe356d7632015-06-22 14:03:32 -07002293 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002294 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002296 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002297 return -1;
2298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299
2300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 final Phone phone = getPhone(subId);
2303 if (phone != null) {
2304 return phone.getCdmaEriIconMode();
2305 } else {
2306 return -1;
2307 }
2308 } finally {
2309 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 }
2312
2313 /**
2314 * Returns the CDMA ERI text,
2315 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 @Override
2317 public String getCdmaEriText(String callingPackage) {
2318 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002319 }
2320
Sanket Padawe356d7632015-06-22 14:03:32 -07002321 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002324 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 return null;
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 final Phone phone = getPhone(subId);
2331 if (phone != null) {
2332 return phone.getCdmaEriText();
2333 } else {
2334 return null;
2335 }
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
2341 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002342 * Returns the CDMA MDN.
2343 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002345 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2347 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002352 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002353 return phone.getLine1Number();
2354 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002355 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356 return null;
2357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002360 }
2361 }
2362
2363 /**
2364 * Returns the CDMA MIN.
2365 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002366 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002367 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2369 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2375 return phone.getCdmaMin();
2376 } else {
2377 return null;
2378 }
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002381 }
2382 }
2383
Hall Liud892bec2018-11-30 14:51:45 -08002384 @Override
2385 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2386 INumberVerificationCallback callback, String callingPackage) {
2387 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2388 != PERMISSION_GRANTED) {
2389 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2390 }
2391 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2392
2393 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2394 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2395 throw new SecurityException("Calling package must be configured in the device config");
2396 }
2397
2398 if (range == null) {
2399 throw new NullPointerException("Range must be non-null");
2400 }
2401
2402 timeoutMillis = Math.min(timeoutMillis,
2403 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2404
2405 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2406 }
2407
Junda Liuca05d5d2014-08-14 22:36:34 -07002408 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 * Returns true if CDMA provisioning needs to run.
2410 */
2411 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412 final long identity = Binder.clearCallingIdentity();
2413 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002414 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 } finally {
2416 Binder.restoreCallingIdentity(identity);
2417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
2420 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002421 * Sets the voice mail number of a given subId.
2422 */
2423 @Override
2424 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002425 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2430 new Pair<String, String>(alphaTag, number), new Integer(subId));
2431 return success;
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
2434 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002435 }
2436
Ta-wei Yen87c49842016-05-13 21:19:52 -07002437 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002438 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2439 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002440 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002441 if (!TextUtils.equals(callingPackage, systemDialer)) {
2442 throw new SecurityException("caller must be system dialer");
2443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444
2445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2448 if (phoneAccountHandle == null) {
2449 return null;
2450 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002451 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 } finally {
2453 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002454 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002455 }
2456
2457 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002458 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002461 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002462 return null;
2463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002465 final long identity = Binder.clearCallingIdentity();
2466 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002467 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002468 } finally {
2469 Binder.restoreCallingIdentity(identity);
2470 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002471 }
2472
2473 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002474 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2475 VisualVoicemailSmsFilterSettings settings) {
2476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477
2478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002481 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 } finally {
2483 Binder.restoreCallingIdentity(identity);
2484 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002485 }
2486
2487 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002488 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002494 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495 } finally {
2496 Binder.restoreCallingIdentity(identity);
2497 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002498 }
2499
2500 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002501 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2502 String callingPackage, int subId) {
2503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002508 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002512 }
2513
2514 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002515 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002516 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002521 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522 } finally {
2523 Binder.restoreCallingIdentity(identity);
2524 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002525 }
2526
2527 @Override
2528 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2529 String number, int port, String text, PendingIntent sentIntent) {
2530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002531 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002532 enforceSendSmsPermission();
2533 // Make the calls as the phone process.
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2537 if (port == 0) {
2538 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2539 sentIntent, null, false);
2540 } else {
2541 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2542 smsManager.sendDataMessageWithSelfPermissions(number, null,
2543 (short) port, data, sentIntent, null);
2544 }
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002548 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002549 /**
fionaxu0152e512016-11-14 13:36:14 -08002550 * Sets the voice activation state of a given subId.
2551 */
2552 @Override
2553 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2555 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 final Phone phone = getPhone(subId);
2560 if (phone != null) {
2561 phone.setVoiceActivationState(activationState);
2562 } else {
2563 loge("setVoiceActivationState fails with invalid subId: " + subId);
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002567 }
2568 }
2569
2570 /**
2571 * Sets the data activation state of a given subId.
2572 */
2573 @Override
2574 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2576 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 final Phone phone = getPhone(subId);
2581 if (phone != null) {
2582 phone.setDataActivationState(activationState);
2583 } else {
2584 loge("setVoiceActivationState fails with invalid subId: " + subId);
2585 }
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002588 }
2589 }
2590
2591 /**
2592 * Returns the voice activation state of a given subId.
2593 */
2594 @Override
2595 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002596 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
fionaxu0152e512016-11-14 13:36:14 -08002598 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 final long identity = Binder.clearCallingIdentity();
2600 try {
2601 if (phone != null) {
2602 return phone.getVoiceActivationState();
2603 } else {
2604 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002608 }
2609 }
2610
2611 /**
2612 * Returns the data activation state of a given subId.
2613 */
2614 @Override
2615 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002616 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617
fionaxu0152e512016-11-14 13:36:14 -08002618 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 if (phone != null) {
2622 return phone.getDataActivationState();
2623 } else {
2624 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002628 }
2629 }
2630
2631 /**
Wink Saville36469e72014-06-11 15:17:00 -07002632 * Returns the unread count of voicemails for a subId
2633 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002634 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002635 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2637 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2638 return 0;
2639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
2643 if (phone != null) {
2644 return phone.getVoiceMessageCount();
2645 } else {
2646 return 0;
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 }
2652
2653 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002654 * returns true, if the device is in a state where both voice and data
2655 * are supported simultaneously. This can change based on location or network condition.
2656 */
2657 @Override
2658 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
2662 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002666 }
2667
2668 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002669 * Send the dialer code if called from the current default dialer or the caller has
2670 * carrier privilege.
2671 * @param inputCode The dialer code to send
2672 */
2673 @Override
2674 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002675 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002677 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2678 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002679 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002680 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2681 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002686 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
fionaxu235cc5e2017-03-06 22:25:57 -08002690 }
2691
2692 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002693 * Returns the data network type.
2694 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 *
2696 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2697 */
2698 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002699 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 final Phone phone = getPhone(getDefaultSubscription());
2703 if (phone != null) {
2704 return phone.getServiceState().getDataNetworkType();
2705 } else {
2706 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2707 }
2708 } finally {
2709 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002710 }
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Pengquan Menga1bb6272018-09-06 09:59:22 -07002713 @Override
2714 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002715 if (!isActiveSubscription(subId)) {
2716 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2717 }
2718
Pengquan Menga1bb6272018-09-06 09:59:22 -07002719 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2720 }
2721
Brad Ebinger35c841c2018-10-01 10:40:55 -07002722 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002723 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2724 throws RemoteException {
2725 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2727 final long token = Binder.clearCallingIdentity();
2728 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002729 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002730 .addRegistrationCallbackForSubscription(c, subId);
2731 } finally {
2732 Binder.restoreCallingIdentity(token);
2733 }
2734 }
2735
2736 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002737 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2738 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2740 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002742 .removeRegistrationCallbackForSubscription(c, subId));
2743 }
2744
2745 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002746 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2747 throws RemoteException {
2748 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002749 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2750 final long token = Binder.clearCallingIdentity();
2751 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002752 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002753 .addCapabilitiesCallbackForSubscription(c, subId);
2754 } finally {
2755 Binder.restoreCallingIdentity(token);
2756 }
2757 }
2758
2759 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002760 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2761 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002762 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2763 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002765 .removeCapabilitiesCallbackForSubscription(c, subId));
2766 }
2767
2768 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002769 public boolean isCapable(int subId, int capability, int regTech) {
2770 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2772 final long token = Binder.clearCallingIdentity();
2773 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002774 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002775 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2776 } catch (ImsException e) {
2777 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2778 return false;
2779 } finally {
2780 Binder.restoreCallingIdentity(token);
2781 }
2782 }
2783
2784 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002785 public boolean isAvailable(int subId, int capability, int regTech) {
2786 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002787 final long token = Binder.clearCallingIdentity();
2788 try {
2789 Phone phone = getPhone(subId);
2790 if (phone == null) return false;
2791 return phone.isImsCapabilityAvailable(capability, regTech);
2792 } finally {
2793 Binder.restoreCallingIdentity(token);
2794 }
2795 }
2796
2797 @Override
2798 public boolean isAdvancedCallingSettingEnabled(int subId) {
2799 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2801 final long token = Binder.clearCallingIdentity();
2802 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002803 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002804 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2805 } finally {
2806 Binder.restoreCallingIdentity(token);
2807 }
2808 }
2809
2810 @Override
2811 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2813 "setAdvancedCallingSetting");
2814 final long identity = Binder.clearCallingIdentity();
2815 try {
2816 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002817 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002818 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
2821 }
2822 }
2823
2824 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002825 public boolean isVtSettingEnabled(int subId) {
2826 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002830 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002831 getSlotIndexOrException(subId)).isVtEnabledByUser();
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
2834 }
2835 }
2836
2837 @Override
2838 public void setVtSetting(int subId, boolean isEnabled) {
2839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2840 "setVtSetting");
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002844 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
2848 }
2849
2850 @Override
2851 public boolean isVoWiFiSettingEnabled(int subId) {
2852 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002856 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002857 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
2860 }
2861 }
2862
2863 @Override
2864 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2866 "setVoWiFiSetting");
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002871 } finally {
2872 Binder.restoreCallingIdentity(identity);
2873 }
2874 }
2875
2876 @Override
2877 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2878 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002882 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002883 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
2886 }
2887 }
2888
2889 @Override
2890 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2892 "setVoWiFiRoamingSetting");
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002896 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002897 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
2900 }
2901 }
2902
2903 @Override
2904 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2906 "setVoWiFiNonPersistent");
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002910 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002911 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
2915 }
2916
2917 @Override
2918 public int getVoWiFiModeSetting(int subId) {
2919 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002923 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002924 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
2927 }
2928 }
2929
2930 @Override
2931 public void setVoWiFiModeSetting(int subId, int mode) {
2932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2933 "setVoWiFiModeSetting");
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002937 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002938 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
2942 }
2943
2944 @Override
2945 public int getVoWiFiRoamingModeSetting(int subId) {
2946 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002950 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
2955 }
2956
2957 @Override
2958 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2960 "setVoWiFiRoamingModeSetting");
2961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
2972 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2974 "setRttCapabilityEnabled");
2975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
2983 }
2984
2985 @Override
2986 public boolean isTtyOverVolteEnabled(int subId) {
2987 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002998 @Override
2999 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3000 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003005 .getConfigInterface().addConfigCallback(callback);
3006 } catch (ImsException e) {
3007 throw new IllegalArgumentException(e.getMessage());
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 @Override
3014 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3015 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003019 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003020 .getConfigInterface().removeConfigCallback(callback);
3021 } catch (ImsException e) {
3022 throw new IllegalArgumentException(e.getMessage());
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
3026 }
3027
3028 @Override
3029 public int getImsProvisioningInt(int subId, int key) {
3030 enforceReadPrivilegedPermission("getImsProvisioningInt");
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 return ImsManager.getInstance(mApp,
3035 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003036 } catch (ImsException e) {
3037 throw new IllegalArgumentException(e.getMessage());
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
3041 }
3042
3043 @Override
3044 public String getImsProvisioningString(int subId, int key) {
3045 enforceReadPrivilegedPermission("getImsProvisioningString");
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049 return ImsManager.getInstance(mApp,
3050 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003051 } catch (ImsException e) {
3052 throw new IllegalArgumentException(e.getMessage());
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
3056 }
3057
3058 @Override
3059 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3061 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003065 return ImsManager.getInstance(mApp,
3066 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003067 } catch (ImsException e) {
3068 throw new IllegalArgumentException(e.getMessage());
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 @Override
3075 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3077 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003081 return ImsManager.getInstance(mApp,
3082 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003083 } catch (ImsException e) {
3084 throw new IllegalArgumentException(e.getMessage());
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
3088 }
3089
Brad Ebinger35c841c2018-10-01 10:40:55 -07003090 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3091 int slotId = SubscriptionManager.getSlotIndex(subId);
3092 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3093 throw new IllegalArgumentException("Invalid Subscription Id.");
3094 }
3095 return slotId;
3096 }
3097
Wink Saville36469e72014-06-11 15:17:00 -07003098 /**
3099 * Returns the network type for a subId
3100 */
3101 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003102 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003104 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003105 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3106 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 final Phone phone = getPhone(subId);
3111 if (phone != null) {
3112 return phone.getServiceState().getDataNetworkType();
3113 } else {
3114 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3115 }
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 }
3120
3121 /**
3122 * Returns the data network type
3123 */
3124 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003125 public int getDataNetworkType(String callingPackage) {
3126 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003127 }
3128
3129 /**
3130 * Returns the data network type for a subId
3131 */
3132 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003133 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003135 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003136 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3137 }
3138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 final Phone phone = getPhone(subId);
3142 if (phone != null) {
3143 return phone.getServiceState().getDataNetworkType();
3144 } else {
3145 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3146 }
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
3151
3152 /**
Wink Saville36469e72014-06-11 15:17:00 -07003153 * Returns the Voice network type for a subId
3154 */
3155 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003156 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003158 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003159 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3160 }
3161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 final Phone phone = getPhone(subId);
3165 if (phone != null) {
3166 return phone.getServiceState().getVoiceNetworkType();
3167 } else {
3168 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3169 }
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 }
3174
3175 /**
3176 * @return true if a ICC card is present
3177 */
3178 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003179 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003180 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3181 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003182 }
3183
3184 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003185 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003186 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003187 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003188 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 final Phone phone = PhoneFactory.getPhone(slotIndex);
3192 if (phone != null) {
3193 return phone.getIccCard().hasIccCard();
3194 } else {
3195 return false;
3196 }
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
3202 /**
3203 * Return if the current radio is LTE on CDMA. This
3204 * is a tri-state return value as for a period of time
3205 * the mode may be unknown.
3206 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003207 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003209 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003211 @Override
3212 public int getLteOnCdmaMode(String callingPackage) {
3213 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003214 }
3215
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003217 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003219 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003220 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3221 }
3222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 final Phone phone = getPhone(subId);
3226 if (phone == null) {
3227 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3228 } else {
3229 return phone.getLteOnCdmaMode();
3230 }
3231 } finally {
3232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003233 }
Wink Saville36469e72014-06-11 15:17:00 -07003234 }
3235
Wink Saville36469e72014-06-11 15:17:00 -07003236 /**
3237 * {@hide}
3238 * Returns Default subId, 0 in the case of single standby.
3239 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003240 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003241 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003242 }
3243
Shishir Agrawala9f32182016-04-12 12:00:16 -07003244 private int getSlotForDefaultSubscription() {
3245 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3246 }
3247
Wink Savilleb564aae2014-10-23 10:18:09 -07003248 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003249 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003251
Pengquan Menge92a50d2018-09-21 15:54:48 -07003252 private boolean isActiveSubscription(int subId) {
3253 return mSubscriptionController.isActiveSubId(subId);
3254 }
3255
Ihab Awadf2177b72013-11-25 13:33:23 -08003256 /**
3257 * @see android.telephony.TelephonyManager.WifiCallingChoices
3258 */
3259 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260 final long identity = Binder.clearCallingIdentity();
3261 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003262 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3264 getWhenToMakeWifiCallsDefaultPreference());
3265 } finally {
3266 Binder.restoreCallingIdentity(identity);
3267 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003268 }
3269
3270 /**
3271 * @see android.telephony.TelephonyManager.WifiCallingChoices
3272 */
3273 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003282 }
3283
Sailesh Nepald1e68152013-12-12 19:08:02 -08003284 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003285 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003286 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003287 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003288
Shishir Agrawal566b7612013-10-28 14:41:00 -07003289 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003290 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3291 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3293 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 if (TextUtils.equals(ISDR_AID, aid)) {
3299 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003300 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3301 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003302 if (bestComponent == null
3303 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3304 loge("The calling package is not allowed to access ISD-R.");
3305 throw new SecurityException(
3306 "The calling package is not allowed to access ISD-R.");
3307 }
Derek Tan740e1672017-06-27 14:56:27 -07003308 }
Derek Tan740e1672017-06-27 14:56:27 -07003309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 if (DBG) {
3311 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3312 }
3313 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3314 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3315 if (DBG) log("iccOpenLogicalChannel: " + response);
3316 return response;
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003320 }
3321
3322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003323 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3325 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3330 if (channel < 0) {
3331 return false;
3332 }
3333 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3334 if (DBG) log("iccCloseLogicalChannel: " + success);
3335 return success;
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003338 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339 }
3340
3341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003342 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003343 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 if (DBG) {
3350 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3351 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3352 + p3 + " data=" + data);
3353 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 if (channel < 0) {
3356 return "";
3357 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3360 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3361 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 // Append the returned status code to the end of the response payload.
3364 String s = Integer.toHexString(
3365 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3366 if (response.payload != null) {
3367 s = IccUtils.bytesToHexString(response.payload) + s;
3368 }
3369 return s;
3370 } finally {
3371 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003373 }
Jake Hambye994d462014-02-03 13:10:13 -08003374
Evan Charltonc66da362014-05-16 14:06:40 -07003375 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003376 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3377 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3379 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3385 && TextUtils.equals(ISDR_AID, data)) {
3386 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003387 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3388 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 if (bestComponent == null
3390 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3391 loge("The calling package is not allowed to select ISD-R.");
3392 throw new SecurityException(
3393 "The calling package is not allowed to select ISD-R.");
3394 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003395 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 if (DBG) {
3398 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3399 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3400 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3403 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3404 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406 // Append the returned status code to the end of the response payload.
3407 String s = Integer.toHexString(
3408 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3409 if (response.payload != null) {
3410 s = IccUtils.bytesToHexString(response.payload) + s;
3411 }
3412 return s;
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003415 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003416 }
3417
3418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003419 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003420 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3422 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 if (DBG) {
3427 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3428 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3429 }
3430
3431 IccIoResult response =
3432 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3433 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3434 subId);
3435
3436 if (DBG) {
3437 log("Exchange SIM_IO [R]" + response);
3438 }
3439
3440 byte[] result = null;
3441 int length = 2;
3442 if (response.payload != null) {
3443 length = 2 + response.payload.length;
3444 result = new byte[length];
3445 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3446 } else {
3447 result = new byte[length];
3448 }
3449
3450 result[length - 1] = (byte) response.sw2;
3451 result[length - 2] = (byte) response.sw1;
3452 return result;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003455 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003456 }
3457
Nathan Haroldb3014052017-01-25 15:57:32 -08003458 /**
3459 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3460 * on a particular subscription
3461 */
sqianb6e41952018-03-12 14:54:01 -07003462 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3464 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3465 return null;
3466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467
3468 final long identity = Binder.clearCallingIdentity();
3469 try {
3470 if (appType != TelephonyManager.APPTYPE_USIM
3471 && appType != TelephonyManager.APPTYPE_SIM) {
3472 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3473 return null;
3474 }
3475 Object response = sendRequest(
3476 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3477 if (response instanceof String[]) {
3478 return (String[]) response;
3479 }
3480 // Response is an Exception of some kind,
3481 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003482 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483 } finally {
3484 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003485 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003486 }
3487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003488 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003489 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3491 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3496 if (response.payload == null) {
3497 return "";
3498 }
Evan Charltonc66da362014-05-16 14:06:40 -07003499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500 // Append the returned status code to the end of the response payload.
3501 String s = Integer.toHexString(
3502 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3503 s = IccUtils.bytesToHexString(response.payload) + s;
3504 return s;
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
3507 }
Evan Charltonc66da362014-05-16 14:06:40 -07003508 }
3509
Jake Hambye994d462014-02-03 13:10:13 -08003510 /**
3511 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3512 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3513 *
3514 * @param itemID the ID of the item to read
3515 * @return the NV item as a String, or null on error.
3516 */
3517 @Override
3518 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3521 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003526 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3528 return value;
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
Jake Hambye994d462014-02-03 13:10:13 -08003532 }
3533
3534 /**
3535 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3536 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3537 *
3538 * @param itemID the ID of the item to read
3539 * @param itemValue the value to write, as a String
3540 * @return true on success; false on any failure
3541 */
3542 @Override
3543 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3546 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3551 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003552 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003553 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3554 return success;
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
Jake Hambye994d462014-02-03 13:10:13 -08003558 }
3559
3560 /**
3561 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3562 * Used for device configuration by some CDMA operators.
3563 *
3564 * @param preferredRoamingList byte array containing the new PRL
3565 * @return true on success; false on any failure
3566 */
3567 @Override
3568 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3575 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3576 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3577 return success;
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
Jake Hambye994d462014-02-03 13:10:13 -08003581 }
3582
3583 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003584 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003585 * Used for device configuration by some CDMA operators.
3586 *
chen xu6dac5ab2018-10-26 17:39:23 -07003587 * @param slotIndex - device slot.
3588 *
Jake Hambye994d462014-02-03 13:10:13 -08003589 * @return true on success; false on any failure
3590 */
3591 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003592 public boolean resetModemConfig(int slotIndex) {
3593 Phone phone = PhoneFactory.getPhone(slotIndex);
3594 if (phone != null) {
3595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3596 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597
chen xu6dac5ab2018-10-26 17:39:23 -07003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3601 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3602 return success;
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606 }
chen xu6dac5ab2018-10-26 17:39:23 -07003607 return false;
3608 }
3609
3610 /**
3611 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3612 *
3613 * @param slotIndex - device slot.
3614 *
3615 * @return true on success; false on any failure
3616 */
3617 @Override
3618 public boolean rebootModem(int slotIndex) {
3619 Phone phone = PhoneFactory.getPhone(slotIndex);
3620 if (phone != null) {
3621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3622 mApp, phone.getSubId(), "rebootModem");
3623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3627 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3628 return success;
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003634 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003635
Svet Ganovb320e182015-04-16 12:30:10 -07003636 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003640 return new String[0];
3641 }
3642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 final long identity = Binder.clearCallingIdentity();
3644 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003645 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
Wink Saville36469e72014-06-11 15:17:00 -07003649 }
3650
Brad Ebinger51f743a2017-01-23 13:50:20 -08003651 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003652 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3653 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003654 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003655 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003656 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 PhoneFactory.getImsResolver().enableIms(slotId);
3661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003664 }
3665
3666 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003667 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3668 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003669 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003670 public void disableIms(int slotId) {
3671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 PhoneFactory.getImsResolver().disableIms(slotId);
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003679 }
3680
3681 /**
3682 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3683 * feature or {@link null} if the service is not available. If the feature is available, the
3684 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3685 */
3686 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003687 IImsServiceFeatureCallback callback) {
3688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689
3690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003696 }
3697
3698 /**
3699 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3700 * feature during emergency calling or {@link null} if the service is not available. If the
3701 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3702 * listener for feature updates.
3703 */
3704 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706
3707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003713 }
3714
Brad Ebinger5f64b052017-12-14 14:26:15 -08003715 /**
3716 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3717 * specified.
3718 */
3719 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3720 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003728 }
3729
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003730 /**
3731 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3732 * specified.
3733 */
3734 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3735 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736
3737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003743 }
3744
Brad Ebinger884c07b2018-02-15 16:17:40 -08003745 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003746 * Sets the ImsService Package Name that Telephony will bind to.
3747 *
3748 * @param slotId the slot ID that the ImsService should bind for.
3749 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3750 * ImsService is the device default ImsService.
3751 * @param packageName The package name of the application that contains the ImsService to bind
3752 * to.
3753 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3754 * @hide
3755 */
3756 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003757 int[] subIds = SubscriptionManager.getSubId(slotId);
3758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3759 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3760 "setImsService");
3761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3765 isCarrierImsService, packageName);
3766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003769 }
3770
3771 /**
3772 * Return the ImsService configuration.
3773 *
3774 * @param slotId The slot that the ImsService is associated with.
3775 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3776 * the device default.
3777 * @return the package name of the ImsService configuration.
3778 */
3779 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003780 int[] subIds = SubscriptionManager.getSubId(slotId);
3781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3782 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3783 "getImsService");
3784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3788 isCarrierImsService);
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003792 }
3793
Wink Saville36469e72014-06-11 15:17:00 -07003794 public void setImsRegistrationState(boolean registered) {
3795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Wink Saville36469e72014-06-11 15:17:00 -07003803 }
3804
3805 /**
Stuart Scott54788802015-03-30 13:18:01 -07003806 * Set the network selection mode to automatic.
3807 *
3808 */
3809 @Override
3810 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813
Pengquan Menge92a50d2018-09-21 15:54:48 -07003814 if (!isActiveSubscription(subId)) {
3815 return;
3816 }
3817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3821 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
Stuart Scott54788802015-03-30 13:18:01 -07003825 }
3826
Pengquan Mengea84e042018-09-20 14:57:26 -07003827 /**
3828 * Ask the radio to connect to the input network and change selection mode to manual.
3829 *
3830 * @param subId the id of the subscription.
3831 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3832 * the operator to attach to.
3833 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3834 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3835 * normal network selection next time.
3836 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003837 */
3838 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003839 public boolean setNetworkSelectionModeManual(
3840 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3842 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003843
3844 if (!isActiveSubscription(subId)) {
3845 return false;
3846 }
3847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003850 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003852 if (DBG) {
3853 log("setNetworkSelectionModeManual: subId: " + subId
3854 + " operator: " + operatorInfo);
3855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003860 }
3861
3862 /**
3863 * Scans for available networks.
3864 */
3865 @Override
3866 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3868 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869
Pengquan Menga1bb6272018-09-06 09:59:22 -07003870 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 try {
3872 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003873 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003878 }
3879
3880 /**
yinxub1bed742017-04-17 11:45:04 -07003881 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003882 *
yinxub1bed742017-04-17 11:45:04 -07003883 * @param subId id of the subscription
3884 * @param request contains the radio access networks with bands/channels to scan
3885 * @param messenger callback messenger for scan results or errors
3886 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003887 * @return the id of the requested scan which can be used to stop the scan.
3888 */
3889 @Override
3890 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3891 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3893 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894
3895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 return mNetworkScanRequestTracker.startNetworkScan(
3898 request, messenger, binder, getPhone(subId));
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
yinxu504e1392017-04-12 16:03:22 -07003902 }
3903
3904 /**
3905 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003906 *
3907 * @param subId id of the subscription
3908 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003909 */
3910 @Override
3911 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3913 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914
3915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
yinxu504e1392017-04-12 16:03:22 -07003921 }
3922
3923 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003924 * Get the calculated preferred network type.
3925 * Used for debugging incorrect network type.
3926 *
3927 * @return the preferred network type, defined in RILConstants.java.
3928 */
3929 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003930 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003931 final Phone defaultPhone = getDefaultPhone();
3932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3933 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003934 return RILConstants.PREFERRED_NETWORK_MODE;
3935 }
3936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003940 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
Junda Liu84d15a22014-07-02 11:21:04 -07003944 }
3945
3946 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003947 * Get the preferred network type.
3948 * Used for device configuration by some CDMA operators.
3949 *
3950 * @return the preferred network type, defined in RILConstants.java.
3951 */
3952 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003953 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08003954 TelephonyPermissions
3955 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
3956 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 if (DBG) log("getPreferredNetworkType");
3961 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3962 int networkType = (result != null ? result[0] : -1);
3963 if (DBG) log("getPreferredNetworkType: " + networkType);
3964 return networkType;
3965 } finally {
3966 Binder.restoreCallingIdentity(identity);
3967 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003968 }
3969
3970 /**
3971 * Set the preferred network type.
3972 * Used for device configuration by some CDMA operators.
3973 *
3974 * @param networkType the preferred network type, defined in RILConstants.java.
3975 * @return true on success; false on any failure.
3976 */
3977 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003978 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3980 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3985 Boolean success = (Boolean) sendRequest(
3986 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3987 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3988 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003989 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3991 }
3992 return success;
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003995 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003996 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003997
3998 /**
Junda Liu475951f2014-11-07 16:45:03 -08003999 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07004000 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004001 * tethering.
4002 *
4003 * @return 0: Not required. 1: required. 2: Not set.
4004 * @hide
4005 */
4006 @Override
4007 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004008 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009
4010 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004011 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004012 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004013 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004015 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004016 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 dunRequired = 1;
4018 }
4019 return dunRequired;
4020 } finally {
4021 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004022 }
Junda Liu475951f2014-11-07 16:45:03 -08004023 }
4024
4025 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004026 * Set mobile data enabled
4027 * Used by the user through settings etc to turn on/off mobile data
4028 *
4029 * @param enable {@code true} turn turn data on, else {@code false}
4030 */
4031 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004032 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4034 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035
4036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 int phoneId = mSubscriptionController.getPhoneId(subId);
4039 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4040 Phone phone = PhoneFactory.getPhone(phoneId);
4041 if (phone != null) {
4042 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004043 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004045 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 }
4047 } finally {
4048 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004049 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004050 }
4051
4052 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004053 * Get the user enabled state of Mobile Data.
4054 *
4055 * TODO: remove and use isUserDataEnabled.
4056 * This can't be removed now because some vendor codes
4057 * calls through ITelephony directly while they should
4058 * use TelephonyManager.
4059 *
4060 * @return true on enabled
4061 */
4062 @Override
4063 public boolean getDataEnabled(int subId) {
4064 return isUserDataEnabled(subId);
4065 }
4066
4067 /**
4068 * Get whether mobile data is enabled per user setting.
4069 *
4070 * There are other factors deciding whether mobile data is actually enabled, but they are
4071 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004072 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004073 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004074 *
4075 * @return {@code true} if data is enabled else {@code false}
4076 */
4077 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004078 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004079 try {
4080 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4081 null);
4082 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4084 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 int phoneId = mSubscriptionController.getPhoneId(subId);
4090 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4091 Phone phone = PhoneFactory.getPhone(phoneId);
4092 if (phone != null) {
4093 boolean retVal = phone.isUserDataEnabled();
4094 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4095 return retVal;
4096 } else {
4097 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4098 return false;
4099 }
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004102 }
4103 }
4104
4105 /**
4106 * Get whether mobile data is enabled.
4107 *
4108 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4109 * whether mobile data is actually enabled.
4110 *
4111 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4112 *
4113 * @return {@code true} if data is enabled else {@code false}
4114 */
4115 @Override
4116 public boolean isDataEnabled(int subId) {
4117 try {
4118 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4119 null);
4120 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4122 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 int phoneId = mSubscriptionController.getPhoneId(subId);
4128 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4129 Phone phone = PhoneFactory.getPhone(phoneId);
4130 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004131 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4133 return retVal;
4134 } else {
4135 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4136 return false;
4137 }
4138 } finally {
4139 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004140 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004141 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004142
4143 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004144 public int getCarrierPrivilegeStatus(int subId) {
4145 final Phone phone = getPhone(subId);
4146 if (phone == null) {
4147 loge("getCarrierPrivilegeStatus: Invalid subId");
4148 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4149 }
4150 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004151 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004152 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004153 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4154 }
4155 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004156 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004157 }
Junda Liu29340342014-07-10 15:23:27 -07004158
4159 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004160 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4161 final Phone phone = getPhone(subId);
4162 if (phone == null) {
4163 loge("getCarrierPrivilegeStatus: Invalid subId");
4164 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4165 }
4166 UiccProfile profile =
4167 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4168 if (profile == null) {
4169 loge("getCarrierPrivilegeStatus: No UICC");
4170 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4171 }
4172 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4173 }
4174
4175 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004176 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004177 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004178 if (TextUtils.isEmpty(pkgName))
4179 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004180 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004181 if (card == null) {
4182 loge("checkCarrierPrivilegesForPackage: No UICC");
4183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4184 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004185 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4186 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004187 }
4188
4189 @Override
4190 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004191 if (TextUtils.isEmpty(pkgName))
4192 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004193 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4194 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4195 UiccCard card = UiccController.getInstance().getUiccCard(i);
4196 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004197 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004198 continue;
4199 }
4200
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004201 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004202 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4203 break;
4204 }
4205 }
4206
4207 return result;
Junda Liu29340342014-07-10 15:23:27 -07004208 }
Derek Tan89e89d42014-07-08 17:00:10 -07004209
4210 @Override
Junda Liue64de782015-04-16 17:19:16 -07004211 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4212 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4213 loge("phoneId " + phoneId + " is not valid.");
4214 return null;
4215 }
4216 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004217 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004218 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004219 return null ;
4220 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004221 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004222 }
4223
Amith Yamasani6e118872016-02-19 12:53:51 -08004224 @Override
4225 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004226 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004227 List<String> privilegedPackages = new ArrayList<>();
4228 List<PackageInfo> packages = null;
4229 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4230 UiccCard card = UiccController.getInstance().getUiccCard(i);
4231 if (card == null) {
4232 // No UICC in that slot.
4233 continue;
4234 }
4235 if (card.hasCarrierPrivilegeRules()) {
4236 if (packages == null) {
4237 // Only check packages in user 0 for now
4238 packages = pm.getInstalledPackagesAsUser(
4239 PackageManager.MATCH_DISABLED_COMPONENTS
4240 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4241 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4242 }
4243 for (int p = packages.size() - 1; p >= 0; p--) {
4244 PackageInfo pkgInfo = packages.get(p);
4245 if (pkgInfo != null && pkgInfo.packageName != null
4246 && card.getCarrierPrivilegeStatus(pkgInfo)
4247 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4248 privilegedPackages.add(pkgInfo.packageName);
4249 }
4250 }
4251 }
4252 }
4253 return privilegedPackages;
4254 }
4255
Wink Savilleb564aae2014-10-23 10:18:09 -07004256 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004257 final Phone phone = getPhone(subId);
4258 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004259 if (card == null) {
4260 loge("getIccId: No UICC");
4261 return null;
4262 }
4263 String iccId = card.getIccId();
4264 if (TextUtils.isEmpty(iccId)) {
4265 loge("getIccId: ICC ID is null or empty.");
4266 return null;
4267 }
4268 return iccId;
4269 }
4270
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004271 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004272 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4273 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4275 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 final String iccId = getIccId(subId);
4280 final Phone phone = getPhone(subId);
4281 if (phone == null) {
4282 return false;
4283 }
4284 final String subscriberId = phone.getSubscriberId();
4285
4286 if (DBG_MERGE) {
4287 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4288 + subscriberId + " to " + number);
4289 }
4290
4291 if (TextUtils.isEmpty(iccId)) {
4292 return false;
4293 }
4294
4295 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4296
4297 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4298 if (alphaTag == null) {
4299 editor.remove(alphaTagPrefKey);
4300 } else {
4301 editor.putString(alphaTagPrefKey, alphaTag);
4302 }
4303
4304 // Record both the line number and IMSI for this ICCID, since we need to
4305 // track all merged IMSIs based on line number
4306 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4307 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4308 if (number == null) {
4309 editor.remove(numberPrefKey);
4310 editor.remove(subscriberPrefKey);
4311 } else {
4312 editor.putString(numberPrefKey, number);
4313 editor.putString(subscriberPrefKey, subscriberId);
4314 }
4315
4316 editor.commit();
4317 return true;
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004320 }
Derek Tan7226c842014-07-02 17:42:23 -07004321 }
4322
4323 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004324 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004325 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004327 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004328 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004329 return null;
4330 }
Derek Tan97ebb422014-09-05 16:55:38 -07004331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 String iccId = getIccId(subId);
4335 if (iccId != null) {
4336 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4337 if (DBG_MERGE) {
4338 log("getLine1NumberForDisplay returning "
4339 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4340 }
4341 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4344 return null;
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004347 }
Derek Tan7226c842014-07-02 17:42:23 -07004348 }
4349
4350 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004351 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004353 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004354 return null;
4355 }
Derek Tan97ebb422014-09-05 16:55:38 -07004356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 String iccId = getIccId(subId);
4360 if (iccId != null) {
4361 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4362 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4363 }
4364 return null;
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004367 }
Derek Tan7226c842014-07-02 17:42:23 -07004368 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004369
4370 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004371 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004372 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4373 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004375 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4376 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004377 return null;
4378 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004379
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004380 final long identity = Binder.clearCallingIdentity();
4381 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004382 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 final TelephonyManager tele = TelephonyManager.from(context);
4384 final SubscriptionManager sub = SubscriptionManager.from(context);
4385
4386 // Figure out what subscribers are currently active
4387 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4388 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4389 // the process, where TelephonyManager was instantiated.
4390 // Otherwise AppOps check will fail.
4391
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004392 final int[] subIds = sub.getActiveSubscriptionIdList();
4393 for (int subId : subIds) {
4394 activeSubscriberIds.add(tele.getSubscriberId(subId));
4395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396
4397 // First pass, find a number override for an active subscriber
4398 String mergeNumber = null;
4399 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4400 for (String key : prefs.keySet()) {
4401 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4402 final String subscriberId = (String) prefs.get(key);
4403 if (activeSubscriberIds.contains(subscriberId)) {
4404 final String iccId = key.substring(
4405 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4406 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4407 mergeNumber = (String) prefs.get(numberKey);
4408 if (DBG_MERGE) {
4409 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4410 + " for active subscriber " + subscriberId);
4411 }
4412 if (!TextUtils.isEmpty(mergeNumber)) {
4413 break;
4414 }
4415 }
4416 }
4417 }
4418
4419 // Shortcut when no active merged subscribers
4420 if (TextUtils.isEmpty(mergeNumber)) {
4421 return null;
4422 }
4423
4424 // Second pass, find all subscribers under that line override
4425 final ArraySet<String> result = new ArraySet<>();
4426 for (String key : prefs.keySet()) {
4427 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4428 final String number = (String) prefs.get(key);
4429 if (mergeNumber.equals(number)) {
4430 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4431 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4432 final String subscriberId = (String) prefs.get(subscriberKey);
4433 if (!TextUtils.isEmpty(subscriberId)) {
4434 result.add(subscriberId);
4435 }
4436 }
4437 }
4438 }
4439
4440 final String[] resultArray = result.toArray(new String[result.size()]);
4441 Arrays.sort(resultArray);
4442 if (DBG_MERGE) {
4443 Slog.d(LOG_TAG,
4444 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4445 }
4446 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004449 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004450 }
4451
4452 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004453 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004454 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4455 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456
4457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 final Phone phone = getPhone(subId);
4460 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004464 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004465
4466 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004467 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004468 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4469 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004470 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471
4472 final long identity = Binder.clearCallingIdentity();
4473 try {
4474 final Phone phone = getPhone(subId);
4475 if (phone == null) {
4476 return false;
4477 }
4478 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4479 cdmaNonRoamingList);
4480 } finally {
4481 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004482 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004483 }
4484
4485 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004486 @Deprecated
4487 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4488 enforceModifyPermission();
4489
4490 int returnValue = 0;
4491 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004492 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004493 if(result.exception == null) {
4494 if (result.result != null) {
4495 byte[] responseData = (byte[])(result.result);
4496 if(responseData.length > oemResp.length) {
4497 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4498 responseData.length + "bytes. Buffer Size is " +
4499 oemResp.length + "bytes.");
4500 }
4501 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4502 returnValue = responseData.length;
4503 }
4504 } else {
4505 CommandException ex = (CommandException) result.exception;
4506 returnValue = ex.getCommandError().ordinal();
4507 if(returnValue > 0) returnValue *= -1;
4508 }
4509 } catch (RuntimeException e) {
4510 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4511 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4512 if(returnValue > 0) returnValue *= -1;
4513 }
4514
4515 return returnValue;
4516 }
4517
4518 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004519 public void setRadioCapability(RadioAccessFamily[] rafs) {
4520 try {
4521 ProxyController.getInstance().setRadioCapability(rafs);
4522 } catch (RuntimeException e) {
4523 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4524 }
4525 }
4526
4527 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004528 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004529 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004530 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004531 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004532 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 final long identity = Binder.clearCallingIdentity();
4535 try {
chen xub97461a2018-10-26 14:17:57 -07004536 TelephonyPermissions
4537 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4538 mApp, phone.getSubId(), "getRadioAccessFamily");
4539 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
chen xub97461a2018-10-26 14:17:57 -07004543 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004544 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004545
4546 @Override
4547 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004548 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004553 ImsManager.getInstance(defaultPhone.getContext(),
4554 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
4557 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004558 }
4559
4560 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004561 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004562 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004564 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004565 return false;
4566 }
Svet Ganovb320e182015-04-16 12:30:10 -07004567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 // Check the user preference and the system-level IMS setting. Even if the user has
4571 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4572 // In the long run, we may instead need to check if there exists a connection service
4573 // which can support video calling.
4574 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004575 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 return imsManager.isVtEnabledByPlatform()
4577 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4578 && imsManager.isVtEnabledByUser();
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004582 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004583
Andrew Leea1239f22015-03-02 17:44:07 -08004584 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4587 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4588 return false;
4589 }
4590
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 CarrierConfigManager configManager =
4594 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004595 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Andrew Leea1239f22015-03-02 17:44:07 -08004600 }
4601
4602 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603 public boolean isWorldPhone(int subId, String callingPackage) {
4604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4605 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4606 return false;
4607 }
4608
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 CarrierConfigManager configManager =
4612 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004613 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
Andrew Leea1239f22015-03-02 17:44:07 -08004618 }
4619
Andrew Lee9431b832015-03-09 18:46:45 -07004620 @Override
4621 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004622 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004623 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004624 }
4625
4626 @Override
4627 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 final long identity = Binder.clearCallingIdentity();
4629 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004630 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
Andrew Lee9431b832015-03-09 18:46:45 -07004634 }
4635
Hall Liuf6668912018-10-31 17:05:23 -07004636 /**
4637 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4638 * support for the feature and device firmware support.
4639 *
4640 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4641 */
4642 @Override
4643 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004645 final Phone phone = getPhone(subscriptionId);
4646 if (phone == null) {
4647 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4648 return false;
4649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004651 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4653 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004654 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 return isCarrierSupported && isDeviceSupported;
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
Hall Liu98187582018-01-22 19:15:32 -08004659 }
4660
Hall Liuf6668912018-10-31 17:05:23 -07004661 /**
4662 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4663 * both also support RTT.
4664 */
4665 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 final long identity = Binder.clearCallingIdentity();
4667 try {
Hall Liuf6668912018-10-31 17:05:23 -07004668 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004669 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004673 }
4674
Sanket Padawe7310cc72015-01-14 09:53:20 -08004675 /**
4676 * Returns the unique device ID of phone, for example, the IMEI for
4677 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4678 *
4679 * <p>Requires Permission:
4680 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4681 */
4682 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004683 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004684 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004685 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004686 return null;
4687 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004688 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004689 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4690 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004691 return null;
4692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693
4694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 return phone.getDeviceId();
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004700 }
4701
Ping Sunc67b7c22016-03-02 19:16:45 +08004702 /**
4703 * {@hide}
4704 * Returns the IMS Registration Status on a particular subid
4705 *
4706 * @param subId
4707 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004708 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004709 Phone phone = getPhone(subId);
4710 if (phone != null) {
4711 return phone.isImsRegistered();
4712 } else {
4713 return false;
4714 }
4715 }
4716
Santos Cordon7a1885b2015-02-03 11:15:19 -08004717 @Override
4718 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004725 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004726
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004727 /**
4728 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004729 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004730 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 Phone phone = getPhone(subId);
4734 if (phone != null) {
4735 return phone.isWifiCallingEnabled();
4736 } else {
4737 return false;
4738 }
4739 } finally {
4740 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004741 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004742 }
4743
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004744 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004745 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004746 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004747 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748 final long identity = Binder.clearCallingIdentity();
4749 try {
4750 Phone phone = getPhone(subId);
4751 if (phone != null) {
4752 return phone.isVideoEnabled();
4753 } else {
4754 return false;
4755 }
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004758 }
4759 }
4760
4761 /**
4762 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4763 * defined in {@link ImsRegistrationImplBase}.
4764 */
4765 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 final long identity = Binder.clearCallingIdentity();
4767 try {
4768 Phone phone = getPhone(subId);
4769 if (phone != null) {
4770 return phone.getImsRegistrationTech();
4771 } else {
4772 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4773 }
4774 } finally {
4775 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004776 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004777 }
4778
Stuart Scott8eef64f2015-04-08 15:13:54 -07004779 @Override
4780 public void factoryReset(int subId) {
4781 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004782 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4783 return;
4784 }
4785
Svet Ganovcc087f82015-05-12 20:35:54 -07004786 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004787
Svet Ganovcc087f82015-05-12 20:35:54 -07004788 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004789 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4790 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004791 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004792 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004793 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004794 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4795 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004796 }
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004799 }
4800 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004801
4802 @Override
4803 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 final long identity = Binder.clearCallingIdentity();
4805 try {
4806 // We query all subscriptions instead of just the active ones, because
4807 // this might be called early on in the provisioning flow when the
4808 // subscriptions potentially aren't active yet.
4809 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4810 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004811 return null;
4812 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 // This function may be called very early, say, from the setup wizard, at
4815 // which point we won't have a default subscription set. If that's the case
4816 // we just choose the first, which will be valid in "most cases".
4817 final int defaultSubId = getDefaultSubscription();
4818 SubscriptionInfo info = null;
4819 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4820 info = slist.get(0);
4821 } else {
4822 for (SubscriptionInfo item : slist) {
4823 if (item.getSubscriptionId() == defaultSubId) {
4824 info = item;
4825 break;
4826 }
4827 }
4828
4829 if (info == null) {
4830 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004831 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004832 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 // Try and fetch the locale from the carrier properties or from the SIM language
4835 // preferences (EF-PL and EF-LI)...
4836 final int mcc = info.getMcc();
4837 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4838 String simLanguage = null;
4839 if (defaultPhone != null) {
4840 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4841 if (localeFromDefaultSim != null) {
4842 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4843 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4844 return localeFromDefaultSim.toLanguageTag();
4845 } else {
4846 simLanguage = localeFromDefaultSim.getLanguage();
4847 }
4848 }
4849 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 // The SIM language preferences only store a language (e.g. fr = French), not an
4852 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4853 // the SIM and carrier preferences does not include a country we add the country
4854 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004855 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 if (mccLocale != null) {
4857 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4858 return mccLocale.toLanguageTag();
4859 }
4860
4861 if (DBG) log("No locale found - returning null");
4862 return null;
4863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004866 }
4867
4868 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004869 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004870 }
4871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 /**
4873 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4874 */
4875 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004876 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004877 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004878
Chenjie Yu1ba97252018-01-11 18:16:20 -08004879 private final ModemActivityInfo mLastModemActivityInfo =
4880 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4881
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004882 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004883 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4884 * representing the state of the modem.
4885 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004886 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4887 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004888 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004889 */
4890 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004891 public void requestModemActivityInfo(ResultReceiver result) {
4892 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004893 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894
4895 final long identity = Binder.clearCallingIdentity();
4896 try {
4897 ModemActivityInfo ret = null;
4898 synchronized (mLastModemActivityInfo) {
4899 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4900 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004901 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004902 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4904 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004905 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
4906 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 }
4908 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004909 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
4910 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 mLastModemActivityInfo.setIdleTimeMillis(
4912 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4913 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4914 mLastModemActivityInfo.setRxTimeMillis(
4915 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4916 mLastModemActivityInfo.setEnergyUsed(
4917 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004919 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4920 mLastModemActivityInfo.getSleepTimeMillis(),
4921 mLastModemActivityInfo.getIdleTimeMillis(),
4922 mLastModemActivityInfo.getTxTimeMillis(),
4923 mLastModemActivityInfo.getRxTimeMillis(),
4924 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 Bundle bundle = new Bundle();
4927 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4928 result.send(0, bundle);
4929 } finally {
4930 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004931 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004932 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004933
Siddharth Rayb8114062018-06-17 15:02:38 -07004934 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4935 // less than total activity duration.
4936 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4937 if (info == null) {
4938 return false;
4939 }
4940 int activityDurationMs =
4941 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4942 int totalTxTimeMs = 0;
4943 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4944 totalTxTimeMs += info.getTxTimeMillis()[i];
4945 }
4946 return (info.isValid()
4947 && (info.getSleepTimeMillis() <= activityDurationMs)
4948 && (info.getIdleTimeMillis() <= activityDurationMs)
4949 && (info.getRxTimeMillis() <= activityDurationMs)
4950 && (totalTxTimeMs <= activityDurationMs));
4951 }
4952
Jack Yu85bd38a2015-11-09 11:34:32 -08004953 /**
4954 * {@hide}
4955 * Returns the service state information on specified subscription.
4956 */
4957 @Override
4958 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004960 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004961 return null;
4962 }
4963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 final Phone phone = getPhone(subId);
4967 if (phone == null) {
4968 return null;
4969 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 return phone.getServiceState();
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004975 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004976
4977 /**
4978 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4979 *
4980 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4981 * voicemail ringtone.
4982 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4983 * PhoneAccount.
4984 */
4985 @Override
4986 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 final long identity = Binder.clearCallingIdentity();
4988 try {
4989 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4990 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004991 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004998 }
4999
5000 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005001 * Sets the per-account voicemail ringtone.
5002 *
5003 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5004 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5005 *
5006 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5007 * voicemail ringtone.
5008 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5009 * PhoneAccount.
5010 */
5011 @Override
5012 public void setVoicemailRingtoneUri(String callingPackage,
5013 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005014 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5016 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005017 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5019 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5020 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022
5023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5026 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005027 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 }
5029 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005032 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005033 }
5034
5035 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005036 * Returns whether vibration is set for voicemail notification in Phone settings.
5037 *
5038 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5039 * voicemail vibration setting.
5040 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5041 */
5042 @Override
5043 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5047 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005048 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005055 }
5056
Youhan Wange64578a2016-05-02 15:32:42 -07005057 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005058 * Sets the per-account voicemail vibration.
5059 *
5060 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5061 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5062 *
5063 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5064 * voicemail vibration setting.
5065 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5066 * specific PhoneAccount.
5067 */
5068 @Override
5069 public void setVoicemailVibrationEnabled(String callingPackage,
5070 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005071 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5073 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005074 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5076 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5077 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005078 }
5079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5083 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005084 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 }
5086 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005089 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005090 }
5091
5092 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005093 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5094 *
5095 * @throws SecurityException if the caller does not have the required permission
5096 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005097 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005099 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005100 }
5101
5102 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005103 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5104 * permission.
5105 *
5106 * @throws SecurityException if the caller does not have the required permission
5107 */
5108 private void enforceSendSmsPermission() {
5109 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5110 }
5111
5112 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005113 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005114 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005115 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005116 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005117 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005121 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 if (componentName == null) {
5123 throw new SecurityException(
5124 "Caller not current active visual voicemail package[null]");
5125 }
5126 String vvmPackage = componentName.getPackageName();
5127 if (!callingPackage.equals(vvmPackage)) {
5128 throw new SecurityException("Caller not current active visual voicemail package["
5129 + vvmPackage + "]");
5130 }
5131 } finally {
5132 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005133 }
5134 }
5135
5136 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005137 * Return the application ID for the app type.
5138 *
5139 * @param subId the subscription ID that this request applies to.
5140 * @param appType the uicc app type.
5141 * @return Application ID for specificied app type, or null if no uicc.
5142 */
5143 @Override
5144 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005145 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005146 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147
5148 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005149 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 if (phone == null) {
5151 return null;
5152 }
5153 String aid = null;
5154 try {
5155 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5156 .getApplicationByType(appType).getAid();
5157 } catch (Exception e) {
5158 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5159 }
5160 return aid;
5161 } finally {
5162 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005163 }
Youhan Wange64578a2016-05-02 15:32:42 -07005164 }
5165
Youhan Wang4001d252016-05-11 10:29:41 -07005166 /**
5167 * Return the Electronic Serial Number.
5168 *
5169 * @param subId the subscription ID that this request applies to.
5170 * @return ESN or null if error.
5171 */
5172 @Override
5173 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005174 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005175 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176
5177 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005178 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 if (phone == null) {
5180 return null;
5181 }
5182 String esn = null;
5183 try {
5184 esn = phone.getEsn();
5185 } catch (Exception e) {
5186 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5187 }
5188 return esn;
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005191 }
Youhan Wang4001d252016-05-11 10:29:41 -07005192 }
5193
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005194 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005195 * Return the Preferred Roaming List Version.
5196 *
5197 * @param subId the subscription ID that this request applies to.
5198 * @return PRLVersion or null if error.
5199 */
5200 @Override
5201 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005202 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005203 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204
5205 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005206 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 if (phone == null) {
5208 return null;
5209 }
5210 String cdmaPrlVersion = null;
5211 try {
5212 cdmaPrlVersion = phone.getCdmaPrlVersion();
5213 } catch (Exception e) {
5214 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5215 }
5216 return cdmaPrlVersion;
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005219 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005220 }
5221
5222 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005223 * Get snapshot of Telephony histograms
5224 * @return List of Telephony histograms
5225 * @hide
5226 */
5227 @Override
5228 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5230 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231
5232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 return RIL.getTelephonyRILTimingHistograms();
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005238 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005239
5240 /**
5241 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005242 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005243 * Require system privileges. In the future we may add this to carrier APIs.
5244 *
5245 * @return The number of carriers set successfully, should match length of carriers
5246 */
5247 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005248 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005249 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005250 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005251
Meng Wang9b7c4e92017-02-17 11:41:27 -08005252 if (carriers == null) {
5253 throw new NullPointerException("carriers cannot be null");
5254 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 final long identity = Binder.clearCallingIdentity();
5257 try {
Michele85121de2018-12-19 15:25:20 -08005258 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5259 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005260 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5261 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 return retVal[0];
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005266 }
5267
5268 /**
5269 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005270 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005271 * Require system privileges. In the future we may add this to carrier APIs.
5272 *
5273 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5274 * means all carriers are allowed.
5275 */
5276 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005277 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005278 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005279 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280
5281 final long identity = Binder.clearCallingIdentity();
5282 try {
Michele85121de2018-12-19 15:25:20 -08005283 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5284 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005285 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5286 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005290 }
5291
fionaxu59545b42016-05-25 15:53:37 -07005292 /**
5293 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5294 * @param subId the subscription ID that this action applies to.
5295 * @param enabled control enable or disable metered apns.
5296 * {@hide}
5297 */
5298 @Override
5299 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5300 enforceModifyPermission();
5301 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302
5303 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005304 if (phone == null) {
5305 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5306 return;
5307 }
5308 try {
5309 phone.carrierActionSetMeteredApnsEnabled(enabled);
5310 } catch (Exception e) {
5311 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 } finally {
5313 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005314 }
5315 }
5316
5317 /**
5318 * Action set from carrier signalling broadcast receivers to enable/disable radio
5319 * @param subId the subscription ID that this action applies to.
5320 * @param enabled control enable or disable radio.
5321 * {@hide}
5322 */
5323 @Override
5324 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5325 enforceModifyPermission();
5326 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327
5328 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005329 if (phone == null) {
5330 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5331 return;
5332 }
5333 try {
5334 phone.carrierActionSetRadioEnabled(enabled);
5335 } catch (Exception e) {
5336 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 } finally {
5338 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005339 }
5340 }
5341
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005342 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005343 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5344 * network status based on which carrier apps could apply actions accordingly,
5345 * enable/disable default url handler for example.
5346 *
5347 * @param subId the subscription ID that this action applies to.
5348 * @param report control start/stop reporting the default network status.
5349 * {@hide}
5350 */
5351 @Override
5352 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5353 enforceModifyPermission();
5354 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355
5356 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005357 if (phone == null) {
5358 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5359 return;
5360 }
5361 try {
5362 phone.carrierActionReportDefaultNetworkStatus(report);
5363 } catch (Exception e) {
5364 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 } finally {
5366 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005367 }
5368 }
5369
5370 /**
fionaxud9622282017-07-17 17:51:30 -07005371 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5372 * @param subId the subscription ID that this action applies to.
5373 * {@hide}
5374 */
5375 @Override
5376 public void carrierActionResetAll(int subId) {
5377 enforceModifyPermission();
5378 final Phone phone = getPhone(subId);
5379 if (phone == null) {
5380 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5381 return;
5382 }
5383 try {
5384 phone.carrierActionResetAll();
5385 } catch (Exception e) {
5386 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5387 }
5388 }
5389
5390 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005391 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5392 * bug report is being generated.
5393 */
5394 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005395 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005396 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5397 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005398 writer.println("Permission Denial: can't dump Phone from pid="
5399 + Binder.getCallingPid()
5400 + ", uid=" + Binder.getCallingUid()
5401 + "without permission "
5402 + android.Manifest.permission.DUMP);
5403 return;
5404 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005405 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005406 }
Jack Yueb89b242016-06-22 13:27:47 -07005407
Brad Ebingerdac2f002018-04-03 15:17:52 -07005408 @Override
5409 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5410 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5411 throws RemoteException {
5412 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5413 }
5414
Jack Yueb89b242016-06-22 13:27:47 -07005415 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005416 * Get aggregated video call data usage since boot.
5417 *
5418 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5419 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005420 * {@hide}
5421 */
5422 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005423 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005424 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5425 null);
5426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 final long identity = Binder.clearCallingIdentity();
5428 try {
5429 // NetworkStatsService keeps tracking the active network interface and identity. It
5430 // records the delta with the corresponding network identity.
5431 // We just return the total video call data usage snapshot since boot.
5432 Phone phone = getPhone(subId);
5433 if (phone != null) {
5434 return phone.getVtDataUsage(perUidStats);
5435 }
5436 return null;
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005439 }
Jack Yueb89b242016-06-22 13:27:47 -07005440 }
Jack Yu75ab2952016-07-08 14:29:33 -07005441
5442 /**
5443 * Policy control of data connection. Usually used when data limit is passed.
5444 * @param enabled True if enabling the data, otherwise disabling.
5445 * @param subId Subscription index
5446 * {@hide}
5447 */
5448 @Override
5449 public void setPolicyDataEnabled(boolean enabled, int subId) {
5450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451
5452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 Phone phone = getPhone(subId);
5455 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005456 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 }
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005460 }
5461 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005462
5463 /**
5464 * Get Client request stats
5465 * @return List of Client Request Stats
5466 * @hide
5467 */
5468 @Override
5469 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005471 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005472 return null;
5473 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005474 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 final long identity = Binder.clearCallingIdentity();
5477 try {
5478 if (phone != null) {
5479 return phone.getClientRequestStats();
5480 }
5481
5482 return null;
5483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005486 }
5487
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005488 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005489 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005490 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005491 }
Jack Yueb4124c2017-02-16 15:32:43 -08005492
5493 /**
Grace Chen70990072017-03-24 17:21:30 -07005494 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005495 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005496 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005497 * @param state State of SIM (power down, power up, pass through)
5498 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5499 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5500 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005501 *
5502 **/
5503 @Override
Grace Chen70990072017-03-24 17:21:30 -07005504 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005505 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005506 Phone phone = PhoneFactory.getPhone(slotIndex);
5507
vagdeviaf9a5b92018-08-15 16:01:53 -07005508 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005513 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 }
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005517 }
5518 }
Shuo Qiandd210312017-04-12 22:11:33 +00005519
Tyler Gunn65d45c22017-06-05 11:22:26 -07005520 private boolean isUssdApiAllowed(int subId) {
5521 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005522 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005523 if (configManager == null) {
5524 return false;
5525 }
5526 PersistableBundle pb = configManager.getConfigForSubId(subId);
5527 if (pb == null) {
5528 return false;
5529 }
5530 return pb.getBoolean(
5531 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5532 }
5533
Shuo Qiandd210312017-04-12 22:11:33 +00005534 /**
5535 * Check if phone is in emergency callback mode
5536 * @return true if phone is in emergency callback mode
5537 * @param subId sub id
5538 */
goneil9c5f4872017-12-05 14:07:56 -08005539 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005540 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005541 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005542 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543
5544 final long identity = Binder.clearCallingIdentity();
5545 try {
5546 if (phone != null) {
5547 return phone.isInEcm();
5548 } else {
5549 return false;
5550 }
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005553 }
5554 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005555
5556 /**
5557 * Get the current signal strength information for the given subscription.
5558 * Because this information is not updated when the device is in a low power state
5559 * it should not be relied-upon to be current.
5560 * @param subId Subscription index
5561 * @return the most recent cached signal strength info from the modem
5562 */
5563 @Override
5564 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 Phone p = getPhone(subId);
5568 if (p == null) {
5569 return null;
5570 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 return p.getSignalStrength();
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005576 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005577
Pengquan Meng77b7f132018-08-22 14:49:57 -07005578 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005579 * Get the current modem radio state for the given slot.
5580 * @param slotIndex slot index.
5581 * @param callingPackage the name of the package making the call.
5582 * @return the current radio power state from the modem
5583 */
5584 @Override
5585 public int getRadioPowerState(int slotIndex, String callingPackage) {
5586 Phone phone = PhoneFactory.getPhone(slotIndex);
5587 if (phone != null) {
5588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5589 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5590 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5591 }
5592
5593 final long identity = Binder.clearCallingIdentity();
5594 try {
5595 return phone.getRadioPowerState();
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
5599 }
5600 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5601 }
5602
5603 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005604 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5605 *
5606 * <p>Requires one of the following permissions:
5607 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5608 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5609 * privileges.
5610 *
5611 * @param subId subscription id
5612 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5613 * {@code false}.
5614 */
5615 @Override
5616 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005617 boolean isEnabled = false;
5618 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005619 try {
5620 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005621 null /* message */);
5622 Phone phone = getPhone(subId);
5623 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005624 } catch (Exception e) {
5625 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5626 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005627 } finally {
5628 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005629 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005630 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005631 }
5632
5633
5634 /**
5635 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5636 *
5637 * <p> Requires permission:
5638 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5639 * privileges.
5640 *
5641 * @param subId subscription id
5642 * @param isEnabled {@code true} means enable, {@code false} means disable.
5643 */
5644 @Override
5645 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5649 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005650
Pengquan Menga1bb6272018-09-06 09:59:22 -07005651 Phone phone = getPhone(subId);
5652 if (phone != null) {
5653 phone.setDataRoamingEnabled(isEnabled);
5654 }
5655 } finally {
5656 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005657 }
5658 }
5659
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005660 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005661 public boolean isManualNetworkSelectionAllowed(int subId) {
5662 boolean isAllowed = true;
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5666 mApp, subId, "isManualNetworkSelectionAllowed");
5667 Phone phone = getPhone(subId);
5668 if (phone != null) {
5669 isAllowed = phone.isCspPlmnEnabled();
5670 }
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
5674 return isAllowed;
5675 }
5676
5677 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005678 public UiccCardInfo[] getUiccCardsInfo() {
5679 enforceReadPrivilegedPermission("getUiccCardsInfo");
5680
5681 final long identity = Binder.clearCallingIdentity();
5682 try {
5683 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5684 return cards.toArray(new UiccCardInfo[cards.size()]);
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689
5690 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005691 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005692 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5697 if (slots == null) {
5698 Rlog.i(LOG_TAG, "slots is null.");
5699 return null;
5700 }
5701
5702 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5703 for (int i = 0; i < slots.length; i++) {
5704 UiccSlot slot = slots[i];
5705 if (slot == null) {
5706 continue;
5707 }
5708
5709 String cardId;
5710 UiccCard card = slot.getUiccCard();
5711 if (card != null) {
5712 cardId = card.getCardId();
5713 } else {
5714 cardId = slot.getIccId();
5715 }
5716
5717 int cardState = 0;
5718 switch (slot.getCardState()) {
5719 case CARDSTATE_ABSENT:
5720 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5721 break;
5722 case CARDSTATE_PRESENT:
5723 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5724 break;
5725 case CARDSTATE_ERROR:
5726 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5727 break;
5728 case CARDSTATE_RESTRICTED:
5729 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5730 break;
5731 default:
5732 break;
5733
5734 }
5735
5736 infos[i] = new UiccSlotInfo(
5737 slot.isActive(),
5738 slot.isEuicc(),
5739 cardId,
5740 cardState,
5741 slot.getPhoneId(),
5742 slot.isExtendedApduSupported());
5743 }
5744 return infos;
5745 } finally {
5746 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005747 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005748 }
5749
5750 @Override
5751 public boolean switchSlots(int[] physicalSlots) {
5752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753
5754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005760 }
Jack Yu4c988042018-02-27 15:30:01 -08005761
5762 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005763 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5765 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5766 return TelephonyManager.INVALID_CARD_ID;
5767 }
5768
5769 final long identity = Binder.clearCallingIdentity();
5770 try {
5771 return UiccController.getInstance().getCardIdForDefaultEuicc();
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
5775 }
5776
5777 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005778 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5779 enforceModifyPermission();
5780 final Phone phone = getPhone(subId);
5781 if (phone == null) {
5782 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5783 return;
5784 }
5785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 phone.setRadioIndicationUpdateMode(filters, mode);
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
Jack Yu4c988042018-02-27 15:30:01 -08005792 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005793
5794 /**
goneil47ffb6e2018-04-06 15:40:58 -07005795 * A test API to reload the UICC profile.
5796 *
5797 * <p>Requires that the calling app has permission
5798 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5799 * @hide
5800 */
5801 @Override
5802 public void refreshUiccProfile(int subId) {
5803 enforceModifyPermission();
5804
5805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 Phone phone = getPhone(subId);
5808 if (phone == null) {
5809 return;
5810 }
5811 UiccCard uiccCard = phone.getUiccCard();
5812 if (uiccCard == null) {
5813 return;
5814 }
5815 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5816 if (uiccProfile == null) {
5817 return;
5818 }
5819 uiccProfile.refresh();
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
5823 }
5824
5825 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005826 * Returns false if the mobile data is disabled by default, otherwise return true.
5827 */
5828 private boolean getDefaultDataEnabled() {
5829 return "true".equalsIgnoreCase(
5830 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5831 }
5832
5833 /**
5834 * Returns true if the data roaming is enabled by default, i.e the system property
5835 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5836 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5837 */
5838 private boolean getDefaultDataRoamingEnabled(int subId) {
5839 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005840 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005841 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5842 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5843 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5844 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5845 return isDataRoamingEnabled;
5846 }
5847
5848 /**
5849 * Returns the default network type for the given {@code subId}, if the default network type is
5850 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5851 */
5852 private int getDefaultNetworkType(int subId) {
5853 return Integer.parseInt(
5854 TelephonyManager.getTelephonyProperty(
5855 mSubscriptionController.getPhoneId(subId),
5856 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5857 String.valueOf(Phone.PREFERRED_NT_MODE)));
5858 }
fionaxua13278b2018-03-21 00:08:13 -07005859
5860 @Override
5861 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5862 gid1, String gid2, String plmn, String spn) {
5863 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864
5865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 final Phone phone = getPhone(subId);
5868 if (phone == null) {
5869 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5870 return;
5871 }
5872 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5873 } finally {
5874 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005875 }
fionaxua13278b2018-03-21 00:08:13 -07005876 }
5877
5878 @Override
5879 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005880 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 final Phone phone = getPhone(subId);
5885 if (phone == null) {
5886 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5887 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5888 }
5889 return phone.getCarrierIdListVersion();
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005892 }
fionaxua13278b2018-03-21 00:08:13 -07005893 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005894
5895 @Override
5896 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5898 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5899 return -1;
5900 }
5901
5902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
5908 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005909
5910 @Override
5911 public int getCdmaRoamingMode(int subId) {
5912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5913 mApp, subId, "getCdmaRoamingMode");
5914
5915 final long identity = Binder.clearCallingIdentity();
5916 try {
5917 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
5921 }
5922
5923 @Override
5924 public boolean setCdmaRoamingMode(int subId, int mode) {
5925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5926 mApp, subId, "setCdmaRoamingMode");
5927
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
5930 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
5934 }
5935
5936 @Override
5937 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5939 mApp, subId, "setCdmaSubscriptionMode");
5940
5941 final long identity = Binder.clearCallingIdentity();
5942 try {
5943 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
5947 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005948
5949 private void ensureUserRunning(int userId) {
5950 if (!mUserManager.isUserRunning(userId)) {
5951 throw new IllegalStateException("User " + userId + " does not exist or not running");
5952 }
5953 }
5954
5955 /**
5956 * Returns a list of SMS apps on a given user.
5957 *
5958 * Only the shell user (UID 2000 or 0) can call it.
5959 * Target user must be running.
5960 */
5961 @Override
5962 public String[] getSmsApps(int userId) {
5963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5964 ensureUserRunning(userId);
5965
5966 final Collection<SmsApplicationData> apps =
5967 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5968
5969 String[] ret = new String[apps.size()];
5970 int i = 0;
5971 for (SmsApplicationData app : apps) {
5972 ret[i++] = app.mPackageName;
5973 }
5974 return ret;
5975 }
5976
5977 /**
5978 * Returns the default SMS app package name on a given user.
5979 *
5980 * Only the shell user (UID 2000 or 0) can call it.
5981 * Target user must be running.
5982 */
5983 @Override
5984 public String getDefaultSmsApp(int userId) {
5985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5986 ensureUserRunning(userId);
5987
5988 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5989 /* updateIfNeeded= */ true, userId);
5990 return cn == null ? null : cn.getPackageName();
5991 }
5992
5993 /**
5994 * Set a package as the default SMS app on a given user.
5995 *
5996 * Only the shell user (UID 2000 or 0) can call it.
5997 * Target user must be running.
5998 */
5999 @Override
6000 public void setDefaultSmsApp(int userId, String packageName) {
6001 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6002 ensureUserRunning(userId);
6003
6004 boolean found = false;
6005 for (String pkg : getSmsApps(userId)) {
6006 if (TextUtils.equals(packageName, pkg)) {
6007 found = true;
6008 break;
6009 }
6010 }
6011 if (!found) {
6012 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6013 }
6014
6015 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6016 }
sqianc5eccab2018-10-19 18:46:41 -07006017
6018 @Override
6019 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6020 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6022 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6023 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6024 }
6025 final long identity = Binder.clearCallingIdentity();
6026 try {
sqian854d44b2018-12-12 16:48:18 -08006027 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6028 for (Phone phone: PhoneFactory.getPhones()) {
6029 if (phone.getEmergencyNumberTracker() != null
6030 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6031 emergencyNumberListInternal.put(
6032 phone.getSubId(),
6033 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6034 }
sqian11b7a0e2018-12-05 18:48:28 -08006035 }
sqian854d44b2018-12-12 16:48:18 -08006036 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
sqianc5eccab2018-10-19 18:46:41 -07006040 }
6041
6042 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006043 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006044 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006045 if (!exactMatch) {
6046 TelephonyPermissions
6047 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006048 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006049 }
6050 final long identity = Binder.clearCallingIdentity();
6051 try {
sqian854d44b2018-12-12 16:48:18 -08006052 for (Phone phone: PhoneFactory.getPhones()) {
6053 if (phone.getEmergencyNumberTracker() != null
6054 && phone.getEmergencyNumberTracker() != null) {
6055 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6056 number, exactMatch)) {
6057 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006058 }
6059 }
sqian11b7a0e2018-12-05 18:48:28 -08006060 }
6061 return false;
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
6065 }
6066
sqianf4ca7ed2019-01-15 18:32:07 -08006067 /**
6068 * Update emergency number list for test mode.
6069 */
6070 @Override
6071 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6072 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6073 "updateEmergencyNumberListTestMode");
6074
6075 final long identity = Binder.clearCallingIdentity();
6076 try {
6077 for (Phone phone: PhoneFactory.getPhones()) {
6078 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6079 if (tracker != null) {
6080 tracker.executeEmergencyNumberTestModeCommand(action, num);
6081 }
6082 }
6083 } finally {
6084 Binder.restoreCallingIdentity(identity);
6085 }
6086 }
6087
6088 /**
6089 * Get the full emergency number list for test mode.
6090 */
6091 @Override
6092 public List<String> getEmergencyNumberListTestMode() {
6093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6094 "getEmergencyNumberListTestMode");
6095
6096 final long identity = Binder.clearCallingIdentity();
6097 try {
6098 Set<String> emergencyNumbers = new HashSet<>();
6099 for (Phone phone: PhoneFactory.getPhones()) {
6100 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6101 if (tracker != null) {
6102 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6103 emergencyNumbers.add(num.getNumber());
6104 }
6105 }
6106 }
6107 return new ArrayList<>(emergencyNumbers);
6108 } finally {
6109 Binder.restoreCallingIdentity(identity);
6110 }
6111 }
6112
chen xud6b45bd2018-10-30 22:27:10 -07006113 @Override
6114 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6115 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6116 Phone phone = getPhone(subId);
6117 if (phone == null) {
6118 return null;
6119 }
6120 final long identity = Binder.clearCallingIdentity();
6121 try {
6122 UiccProfile profile = UiccController.getInstance()
6123 .getUiccProfileForPhone(phone.getPhoneId());
6124 if (profile != null) {
6125 return profile.getCertsFromCarrierPrivilegeAccessRules();
6126 }
6127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129 }
6130 return null;
6131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006132}