blob: eff2a63cfdc793c5cb669a5c82dd8af982d49155 [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;
Santos Cordon7a1885b2015-02-03 11:15:19 -080055import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080056import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070057import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080059import android.telephony.CarrierRestrictionRules;
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;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800235 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
236 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800238 // Parameters of select command.
239 private static final int SELECT_COMMAND = 0xA4;
240 private static final int SELECT_P1 = 0x04;
241 private static final int SELECT_P2 = 0;
242 private static final int SELECT_P3 = 0x10;
243
Pengquan Meng85728fb2018-03-12 16:31:21 -0700244 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
245 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
246 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
247
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 /** The singleton instance. */
249 private static PhoneInterfaceManager sInstance;
250
Wink Saville3ab207e2014-11-20 13:07:20 -0800251 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700253 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800254 private AppOpsManager mAppOps;
255 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800256 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800257 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700258 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259
Derek Tan97ebb422014-09-05 16:55:38 -0700260 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
261 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800262 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700263
Derek Tan740e1672017-06-27 14:56:27 -0700264 // The AID of ISD-R.
265 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
266
yinxub1bed742017-04-17 11:45:04 -0700267 private NetworkScanRequestTracker mNetworkScanRequestTracker;
268
David Kelly5e06a7f2018-03-12 14:10:59 +0000269 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
270 private static final int MANUFACTURER_CODE_LENGTH = 8;
271
Derek Tan89e89d42014-07-08 17:00:10 -0700272 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700273 * A request object to use for transmitting data to an ICC.
274 */
275 private static final class IccAPDUArgument {
276 public int channel, cla, command, p1, p2, p3;
277 public String data;
278
279 public IccAPDUArgument(int channel, int cla, int command,
280 int p1, int p2, int p3, String data) {
281 this.channel = channel;
282 this.cla = cla;
283 this.command = command;
284 this.p1 = p1;
285 this.p2 = p2;
286 this.p3 = p3;
287 this.data = data;
288 }
289 }
290
291 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700292 * A request object to use for transmitting data to an ICC.
293 */
294 private static final class ManualNetworkSelectionArgument {
295 public OperatorInfo operatorInfo;
296 public boolean persistSelection;
297
298 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
299 this.operatorInfo = operatorInfo;
300 this.persistSelection = persistSelection;
301 }
302 }
303
304 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
306 * request after sending. The main thread will notify the request when it is complete.
307 */
308 private static final class MainThreadRequest {
309 /** The argument to use for the request */
310 public Object argument;
311 /** The result of the request that is run on the main thread */
312 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800313 // The subscriber id that this request applies to. Defaults to
314 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
315 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316
Nathan Harold92bed182018-10-12 18:16:49 -0700317 // In cases where subId is unavailable, the caller needs to specify the phone.
318 public Phone phone;
319
vagdeviaf9a5b92018-08-15 16:01:53 -0700320 public WorkSource workSource;
321
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 public MainThreadRequest(Object argument) {
323 this.argument = argument;
324 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800325
Nathan Harold92bed182018-10-12 18:16:49 -0700326 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
327 this.argument = argument;
328 if (phone != null) {
329 this.phone = phone;
330 }
331 this.workSource = workSource;
332 }
333
vagdeviaf9a5b92018-08-15 16:01:53 -0700334 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800335 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800336 if (subId != null) {
337 this.subId = subId;
338 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700339 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 }
342
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800343 private static final class IncomingThirdPartyCallArgs {
344 public final ComponentName component;
345 public final String callId;
346 public final String callerDisplayName;
347
348 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
349 String callerDisplayName) {
350 this.component = component;
351 this.callId = callId;
352 this.callerDisplayName = callerDisplayName;
353 }
354 }
355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 /**
357 * A handler that processes messages on the main thread in the phone process. Since many
358 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
359 * inbound binder threads to the main thread in the phone process. The Binder thread
360 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
361 * on, which will be notified when the operation completes and will contain the result of the
362 * request.
363 *
364 * <p>If a MainThreadRequest object is provided in the msg.obj field,
365 * note that request.result must be set to something non-null for the calling thread to
366 * unblock.
367 */
368 private final class MainThreadHandler extends Handler {
369 @Override
370 public void handleMessage(Message msg) {
371 MainThreadRequest request;
372 Message onCompleted;
373 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800374 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700375 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800376 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377
378 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700379 case CMD_HANDLE_USSD_REQUEST: {
380 request = (MainThreadRequest) msg.obj;
381 final Phone phone = getPhoneFromRequest(request);
382 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
383 String ussdRequest = ussdObject.first;
384 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700385
Pengquan Menga1bb6272018-09-06 09:59:22 -0700386 if (!isUssdApiAllowed(request.subId)) {
387 // Carrier does not support use of this API, return failure.
388 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
389 UssdResponse response = new UssdResponse(ussdRequest, null);
390 Bundle returnData = new Bundle();
391 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
392 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700393
Pengquan Menga1bb6272018-09-06 09:59:22 -0700394 request.result = true;
395 notifyRequester(request);
396 return;
397 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700398
Pengquan Menga1bb6272018-09-06 09:59:22 -0700399 try {
400 request.result = phone != null
401 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
402 } catch (CallStateException cse) {
403 request.result = false;
404 }
405 // Wake up the requesting thread
406 notifyRequester(request);
407 break;
pkanwar32d516d2016-10-14 19:37:38 -0700408 }
409
Yorke Lee716f67e2015-06-17 15:39:16 -0700410 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700412 final Phone phone = getPhoneFromRequest(request);
413 request.result = phone != null ?
414 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
415 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700422 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800424 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 if (uiccCard == null) {
426 loge("iccTransmitApduLogicalChannel: No UICC");
427 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700428 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
431 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700432 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 iccArgument.channel, iccArgument.cla, iccArgument.command,
434 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 break;
438
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 ar = (AsyncResult) msg.obj;
441 request = (MainThreadRequest) ar.userObj;
442 if (ar.exception == null && ar.result != null) {
443 request.result = ar.result;
444 } else {
445 request.result = new IccIoResult(0x6F, 0, (byte[])null);
446 if (ar.result == null) {
447 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800448 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800450 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 } else {
452 loge("iccTransmitApduLogicalChannel: Unknown exception");
453 }
454 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 break;
457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
459 request = (MainThreadRequest) msg.obj;
460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduBasicChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 } else {
467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
468 request);
469 uiccCard.iccTransmitApduBasicChannel(
470 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
471 iccArgument.p3, iccArgument.data, onCompleted);
472 }
473 break;
474
475 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
476 ar = (AsyncResult) msg.obj;
477 request = (MainThreadRequest) ar.userObj;
478 if (ar.exception == null && ar.result != null) {
479 request.result = ar.result;
480 } else {
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
482 if (ar.result == null) {
483 loge("iccTransmitApduBasicChannel: Empty response");
484 } else if (ar.exception instanceof CommandException) {
485 loge("iccTransmitApduBasicChannel: CommandException: " +
486 ar.exception);
487 } else {
488 loge("iccTransmitApduBasicChannel: Unknown exception");
489 }
490 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 break;
493
494 case CMD_EXCHANGE_SIM_IO:
495 request = (MainThreadRequest) msg.obj;
496 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800497 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 if (uiccCard == null) {
499 loge("iccExchangeSimIO: No UICC");
500 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 } else {
503 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
504 request);
505 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
506 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
507 iccArgument.data, onCompleted);
508 }
509 break;
510
511 case EVENT_EXCHANGE_SIM_IO_DONE:
512 ar = (AsyncResult) msg.obj;
513 request = (MainThreadRequest) ar.userObj;
514 if (ar.exception == null && ar.result != null) {
515 request.result = ar.result;
516 } else {
517 request.result = new IccIoResult(0x6f, 0, (byte[])null);
518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 break;
521
Derek Tan4d5e5c12014-02-04 11:54:58 -0800522 case CMD_SEND_ENVELOPE:
523 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800524 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700525 if (uiccCard == null) {
526 loge("sendEnvelopeWithStatus: No UICC");
527 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 } else {
530 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
531 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
532 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 break;
534
535 case EVENT_SEND_ENVELOPE_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700538 if (ar.exception == null && ar.result != null) {
539 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
542 if (ar.result == null) {
543 loge("sendEnvelopeWithStatus: Empty response");
544 } else if (ar.exception instanceof CommandException) {
545 loge("sendEnvelopeWithStatus: CommandException: " +
546 ar.exception);
547 } else {
548 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
549 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800552 break;
553
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 case CMD_OPEN_CHANNEL:
555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800557 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 if (uiccCard == null) {
559 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800560 request.result = new IccOpenLogicalChannelResponse(-1,
561 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 } else {
564 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800565 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
566 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 break;
569
570 case EVENT_OPEN_CHANNEL_DONE:
571 ar = (AsyncResult) msg.obj;
572 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 int[] result = (int[]) ar.result;
576 int channelId = result[0];
577 byte[] selectResponse = null;
578 if (result.length > 1) {
579 selectResponse = new byte[result.length - 1];
580 for (int i = 1; i < result.length; ++i) {
581 selectResponse[i - 1] = (byte) result[i];
582 }
583 }
584 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700585 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 if (ar.result == null) {
588 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 if (ar.exception != null) {
591 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
592 }
593
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700595 if (ar.exception instanceof CommandException) {
596 CommandException.Error error =
597 ((CommandException) (ar.exception)).getCommandError();
598 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700600 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 }
603 }
604 openChannelResp = new IccOpenLogicalChannelResponse(
605 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700607 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
611 case CMD_CLOSE_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800613 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 if (uiccCard == null) {
615 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900616 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 } else {
619 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
620 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
624 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800625 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
626 break;
627
628 case CMD_NV_READ_ITEM:
629 request = (MainThreadRequest) msg.obj;
630 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800631 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
632 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800633 break;
634
635 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800638 if (ar.exception == null && ar.result != null) {
639 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800641 request.result = "";
642 if (ar.result == null) {
643 loge("nvReadItem: Empty response");
644 } else if (ar.exception instanceof CommandException) {
645 loge("nvReadItem: CommandException: " +
646 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800648 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 }
650 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 break;
653
Jake Hambye994d462014-02-03 13:10:13 -0800654 case CMD_NV_WRITE_ITEM:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
657 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800658 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700659 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800660 break;
661
662 case EVENT_NV_WRITE_ITEM_DONE:
663 handleNullReturnEvent(msg, "nvWriteItem");
664 break;
665
666 case CMD_NV_WRITE_CDMA_PRL:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800669 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_WRITE_CDMA_PRL_DONE:
673 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
674 break;
675
chen xu6dac5ab2018-10-26 17:39:23 -0700676 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800677 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700678 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800679 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800680 break;
681
chen xu6dac5ab2018-10-26 17:39:23 -0700682 case EVENT_RESET_MODEM_CONFIG_DONE:
683 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800684 break;
685
Jake Hamby7c27be32014-03-03 13:25:59 -0800686 case CMD_GET_PREFERRED_NETWORK_TYPE:
687 request = (MainThreadRequest) msg.obj;
688 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700689 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800690 break;
691
692 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result; // Integer
697 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800698 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 if (ar.result == null) {
700 loge("getPreferredNetworkType: Empty response");
701 } else if (ar.exception instanceof CommandException) {
702 loge("getPreferredNetworkType: CommandException: " +
703 ar.exception);
704 } else {
705 loge("getPreferredNetworkType: Unknown exception");
706 }
707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800709 break;
710
711 case CMD_SET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
714 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700715 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 break;
717
718 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
719 handleNullReturnEvent(msg, "setPreferredNetworkType");
720 break;
721
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000722 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
723 request = (MainThreadRequest)msg.obj;
724 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800725 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000726 break;
727
728 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
729 ar = (AsyncResult)msg.obj;
730 request = (MainThreadRequest)ar.userObj;
731 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000733 break;
734
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800735 case CMD_SET_VOICEMAIL_NUMBER:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
738 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800739 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
740 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800741 break;
742
743 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
744 handleNullReturnEvent(msg, "setVoicemailNumber");
745 break;
746
Stuart Scott54788802015-03-30 13:18:01 -0700747 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
750 request);
751 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
752 break;
753
754 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
755 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
756 break;
757
Shishir Agrawal302c8692015-06-19 13:49:39 -0700758 case CMD_PERFORM_NETWORK_SCAN:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
761 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
762 break;
763
764 case EVENT_PERFORM_NETWORK_SCAN_DONE:
765 ar = (AsyncResult) msg.obj;
766 request = (MainThreadRequest) ar.userObj;
767 CellNetworkScanResult cellScanResult;
768 if (ar.exception == null && ar.result != null) {
769 cellScanResult = new CellNetworkScanResult(
770 CellNetworkScanResult.STATUS_SUCCESS,
771 (List<OperatorInfo>) ar.result);
772 } else {
773 if (ar.result == null) {
774 loge("getCellNetworkScanResults: Empty response");
775 }
776 if (ar.exception != null) {
777 loge("getCellNetworkScanResults: Exception: " + ar.exception);
778 }
779 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
780 if (ar.exception instanceof CommandException) {
781 CommandException.Error error =
782 ((CommandException) (ar.exception)).getCommandError();
783 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
784 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
785 } else if (error == CommandException.Error.GENERIC_FAILURE) {
786 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
787 }
788 }
789 cellScanResult = new CellNetworkScanResult(errorCode, null);
790 }
791 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700792 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700793 break;
794
795 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
796 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700797 ManualNetworkSelectionArgument selArg =
798 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
800 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700801 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
802 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700803 break;
804
805 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 if (ar.exception == null) {
809 request.result = true;
810 } else {
811 request.result = false;
812 loge("setNetworkSelectionModeManual " + ar.exception);
813 }
814 notifyRequester(request);
815 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700816 break;
817
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700818 case CMD_GET_MODEM_ACTIVITY_INFO:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800821 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700822 break;
823
824 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
825 ar = (AsyncResult) msg.obj;
826 request = (MainThreadRequest) ar.userObj;
827 if (ar.exception == null && ar.result != null) {
828 request.result = ar.result;
829 } else {
830 if (ar.result == null) {
831 loge("queryModemActivityInfo: Empty response");
832 } else if (ar.exception instanceof CommandException) {
833 loge("queryModemActivityInfo: CommandException: " +
834 ar.exception);
835 } else {
836 loge("queryModemActivityInfo: Unknown exception");
837 }
838 }
Amit Mahajand4766222016-01-28 15:28:28 -0800839 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
840 if (request.result == null) {
841 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
842 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700843 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700844 break;
845
Meng Wang1a7c35a2016-05-05 20:56:15 -0700846 case CMD_SET_ALLOWED_CARRIERS:
847 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800848 CarrierRestrictionRules argument =
849 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700850 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800851 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700852 break;
853
854 case EVENT_SET_ALLOWED_CARRIERS_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800860 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
861 if (ar.exception instanceof CommandException) {
862 loge("setAllowedCarriers: CommandException: " + ar.exception);
863 CommandException.Error error =
864 ((CommandException) (ar.exception)).getCommandError();
865 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
866 request.result =
867 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
868 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 } else {
870 loge("setAllowedCarriers: Unknown exception");
871 }
872 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700873 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700874 break;
875
876 case CMD_GET_ALLOWED_CARRIERS:
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800879 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 break;
881
882 case EVENT_GET_ALLOWED_CARRIERS_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result;
887 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800888 request.result = new IllegalStateException(
889 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 if (ar.result == null) {
891 loge("getAllowedCarriers: Empty response");
892 } else if (ar.exception instanceof CommandException) {
893 loge("getAllowedCarriers: CommandException: " +
894 ar.exception);
895 } else {
896 loge("getAllowedCarriers: Unknown exception");
897 }
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;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001088 case CMD_REQUEST_ENABLE_MODEM:
1089 request = (MainThreadRequest) msg.obj;
1090 boolean enable = (boolean) request.argument;
1091 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1092 PhoneConfigurationManager.getInstance()
1093 .enablePhone(request.phone, enable, onCompleted);
1094 break;
1095 case EVENT_ENABLE_MODEM_DONE:
1096 ar = (AsyncResult) msg.obj;
1097 request = (MainThreadRequest) ar.userObj;
1098 request.result = (ar.exception == null);
1099 notifyRequester(request);
1100 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001101 default:
1102 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1103 break;
1104 }
1105 }
Jake Hambye994d462014-02-03 13:10:13 -08001106
Pengquan Menga1bb6272018-09-06 09:59:22 -07001107 private void notifyRequester(MainThreadRequest request) {
1108 synchronized (request) {
1109 request.notifyAll();
1110 }
1111 }
1112
Jake Hambye994d462014-02-03 13:10:13 -08001113 private void handleNullReturnEvent(Message msg, String command) {
1114 AsyncResult ar = (AsyncResult) msg.obj;
1115 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1116 if (ar.exception == null) {
1117 request.result = true;
1118 } else {
1119 request.result = false;
1120 if (ar.exception instanceof CommandException) {
1121 loge(command + ": CommandException: " + ar.exception);
1122 } else {
1123 loge(command + ": Unknown exception");
1124 }
1125 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001126 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001128 }
1129
1130 /**
1131 * Posts the specified command to be executed on the main thread,
1132 * waits for the request to complete, and returns the result.
1133 * @see #sendRequestAsync
1134 */
1135 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001136 return sendRequest(
1137 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001138 }
1139
1140 /**
1141 * Posts the specified command to be executed on the main thread,
1142 * waits for the request to complete, and returns the result.
1143 * @see #sendRequestAsync
1144 */
1145 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1146 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001147 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001148 }
1149
1150 /**
1151 * Posts the specified command to be executed on the main thread,
1152 * waits for the request to complete, and returns the result.
1153 * @see #sendRequestAsync
1154 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001155 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001156 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001157 }
1158
1159 /**
1160 * Posts the specified command to be executed on the main thread,
1161 * waits for the request to complete, and returns the result.
1162 * @see #sendRequestAsync
1163 */
Nathan Harold92bed182018-10-12 18:16:49 -07001164 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1165 return sendRequest(command, argument, subId, null, workSource);
1166 }
1167
1168 /**
1169 * Posts the specified command to be executed on the main thread,
1170 * waits for the request to complete, and returns the result.
1171 * @see #sendRequestAsync
1172 */
1173 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1174 return sendRequest(
1175 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1176 }
1177
1178 /**
1179 * Posts the specified command to be executed on the main thread,
1180 * waits for the request to complete, and returns the result.
1181 * @see #sendRequestAsync
1182 */
1183 private Object sendRequest(
1184 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1186 throw new RuntimeException("This method will deadlock if called from the main thread.");
1187 }
1188
Nathan Harold92bed182018-10-12 18:16:49 -07001189 MainThreadRequest request = null;
1190 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1191 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1192 } else if (phone != null) {
1193 request = new MainThreadRequest(argument, phone, workSource);
1194 } else {
1195 request = new MainThreadRequest(argument, subId, workSource);
1196 }
1197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001198 Message msg = mMainThreadHandler.obtainMessage(command, request);
1199 msg.sendToTarget();
1200
1201 // Wait for the request to complete
1202 synchronized (request) {
1203 while (request.result == null) {
1204 try {
1205 request.wait();
1206 } catch (InterruptedException e) {
1207 // Do nothing, go back and wait until the request is complete
1208 }
1209 }
1210 }
1211 return request.result;
1212 }
1213
1214 /**
1215 * Asynchronous ("fire and forget") version of sendRequest():
1216 * Posts the specified command to be executed on the main thread, and
1217 * returns immediately.
1218 * @see #sendRequest
1219 */
1220 private void sendRequestAsync(int command) {
1221 mMainThreadHandler.sendEmptyMessage(command);
1222 }
1223
1224 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001225 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001226 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001227 */
1228 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001229 sendRequestAsync(command, argument, null, null);
1230 }
1231
1232 /**
1233 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1234 * @see {@link #sendRequest(int,Object)}
1235 */
1236 private void sendRequestAsync(
1237 int command, Object argument, Phone phone, WorkSource workSource) {
1238 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001239 Message msg = mMainThreadHandler.obtainMessage(command, request);
1240 msg.sendToTarget();
1241 }
1242
1243 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 * Initialize the singleton PhoneInterfaceManager instance.
1245 * This is only done once, at startup, from PhoneApp.onCreate().
1246 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001247 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 synchronized (PhoneInterfaceManager.class) {
1249 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001250 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 } else {
1252 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1253 }
1254 return sInstance;
1255 }
1256 }
1257
1258 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001259 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001262 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1264 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001265 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001266 mTelephonySharedPreferences =
1267 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001268 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001269 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001270
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 publish();
1272 }
1273
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001274 private Phone getDefaultPhone() {
1275 Phone thePhone = getPhone(getDefaultSubscription());
1276 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1277 }
1278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 private void publish() {
1280 if (DBG) log("publish: " + this);
1281
1282 ServiceManager.addService("phone", this);
1283 }
1284
Stuart Scott584921c2015-01-15 17:10:34 -08001285 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001286 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001287 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001288 }
1289
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001290 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1291 Phone phone = getPhoneFromRequest(request);
1292 return phone == null ? null :
1293 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1294 }
1295
Wink Saville36469e72014-06-11 15:17:00 -07001296 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001297 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001298 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300
1301 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001302 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001303 }
1304
Wink Savilleb564aae2014-10-23 10:18:09 -07001305 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 if (DBG) log("dial: " + number);
1307 // No permission check needed here: This is just a wrapper around the
1308 // ACTION_DIAL intent, which is available to any app since it puts up
1309 // the UI before it does anything.
1310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001311 final long identity = Binder.clearCallingIdentity();
1312 try {
1313 String url = createTelUrl(number);
1314 if (url == null) {
1315 return;
1316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001318 // PENDING: should we just silently fail if phone is offhook or ringing?
1319 PhoneConstants.State state = mCM.getState(subId);
1320 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1321 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1322 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1323 mApp.startActivity(intent);
1324 }
1325 } finally {
1326 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 }
1328 }
1329
1330 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001331 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
1333
Wink Savilleb564aae2014-10-23 10:18:09 -07001334 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 if (DBG) log("call: " + number);
1336
1337 // This is just a wrapper around the ACTION_CALL intent, but we still
1338 // need to do a permission check since we're calling startActivity()
1339 // from the context of the phone app.
1340 enforceCallPermission();
1341
1342 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1343 != AppOpsManager.MODE_ALLOWED) {
1344 return;
1345 }
1346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001347 final long identity = Binder.clearCallingIdentity();
1348 try {
1349 String url = createTelUrl(number);
1350 if (url == null) {
1351 return;
1352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001354 boolean isValid = false;
1355 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1356 if (slist != null) {
1357 for (SubscriptionInfo subInfoRecord : slist) {
1358 if (subInfoRecord.getSubscriptionId() == subId) {
1359 isValid = true;
1360 break;
1361 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001362 }
Wink Saville08874612014-08-31 19:19:58 -07001363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001364 if (!isValid) {
1365 return;
1366 }
Wink Saville08874612014-08-31 19:19:58 -07001367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001368 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1369 intent.putExtra(SUBSCRIPTION_KEY, subId);
1370 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1371 mApp.startActivity(intent);
1372 } finally {
1373 Binder.restoreCallingIdentity(identity);
1374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 }
1376
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001379 }
1380
Wink Savilleb564aae2014-10-23 10:18:09 -07001381 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001382 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001383 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1384 }
1385
1386 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001387 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001388 }
1389
Wink Savilleb564aae2014-10-23 10:18:09 -07001390 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001391 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001392 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1393 }
1394
1395 /** {@hide} */
1396 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001397 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001398 }
1399
Wink Savilleb564aae2014-10-23 10:18:09 -07001400 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001402
1403 final long identity = Binder.clearCallingIdentity();
1404 try {
1405 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1406 checkSimPin.start();
1407 return checkSimPin.unlockSim(null, pin);
1408 } finally {
1409 Binder.restoreCallingIdentity(identity);
1410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 }
1412
Wink Saville9de0f752013-10-22 19:04:03 -07001413 /** {@hide} */
1414 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001415 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001416 }
1417
Wink Savilleb564aae2014-10-23 10:18:09 -07001418 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001420
1421 final long identity = Binder.clearCallingIdentity();
1422 try {
1423 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1424 checkSimPuk.start();
1425 return checkSimPuk.unlockSim(puk, pin);
1426 } finally {
1427 Binder.restoreCallingIdentity(identity);
1428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 }
1430
1431 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001432 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 * a synchronous one.
1434 */
1435 private static class UnlockSim extends Thread {
1436
1437 private final IccCard mSimCard;
1438
1439 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001440 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1441 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
1443 // For replies from SimCard interface
1444 private Handler mHandler;
1445
1446 // For async handler to identify request type
1447 private static final int SUPPLY_PIN_COMPLETE = 100;
1448
1449 public UnlockSim(IccCard simCard) {
1450 mSimCard = simCard;
1451 }
1452
1453 @Override
1454 public void run() {
1455 Looper.prepare();
1456 synchronized (UnlockSim.this) {
1457 mHandler = new Handler() {
1458 @Override
1459 public void handleMessage(Message msg) {
1460 AsyncResult ar = (AsyncResult) msg.obj;
1461 switch (msg.what) {
1462 case SUPPLY_PIN_COMPLETE:
1463 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1464 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001465 mRetryCount = msg.arg1;
1466 if (ar.exception != null) {
1467 if (ar.exception instanceof CommandException &&
1468 ((CommandException)(ar.exception)).getCommandError()
1469 == CommandException.Error.PASSWORD_INCORRECT) {
1470 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1471 } else {
1472 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1473 }
1474 } else {
1475 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 mDone = true;
1478 UnlockSim.this.notifyAll();
1479 }
1480 break;
1481 }
1482 }
1483 };
1484 UnlockSim.this.notifyAll();
1485 }
1486 Looper.loop();
1487 }
1488
1489 /*
1490 * Use PIN or PUK to unlock SIM card
1491 *
1492 * If PUK is null, unlock SIM card with PIN
1493 *
1494 * If PUK is not null, unlock SIM card with PUK and set PIN code
1495 */
Wink Saville9de0f752013-10-22 19:04:03 -07001496 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497
1498 while (mHandler == null) {
1499 try {
1500 wait();
1501 } catch (InterruptedException e) {
1502 Thread.currentThread().interrupt();
1503 }
1504 }
1505 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1506
1507 if (puk == null) {
1508 mSimCard.supplyPin(pin, callback);
1509 } else {
1510 mSimCard.supplyPuk(puk, pin, callback);
1511 }
1512
1513 while (!mDone) {
1514 try {
1515 Log.d(LOG_TAG, "wait for done");
1516 wait();
1517 } catch (InterruptedException e) {
1518 // Restore the interrupted status
1519 Thread.currentThread().interrupt();
1520 }
1521 }
1522 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001523 int[] resultArray = new int[2];
1524 resultArray[0] = mResult;
1525 resultArray[1] = mRetryCount;
1526 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 }
1528 }
1529
1530 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001531 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001532
1533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 // No permission check needed here: this call is harmless, and it's
1537 // needed for the ServiceState.requestStateUpdate() call (which is
1538 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001539 final long identity = Binder.clearCallingIdentity();
1540 try {
1541 final Phone phone = getPhone(subId);
1542 if (phone != null) {
1543 phone.updateServiceLocation();
1544 }
1545 } finally {
1546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 }
1549
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001550 @Override
1551 public boolean isRadioOn(String callingPackage) {
1552 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001555 @Override
1556 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001558 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001559 return false;
1560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001561
1562 final long identity = Binder.clearCallingIdentity();
1563 try {
1564 return isRadioOnForSubscriber(subId);
1565 } finally {
1566 Binder.restoreCallingIdentity(identity);
1567 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001568 }
1569
1570 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 final Phone phone = getPhone(subId);
1574 if (phone != null) {
1575 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1576 } else {
1577 return false;
1578 }
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 }
1583
1584 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001585 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 }
Wink Saville36469e72014-06-11 15:17:00 -07001587
Wink Savilleb564aae2014-10-23 10:18:09 -07001588 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001590
1591 final long identity = Binder.clearCallingIdentity();
1592 try {
1593 final Phone phone = getPhone(subId);
1594 if (phone != null) {
1595 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1596 }
1597 } finally {
1598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 }
Wink Saville36469e72014-06-11 15:17:00 -07001600 }
1601
1602 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001604 }
1605
Wink Savilleb564aae2014-10-23 10:18:09 -07001606 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001608
1609 final long identity = Binder.clearCallingIdentity();
1610 try {
1611 final Phone phone = getPhone(subId);
1612 if (phone == null) {
1613 return false;
1614 }
1615 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1616 toggleRadioOnOffForSubscriber(subId);
1617 }
1618 return true;
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
Wink Saville36469e72014-06-11 15:17:00 -07001623
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001624 public boolean needMobileRadioShutdown() {
1625 /*
1626 * If any of the Radios are available, it will need to be
1627 * shutdown. So return true if any Radio is available.
1628 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001629 final long identity = Binder.clearCallingIdentity();
1630 try {
1631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1632 Phone phone = PhoneFactory.getPhone(i);
1633 if (phone != null && phone.isRadioAvailable()) return true;
1634 }
1635 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1636 return false;
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001639 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001640 }
1641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001642 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001643 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001644 enforceModifyPermission();
1645
1646 final long identity = Binder.clearCallingIdentity();
1647 try {
1648 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1649 logv("Shutting down Phone " + i);
1650 shutdownRadioUsingPhoneId(i);
1651 }
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001654 }
1655 }
1656
1657 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001658 Phone phone = PhoneFactory.getPhone(phoneId);
1659 if (phone != null && phone.isRadioAvailable()) {
1660 phone.shutdownRadio();
1661 }
1662 }
1663
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001666
1667 final long identity = Binder.clearCallingIdentity();
1668 try {
1669 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1670 if (defaultPhone != null) {
1671 defaultPhone.setRadioPower(turnOn);
1672 return true;
1673 } else {
1674 loge("There's no default phone.");
1675 return false;
1676 }
1677 } finally {
1678 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001679 }
Wink Saville36469e72014-06-11 15:17:00 -07001680 }
1681
Wink Savilleb564aae2014-10-23 10:18:09 -07001682 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 final Phone phone = getPhone(subId);
1688 if (phone != null) {
1689 phone.setRadioPower(turnOn);
1690 return true;
1691 } else {
1692 return false;
1693 }
1694 } finally {
1695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
1698
Wink Saville36469e72014-06-11 15:17:00 -07001699 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 public boolean enableDataConnectivity() {
1702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001703
1704 final long identity = Binder.clearCallingIdentity();
1705 try {
1706 int subId = mSubscriptionController.getDefaultDataSubId();
1707 final Phone phone = getPhone(subId);
1708 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001709 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710 return true;
1711 } else {
1712 return false;
1713 }
1714 } finally {
1715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
1718
Wink Saville36469e72014-06-11 15:17:00 -07001719 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 public boolean disableDataConnectivity() {
1722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723
1724 final long identity = Binder.clearCallingIdentity();
1725 try {
1726 int subId = mSubscriptionController.getDefaultDataSubId();
1727 final Phone phone = getPhone(subId);
1728 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001729 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001730 return true;
1731 } else {
1732 return false;
1733 }
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
Sanket Padawe356d7632015-06-22 14:03:32 -07001739 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001740 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001741 final long identity = Binder.clearCallingIdentity();
1742 try {
1743 final Phone phone = getPhone(subId);
1744 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001745 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746 } else {
1747 return false;
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
1753
1754 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001755 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
pkanwarae03a6b2016-11-06 20:37:09 -08001758 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759 enforceCallPermission();
1760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1764 return;
1765 }
1766 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1767 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1768 } finally {
1769 Binder.restoreCallingIdentity(identity);
1770 }
pkanwar32d516d2016-10-14 19:37:38 -07001771 };
1772
Wink Savilleb564aae2014-10-23 10:18:09 -07001773 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1779 return false;
1780 }
1781 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001788 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001789 }
1790
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001791 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 Phone phone = PhoneFactory.getPhone(slotIndex);
1795 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1796 PhoneConstantConversions.convertCallState(phone.getState());
1797 } finally {
1798 Binder.restoreCallingIdentity(identity);
1799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 }
1801
Sanket Padawe356d7632015-06-22 14:03:32 -07001802 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001804 final long identity = Binder.clearCallingIdentity();
1805 try {
1806 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1807 if (phone != null) {
1808 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1809 } else {
1810 return PhoneConstantConversions.convertDataState(
1811 PhoneConstants.DataState.DISCONNECTED);
1812 }
1813 } finally {
1814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 }
1817
Sanket Padawe356d7632015-06-22 14:03:32 -07001818 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1823 if (phone != null) {
1824 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1825 } else {
1826 return TelephonyManager.DATA_ACTIVITY_NONE;
1827 }
1828 } finally {
1829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
1833 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001834 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001835 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001836 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001837 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1838 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001839 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001842 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843 final long identity = Binder.clearCallingIdentity();
1844 try {
1845 if (DBG_LOC) log("getCellLocation: is active user");
1846 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001847 int subId = mSubscriptionController.getDefaultDataSubId();
1848 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1849 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001850 return data;
1851 } finally {
1852 Binder.restoreCallingIdentity(identity);
1853 }
Svetoslav64fad262015-04-14 14:35:21 -07001854 }
1855
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001857 public String getNetworkCountryIsoForPhone(int phoneId) {
1858 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1859 // registered cell info, so return a NULL country instead.
1860 final long identity = Binder.clearCallingIdentity();
1861 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001862 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1863 // Get default phone in this case.
1864 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1865 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001866 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001867 // Todo: fix this when we can get the actual cellular network info when the device
1868 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001869 if (TelephonyManager.NETWORK_TYPE_IWLAN
1870 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1871 return "";
1872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001873 Phone phone = PhoneFactory.getPhone(phoneId);
1874 if (phone != null) {
1875 ServiceStateTracker sst = phone.getServiceStateTracker();
1876 if (sst != null) {
1877 LocaleTracker lt = sst.getLocaleTracker();
1878 if (lt != null) {
1879 return lt.getCurrentCountry();
1880 }
1881 }
1882 }
1883 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001884 } finally {
1885 Binder.restoreCallingIdentity(identity);
1886 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001887 }
1888
1889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001891 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001895 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 mApp.enforceCallingOrSelfPermission(
1897 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898
1899 final long identity = Binder.clearCallingIdentity();
1900 try {
1901 final Phone phone = getPhone(subId);
1902 if (phone != null) {
1903 phone.enableLocationUpdates();
1904 }
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
1910 @Override
1911 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001912 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001916 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 mApp.enforceCallingOrSelfPermission(
1918 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001919
1920 final long identity = Binder.clearCallingIdentity();
1921 try {
1922 final Phone phone = getPhone(subId);
1923 if (phone != null) {
1924 phone.disableLocationUpdates();
1925 }
1926 } finally {
1927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930
Nathan Harold31d7ff32018-10-15 20:20:30 -07001931 /**
1932 * Returns the target SDK version number for a given package name.
1933 *
1934 * @return target SDK if the package is found or INT_MAX.
1935 */
1936 private int getTargetSdk(String packageName) {
1937 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001938 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1939 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001940 if (ai != null) return ai.targetSdkVersion;
1941 } catch (PackageManager.NameNotFoundException unexpected) {
1942 }
1943 return Integer.MAX_VALUE;
1944 }
1945
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 @Override
1947 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001948 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1949 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001950 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1951 throw new SecurityException(
1952 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1953 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1956 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1957 return null;
1958 }
Svetoslav64fad262015-04-14 14:35:21 -07001959
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001960 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961
Nathan Haroldf180aac2018-06-01 18:43:55 -07001962 List<CellInfo> info = getAllCellInfo(callingPackage);
1963 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964
Nathan Haroldf180aac2018-06-01 18:43:55 -07001965 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1966 for (CellInfo ci : info) {
1967 if (ci instanceof CellInfoGsm) {
1968 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1969 } else if (ci instanceof CellInfoWcdma) {
1970 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001973 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001976 private List<CellInfo> getCachedCellInfo() {
1977 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1978 for (Phone phone : PhoneFactory.getPhones()) {
1979 List<CellInfo> info = phone.getAllCellInfo();
1980 if (info != null) cellInfos.addAll(info);
1981 }
1982 return cellInfos;
1983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984
1985 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001986 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001987 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001988 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001989 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001990 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001991 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 }
1993
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001994 final int targetSdk = getTargetSdk(callingPackage);
1995 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1996 return getCachedCellInfo();
1997 }
1998
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001999 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001 final long identity = Binder.clearCallingIdentity();
2002 try {
2003 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2004 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002005 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002006 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002007 if (info != null) cellInfos.addAll(info);
2008 }
2009 return cellInfos;
2010 } finally {
2011 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 }
2013 }
2014
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002015 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002016 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2017 requestCellInfoUpdateInternal(
2018 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2019 }
2020
2021 @Override
2022 public void requestCellInfoUpdateWithWorkSource(
2023 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2024 enforceModifyPermission();
2025 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2026 }
2027
2028 private void requestCellInfoUpdateInternal(
2029 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002030 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002031 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002032 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2033 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002034 return;
2035 }
2036
2037 final Phone phone = getPhone(subId);
2038 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2039
2040 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2041 }
2042
2043 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002045 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002046 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002047
2048 final long identity = Binder.clearCallingIdentity();
2049 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002050 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002051 } finally {
2052 Binder.restoreCallingIdentity(identity);
2053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
2055
Shishir Agrawala9f32182016-04-12 12:00:16 -07002056 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002057 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002058 Phone phone = PhoneFactory.getPhone(slotIndex);
2059 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002060 return null;
2061 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002062 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002063 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2064 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002065 return null;
2066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067
2068 final long identity = Binder.clearCallingIdentity();
2069 try {
2070 return phone.getImei();
2071 } finally {
2072 Binder.restoreCallingIdentity(identity);
2073 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002074 }
2075
2076 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002077 public String getTypeAllocationCodeForSlot(int slotIndex) {
2078 Phone phone = PhoneFactory.getPhone(slotIndex);
2079 String tac = null;
2080 if (phone != null) {
2081 String imei = phone.getImei();
2082 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2083 }
2084 return tac;
2085 }
2086
2087 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002088 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002089 Phone phone = PhoneFactory.getPhone(slotIndex);
2090 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002091 return null;
2092 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002093
Jeff Davidson913390f2018-02-23 17:11:49 -08002094 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002095 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2096 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002097 return null;
2098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 return phone.getMeid();
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
2105 }
Jack Yu2af8d712017-03-15 17:14:14 -07002106 }
2107
2108 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002109 public String getManufacturerCodeForSlot(int slotIndex) {
2110 Phone phone = PhoneFactory.getPhone(slotIndex);
2111 String manufacturerCode = null;
2112 if (phone != null) {
2113 String meid = phone.getMeid();
2114 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2115 }
2116 return manufacturerCode;
2117 }
2118
2119 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002120 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002121 Phone phone = PhoneFactory.getPhone(slotIndex);
2122 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002123 return null;
2124 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002125 int subId = phone.getSubId();
2126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2127 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2128 return null;
2129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002130
2131 final long identity = Binder.clearCallingIdentity();
2132 try {
2133 return phone.getDeviceSvn();
2134 } finally {
2135 Binder.restoreCallingIdentity(identity);
2136 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002137 }
2138
fionaxu43304da2017-11-27 22:51:16 -08002139 @Override
2140 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002141 final long identity = Binder.clearCallingIdentity();
2142 try {
2143 final Phone phone = getPhone(subId);
2144 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
2147 }
fionaxu43304da2017-11-27 22:51:16 -08002148 }
2149
2150 @Override
2151 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152 final long identity = Binder.clearCallingIdentity();
2153 try {
2154 final Phone phone = getPhone(subId);
2155 return phone == null ? null : phone.getCarrierName();
2156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
fionaxu43304da2017-11-27 22:51:16 -08002159 }
2160
calvinpanffe225e2018-11-01 19:43:06 +08002161 @Override
chen xu25637222018-11-04 17:17:00 -08002162 public int getSubscriptionPreciseCarrierId(int subId) {
2163 final long identity = Binder.clearCallingIdentity();
2164 try {
2165 final Phone phone = getPhone(subId);
2166 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2167 : phone.getPreciseCarrierId();
2168 } finally {
2169 Binder.restoreCallingIdentity(identity);
2170 }
2171 }
2172
2173 @Override
2174 public String getSubscriptionPreciseCarrierName(int subId) {
2175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 final Phone phone = getPhone(subId);
2178 return phone == null ? null : phone.getPreciseCarrierName();
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
2181 }
2182 }
2183
chen xu651eec72018-11-11 19:03:44 -08002184 @Override
chen xu864e11c2018-12-06 22:10:03 -08002185 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2186 if (!isSubscriptionMccMnc) {
2187 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2188 }
chen xu651eec72018-11-11 19:03:44 -08002189 final Phone phone = PhoneFactory.getPhone(slotIndex);
2190 if (phone == null) {
2191 return TelephonyManager.UNKNOWN_CARRIER_ID;
2192 }
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
2198 }
2199 }
2200
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 //
2202 // Internal helper methods.
2203 //
2204
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002205 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2207 *
2208 * @throws SecurityException if the caller does not have the required permission
2209 */
2210 private void enforceModifyPermission() {
2211 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2212 }
2213
2214 /**
2215 * Make sure the caller has the CALL_PHONE permission.
2216 *
2217 * @throws SecurityException if the caller does not have the required permission
2218 */
2219 private void enforceCallPermission() {
2220 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2221 }
2222
Stuart Scott8eef64f2015-04-08 15:13:54 -07002223 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002224 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002225 "ConnectivityService");
2226 }
2227
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 private String createTelUrl(String number) {
2229 if (TextUtils.isEmpty(number)) {
2230 return null;
2231 }
2232
Jake Hambye994d462014-02-03 13:10:13 -08002233 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
Ihab Awadf9e92732013-12-05 18:02:52 -08002236 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2238 }
2239
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002240 private static void logv(String msg) {
2241 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2242 }
2243
Ihab Awadf9e92732013-12-05 18:02:52 -08002244 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2246 }
2247
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002250 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002254 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 final Phone phone = PhoneFactory.getPhone(slotIndex);
2258 if (phone == null) {
2259 return PhoneConstants.PHONE_TYPE_NONE;
2260 } else {
2261 return phone.getPhoneType();
2262 }
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
2268 /**
2269 * Returns the CDMA ERI icon index to display
2270 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002271 @Override
2272 public int getCdmaEriIconIndex(String callingPackage) {
2273 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002274 }
2275
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002277 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002279 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002280 return -1;
2281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282
2283 final long identity = Binder.clearCallingIdentity();
2284 try {
2285 final Phone phone = getPhone(subId);
2286 if (phone != null) {
2287 return phone.getCdmaEriIconIndex();
2288 } else {
2289 return -1;
2290 }
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 /**
2297 * Returns the CDMA ERI icon mode,
2298 * 0 - ON
2299 * 1 - FLASHING
2300 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 @Override
2302 public int getCdmaEriIconMode(String callingPackage) {
2303 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002307 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002309 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002310 return -1;
2311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 final Phone phone = getPhone(subId);
2316 if (phone != null) {
2317 return phone.getCdmaEriIconMode();
2318 } else {
2319 return -1;
2320 }
2321 } finally {
2322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 }
2325
2326 /**
2327 * Returns the CDMA ERI text,
2328 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002329 @Override
2330 public String getCdmaEriText(String callingPackage) {
2331 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
2333
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002335 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002337 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 return null;
2339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 final Phone phone = getPhone(subId);
2344 if (phone != null) {
2345 return phone.getCdmaEriText();
2346 } else {
2347 return null;
2348 }
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
2354 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002355 * Returns the CDMA MDN.
2356 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2360 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002361
2362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002365 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366 return phone.getLine1Number();
2367 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002368 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 return null;
2370 }
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002373 }
2374 }
2375
2376 /**
2377 * Returns the CDMA MIN.
2378 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002379 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002380 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2382 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002383
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 final Phone phone = getPhone(subId);
2387 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2388 return phone.getCdmaMin();
2389 } else {
2390 return null;
2391 }
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002394 }
2395 }
2396
Hall Liud892bec2018-11-30 14:51:45 -08002397 @Override
2398 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2399 INumberVerificationCallback callback, String callingPackage) {
2400 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2401 != PERMISSION_GRANTED) {
2402 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2403 }
2404 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2405
2406 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2407 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2408 throw new SecurityException("Calling package must be configured in the device config");
2409 }
2410
2411 if (range == null) {
2412 throw new NullPointerException("Range must be non-null");
2413 }
2414
2415 timeoutMillis = Math.min(timeoutMillis,
2416 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2417
2418 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2419 }
2420
Junda Liuca05d5d2014-08-14 22:36:34 -07002421 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 * Returns true if CDMA provisioning needs to run.
2423 */
2424 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 final long identity = Binder.clearCallingIdentity();
2426 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002427 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
2433 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002434 * Sets the voice mail number of a given subId.
2435 */
2436 @Override
2437 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002438 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002439
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2443 new Pair<String, String>(alphaTag, number), new Integer(subId));
2444 return success;
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002448 }
2449
Ta-wei Yen87c49842016-05-13 21:19:52 -07002450 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002451 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002453 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002454 if (!TextUtils.equals(callingPackage, systemDialer)) {
2455 throw new SecurityException("caller must be system dialer");
2456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457
2458 final long identity = Binder.clearCallingIdentity();
2459 try {
2460 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2461 if (phoneAccountHandle == null) {
2462 return null;
2463 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002464 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 } finally {
2466 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002467 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002468 }
2469
2470 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002471 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002474 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002475 return null;
2476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002478 final long identity = Binder.clearCallingIdentity();
2479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002480 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002481 } finally {
2482 Binder.restoreCallingIdentity(identity);
2483 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002484 }
2485
2486 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002487 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2488 VisualVoicemailSmsFilterSettings settings) {
2489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002494 mApp, callingPackage, subId, settings);
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 void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002507 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002511 }
2512
2513 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002514 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2515 String callingPackage, int subId) {
2516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002521 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522 } finally {
2523 Binder.restoreCallingIdentity(identity);
2524 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002525 }
2526
2527 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002528 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002529 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002534 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002538 }
2539
2540 @Override
2541 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2542 String number, int port, String text, PendingIntent sentIntent) {
2543 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002544 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002545 enforceSendSmsPermission();
2546 // Make the calls as the phone process.
2547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2550 if (port == 0) {
2551 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2552 sentIntent, null, false);
2553 } else {
2554 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2555 smsManager.sendDataMessageWithSelfPermissions(number, null,
2556 (short) port, data, sentIntent, null);
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
2560 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002561 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002562 /**
fionaxu0152e512016-11-14 13:36:14 -08002563 * Sets the voice activation state of a given subId.
2564 */
2565 @Override
2566 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2568 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 phone.setVoiceActivationState(activationState);
2575 } else {
2576 loge("setVoiceActivationState fails with invalid subId: " + subId);
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002580 }
2581 }
2582
2583 /**
2584 * Sets the data activation state of a given subId.
2585 */
2586 @Override
2587 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2589 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 final Phone phone = getPhone(subId);
2594 if (phone != null) {
2595 phone.setDataActivationState(activationState);
2596 } else {
2597 loge("setVoiceActivationState fails with invalid subId: " + subId);
2598 }
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002601 }
2602 }
2603
2604 /**
2605 * Returns the voice activation state of a given subId.
2606 */
2607 @Override
2608 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002609 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610
fionaxu0152e512016-11-14 13:36:14 -08002611 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 if (phone != null) {
2615 return phone.getVoiceActivationState();
2616 } else {
2617 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002621 }
2622 }
2623
2624 /**
2625 * Returns the data activation state of a given subId.
2626 */
2627 @Override
2628 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002629 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630
fionaxu0152e512016-11-14 13:36:14 -08002631 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 if (phone != null) {
2635 return phone.getDataActivationState();
2636 } else {
2637 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002641 }
2642 }
2643
2644 /**
Wink Saville36469e72014-06-11 15:17:00 -07002645 * Returns the unread count of voicemails for a subId
2646 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002647 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002648 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2650 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2651 return 0;
2652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 final Phone phone = getPhone(subId);
2656 if (phone != null) {
2657 return phone.getVoiceMessageCount();
2658 } else {
2659 return 0;
2660 }
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 }
2665
2666 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002667 * returns true, if the device is in a state where both voice and data
2668 * are supported simultaneously. This can change based on location or network condition.
2669 */
2670 @Override
2671 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 final Phone phone = getPhone(subId);
2675 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002679 }
2680
2681 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002682 * Send the dialer code if called from the current default dialer or the caller has
2683 * carrier privilege.
2684 * @param inputCode The dialer code to send
2685 */
2686 @Override
2687 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002688 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002690 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2691 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002692 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002693 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2694 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002699 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700 } finally {
2701 Binder.restoreCallingIdentity(identity);
2702 }
fionaxu235cc5e2017-03-06 22:25:57 -08002703 }
2704
2705 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002706 * Returns the data network type.
2707 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 *
2709 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2710 */
2711 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002712 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 final Phone phone = getPhone(getDefaultSubscription());
2716 if (phone != null) {
2717 return phone.getServiceState().getDataNetworkType();
2718 } else {
2719 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2720 }
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002723 }
Wink Saville36469e72014-06-11 15:17:00 -07002724 }
2725
Pengquan Menga1bb6272018-09-06 09:59:22 -07002726 @Override
2727 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002728 if (!isActiveSubscription(subId)) {
2729 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2730 }
2731
Pengquan Menga1bb6272018-09-06 09:59:22 -07002732 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2733 }
2734
Brad Ebinger35c841c2018-10-01 10:40:55 -07002735 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002736 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2737 throws RemoteException {
2738 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002739 final long token = Binder.clearCallingIdentity();
2740 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002743 .addRegistrationCallbackForSubscription(c, subId);
2744 } finally {
2745 Binder.restoreCallingIdentity(token);
2746 }
2747 }
2748
2749 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002750 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2751 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2753 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2754 }
2755 Binder.withCleanCallingIdentity(() -> {
2756 try {
2757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002759 .removeRegistrationCallbackForSubscription(c, subId);
2760 } catch (IllegalArgumentException e) {
2761 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2762 + "is inactive, ignoring unregister.");
2763 // If the subscription is no longer active, just return, since the callback
2764 // will already have been removed internally.
2765 }
2766 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002767 }
2768
2769 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002770 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2771 throws RemoteException {
2772 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002773 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2774 final long token = Binder.clearCallingIdentity();
2775 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002776 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002777 .addCapabilitiesCallbackForSubscription(c, subId);
2778 } finally {
2779 Binder.restoreCallingIdentity(token);
2780 }
2781 }
2782
2783 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002784 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2785 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002786
2787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2788 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2789 }
2790 Binder.withCleanCallingIdentity(() -> {
2791 try {
2792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002793 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002794 .removeCapabilitiesCallbackForSubscription(c, subId);
2795 } catch (IllegalArgumentException e) {
2796 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2797 + "is inactive, ignoring unregister.");
2798 // If the subscription is no longer active, just return, since the callback
2799 // will already have been removed internally.
2800 }
2801 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002802 }
2803
2804 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002805 public boolean isCapable(int subId, int capability, int regTech) {
2806 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002807 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2808 final long token = Binder.clearCallingIdentity();
2809 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002810 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002811 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2812 } catch (ImsException e) {
2813 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2814 return false;
2815 } finally {
2816 Binder.restoreCallingIdentity(token);
2817 }
2818 }
2819
2820 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002821 public boolean isAvailable(int subId, int capability, int regTech) {
2822 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002823 final long token = Binder.clearCallingIdentity();
2824 try {
2825 Phone phone = getPhone(subId);
2826 if (phone == null) return false;
2827 return phone.isImsCapabilityAvailable(capability, regTech);
2828 } finally {
2829 Binder.restoreCallingIdentity(token);
2830 }
2831 }
2832
2833 @Override
2834 public boolean isAdvancedCallingSettingEnabled(int subId) {
2835 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2837 final long token = Binder.clearCallingIdentity();
2838 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002839 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002840 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2841 } finally {
2842 Binder.restoreCallingIdentity(token);
2843 }
2844 }
2845
2846 @Override
2847 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2849 "setAdvancedCallingSetting");
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002853 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002854 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
2857 }
2858 }
2859
2860 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002861 public boolean isVtSettingEnabled(int subId) {
2862 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002867 getSlotIndexOrException(subId)).isVtEnabledByUser();
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
2870 }
2871 }
2872
2873 @Override
2874 public void setVtSetting(int subId, boolean isEnabled) {
2875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2876 "setVtSetting");
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002880 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002881 } finally {
2882 Binder.restoreCallingIdentity(identity);
2883 }
2884 }
2885
2886 @Override
2887 public boolean isVoWiFiSettingEnabled(int subId) {
2888 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002892 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002893 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
2896 }
2897 }
2898
2899 @Override
2900 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2902 "setVoWiFiSetting");
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002906 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002907 } finally {
2908 Binder.restoreCallingIdentity(identity);
2909 }
2910 }
2911
2912 @Override
2913 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2914 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002918 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002919 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
2922 }
2923 }
2924
2925 @Override
2926 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2928 "setVoWiFiRoamingSetting");
2929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002932 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2934 } finally {
2935 Binder.restoreCallingIdentity(identity);
2936 }
2937 }
2938
2939 @Override
2940 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2942 "setVoWiFiNonPersistent");
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002946 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002947 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
2951 }
2952
2953 @Override
2954 public int getVoWiFiModeSetting(int subId) {
2955 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002959 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002960 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
2964 }
2965
2966 @Override
2967 public void setVoWiFiModeSetting(int subId, int mode) {
2968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2969 "setVoWiFiModeSetting");
2970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002973 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002974 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
2977 }
2978 }
2979
2980 @Override
2981 public int getVoWiFiRoamingModeSetting(int subId) {
2982 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002986 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
2991 }
2992
2993 @Override
2994 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2996 "setVoWiFiRoamingModeSetting");
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003000 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003001 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
3005 }
3006
3007 @Override
3008 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3010 "setRttCapabilityEnabled");
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003015 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
3019 }
3020
3021 @Override
3022 public boolean isTtyOverVolteEnabled(int subId) {
3023 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003028 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
3032 }
3033
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003034 @Override
3035 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3036 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003040 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003041 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
3045 }
3046
3047 @Override
3048 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3049 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3050 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003051 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3052 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3053 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003054 try {
3055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003056 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003057 .removeProvisioningCallbackForSubscription(callback, subId);
3058 } catch (IllegalArgumentException e) {
3059 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3060 + "is inactive, ignoring unregister.");
3061 // If the subscription is no longer active, just return, since the callback will already
3062 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
3066 }
3067
3068 @Override
3069 public int getImsProvisioningInt(int subId, int key) {
3070 enforceReadPrivilegedPermission("getImsProvisioningInt");
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003074 return ImsManager.getInstance(mApp,
3075 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003076 } catch (ImsException e) {
3077 throw new IllegalArgumentException(e.getMessage());
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
3081 }
3082
3083 @Override
3084 public String getImsProvisioningString(int subId, int key) {
3085 enforceReadPrivilegedPermission("getImsProvisioningString");
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003089 return ImsManager.getInstance(mApp,
3090 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003091 } catch (ImsException e) {
3092 throw new IllegalArgumentException(e.getMessage());
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
3098 @Override
3099 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3101 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003105 return ImsManager.getInstance(mApp,
3106 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003107 } catch (ImsException e) {
3108 throw new IllegalArgumentException(e.getMessage());
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
3114 @Override
3115 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3117 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003121 return ImsManager.getInstance(mApp,
3122 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003123 } catch (ImsException e) {
3124 throw new IllegalArgumentException(e.getMessage());
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
3128 }
3129
Brad Ebinger35c841c2018-10-01 10:40:55 -07003130 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3131 int slotId = SubscriptionManager.getSlotIndex(subId);
3132 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3133 throw new IllegalArgumentException("Invalid Subscription Id.");
3134 }
3135 return slotId;
3136 }
3137
Wink Saville36469e72014-06-11 15:17:00 -07003138 /**
3139 * Returns the network type for a subId
3140 */
3141 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003142 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003144 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003145 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3146 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 final Phone phone = getPhone(subId);
3151 if (phone != null) {
3152 return phone.getServiceState().getDataNetworkType();
3153 } else {
3154 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3155 }
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 }
3160
3161 /**
3162 * Returns the data network type
3163 */
3164 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003165 public int getDataNetworkType(String callingPackage) {
3166 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003167 }
3168
3169 /**
3170 * Returns the data network type for a subId
3171 */
3172 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003173 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003175 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003176 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3177 }
3178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179 final long identity = Binder.clearCallingIdentity();
3180 try {
3181 final Phone phone = getPhone(subId);
3182 if (phone != null) {
3183 return phone.getServiceState().getDataNetworkType();
3184 } else {
3185 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3186 }
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 }
3191
3192 /**
Wink Saville36469e72014-06-11 15:17:00 -07003193 * Returns the Voice network type for a subId
3194 */
3195 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003196 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003198 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003199 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3200 }
3201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 final Phone phone = getPhone(subId);
3205 if (phone != null) {
3206 return phone.getServiceState().getVoiceNetworkType();
3207 } else {
3208 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3209 }
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 }
3214
3215 /**
3216 * @return true if a ICC card is present
3217 */
3218 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003219 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003220 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3221 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003222 }
3223
3224 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003225 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003226 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003227 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003228 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 final Phone phone = PhoneFactory.getPhone(slotIndex);
3232 if (phone != null) {
3233 return phone.getIccCard().hasIccCard();
3234 } else {
3235 return false;
3236 }
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 }
3241
3242 /**
3243 * Return if the current radio is LTE on CDMA. This
3244 * is a tri-state return value as for a period of time
3245 * the mode may be unknown.
3246 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003247 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003249 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003251 @Override
3252 public int getLteOnCdmaMode(String callingPackage) {
3253 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003254 }
3255
Sanket Padawe356d7632015-06-22 14:03:32 -07003256 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003257 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003259 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003260 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3261 }
3262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 final Phone phone = getPhone(subId);
3266 if (phone == null) {
3267 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3268 } else {
3269 return phone.getLteOnCdmaMode();
3270 }
3271 } finally {
3272 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003273 }
Wink Saville36469e72014-06-11 15:17:00 -07003274 }
3275
Wink Saville36469e72014-06-11 15:17:00 -07003276 /**
3277 * {@hide}
3278 * Returns Default subId, 0 in the case of single standby.
3279 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003280 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003281 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003282 }
3283
Shishir Agrawala9f32182016-04-12 12:00:16 -07003284 private int getSlotForDefaultSubscription() {
3285 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3286 }
3287
Wink Savilleb564aae2014-10-23 10:18:09 -07003288 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003289 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003291
Pengquan Menge92a50d2018-09-21 15:54:48 -07003292 private boolean isActiveSubscription(int subId) {
3293 return mSubscriptionController.isActiveSubId(subId);
3294 }
3295
Ihab Awadf2177b72013-11-25 13:33:23 -08003296 /**
3297 * @see android.telephony.TelephonyManager.WifiCallingChoices
3298 */
3299 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003300 final long identity = Binder.clearCallingIdentity();
3301 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003302 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3304 getWhenToMakeWifiCallsDefaultPreference());
3305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003308 }
3309
3310 /**
3311 * @see android.telephony.TelephonyManager.WifiCallingChoices
3312 */
3313 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003322 }
3323
Sailesh Nepald1e68152013-12-12 19:08:02 -08003324 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003325 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003326 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003327 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003328
Shishir Agrawal566b7612013-10-28 14:41:00 -07003329 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003330 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3331 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3333 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 final long identity = Binder.clearCallingIdentity();
3337 try {
3338 if (TextUtils.equals(ISDR_AID, aid)) {
3339 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003340 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3341 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 if (bestComponent == null
3343 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3344 loge("The calling package is not allowed to access ISD-R.");
3345 throw new SecurityException(
3346 "The calling package is not allowed to access ISD-R.");
3347 }
Derek Tan740e1672017-06-27 14:56:27 -07003348 }
Derek Tan740e1672017-06-27 14:56:27 -07003349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350 if (DBG) {
3351 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3352 }
3353 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3354 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3355 if (DBG) log("iccOpenLogicalChannel: " + response);
3356 return response;
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003360 }
3361
3362 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003363 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3365 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3370 if (channel < 0) {
3371 return false;
3372 }
3373 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3374 if (DBG) log("iccCloseLogicalChannel: " + success);
3375 return success;
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003378 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003379 }
3380
3381 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003382 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003383 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3385 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 if (DBG) {
3390 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3391 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3392 + p3 + " data=" + data);
3393 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395 if (channel < 0) {
3396 return "";
3397 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3400 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3401 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 // Append the returned status code to the end of the response payload.
3404 String s = Integer.toHexString(
3405 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3406 if (response.payload != null) {
3407 s = IccUtils.bytesToHexString(response.payload) + s;
3408 }
3409 return s;
3410 } finally {
3411 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003412 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003413 }
Jake Hambye994d462014-02-03 13:10:13 -08003414
Evan Charltonc66da362014-05-16 14:06:40 -07003415 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003416 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3417 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3419 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3425 && TextUtils.equals(ISDR_AID, data)) {
3426 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003427 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3428 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 if (bestComponent == null
3430 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3431 loge("The calling package is not allowed to select ISD-R.");
3432 throw new SecurityException(
3433 "The calling package is not allowed to select ISD-R.");
3434 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003435 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437 if (DBG) {
3438 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3439 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3440 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003442 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3443 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3444 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 // Append the returned status code to the end of the response payload.
3447 String s = Integer.toHexString(
3448 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3449 if (response.payload != null) {
3450 s = IccUtils.bytesToHexString(response.payload) + s;
3451 }
3452 return s;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003455 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003456 }
3457
3458 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003459 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003460 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3462 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 if (DBG) {
3467 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3468 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3469 }
3470
3471 IccIoResult response =
3472 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3473 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3474 subId);
3475
3476 if (DBG) {
3477 log("Exchange SIM_IO [R]" + response);
3478 }
3479
3480 byte[] result = null;
3481 int length = 2;
3482 if (response.payload != null) {
3483 length = 2 + response.payload.length;
3484 result = new byte[length];
3485 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3486 } else {
3487 result = new byte[length];
3488 }
3489
3490 result[length - 1] = (byte) response.sw2;
3491 result[length - 2] = (byte) response.sw1;
3492 return result;
3493 } finally {
3494 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003495 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003496 }
3497
Nathan Haroldb3014052017-01-25 15:57:32 -08003498 /**
3499 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3500 * on a particular subscription
3501 */
sqianb6e41952018-03-12 14:54:01 -07003502 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3504 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3505 return null;
3506 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 if (appType != TelephonyManager.APPTYPE_USIM
3511 && appType != TelephonyManager.APPTYPE_SIM) {
3512 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3513 return null;
3514 }
3515 Object response = sendRequest(
3516 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3517 if (response instanceof String[]) {
3518 return (String[]) response;
3519 }
3520 // Response is an Exception of some kind,
3521 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003522 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003525 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003526 }
3527
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003528 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003529 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3531 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3536 if (response.payload == null) {
3537 return "";
3538 }
Evan Charltonc66da362014-05-16 14:06:40 -07003539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 // Append the returned status code to the end of the response payload.
3541 String s = Integer.toHexString(
3542 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3543 s = IccUtils.bytesToHexString(response.payload) + s;
3544 return s;
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
Evan Charltonc66da362014-05-16 14:06:40 -07003548 }
3549
Jake Hambye994d462014-02-03 13:10:13 -08003550 /**
3551 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3552 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3553 *
3554 * @param itemID the ID of the item to read
3555 * @return the NV item as a String, or null on error.
3556 */
3557 @Override
3558 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003559 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3561 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003566 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3568 return value;
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
3571 }
Jake Hambye994d462014-02-03 13:10:13 -08003572 }
3573
3574 /**
3575 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3576 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3577 *
3578 * @param itemID the ID of the item to read
3579 * @param itemValue the value to write, as a String
3580 * @return true on success; false on any failure
3581 */
3582 @Override
3583 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3586 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3591 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003592 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3594 return success;
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
Jake Hambye994d462014-02-03 13:10:13 -08003598 }
3599
3600 /**
3601 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3602 * Used for device configuration by some CDMA operators.
3603 *
3604 * @param preferredRoamingList byte array containing the new PRL
3605 * @return true on success; false on any failure
3606 */
3607 @Override
3608 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3610 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611
3612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3615 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3616 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3617 return success;
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
Jake Hambye994d462014-02-03 13:10:13 -08003621 }
3622
3623 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003624 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003625 * Used for device configuration by some CDMA operators.
3626 *
chen xu6dac5ab2018-10-26 17:39:23 -07003627 * @param slotIndex - device slot.
3628 *
Jake Hambye994d462014-02-03 13:10:13 -08003629 * @return true on success; false on any failure
3630 */
3631 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003632 public boolean resetModemConfig(int slotIndex) {
3633 Phone phone = PhoneFactory.getPhone(slotIndex);
3634 if (phone != null) {
3635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3636 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637
chen xu6dac5ab2018-10-26 17:39:23 -07003638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3641 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3642 return success;
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 }
chen xu6dac5ab2018-10-26 17:39:23 -07003647 return false;
3648 }
3649
3650 /**
3651 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3652 *
3653 * @param slotIndex - device slot.
3654 *
3655 * @return true on success; false on any failure
3656 */
3657 @Override
3658 public boolean rebootModem(int slotIndex) {
3659 Phone phone = PhoneFactory.getPhone(slotIndex);
3660 if (phone != null) {
3661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3662 mApp, phone.getSubId(), "rebootModem");
3663
3664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3667 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3668 return success;
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
3672 }
3673 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003674 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003675
Svet Ganovb320e182015-04-16 12:30:10 -07003676 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003677 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003679 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003680 return new String[0];
3681 }
3682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683 final long identity = Binder.clearCallingIdentity();
3684 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003685 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
Wink Saville36469e72014-06-11 15:17:00 -07003689 }
3690
Brad Ebinger51f743a2017-01-23 13:50:20 -08003691 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003692 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3693 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003694 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003695 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003696 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 PhoneFactory.getImsResolver().enableIms(slotId);
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003704 }
3705
3706 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003707 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3708 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003709 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003710 public void disableIms(int slotId) {
3711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 PhoneFactory.getImsResolver().disableIms(slotId);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003719 }
3720
3721 /**
3722 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3723 * feature or {@link null} if the service is not available. If the feature is available, the
3724 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3725 */
3726 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003727 IImsServiceFeatureCallback callback) {
3728 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3733 } finally {
3734 Binder.restoreCallingIdentity(identity);
3735 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003736 }
3737
3738 /**
3739 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3740 * feature during emergency calling or {@link null} if the service is not available. If the
3741 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3742 * listener for feature updates.
3743 */
3744 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003753 }
3754
Brad Ebinger5f64b052017-12-14 14:26:15 -08003755 /**
3756 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3757 * specified.
3758 */
3759 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003768 }
3769
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003770 /**
3771 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3772 * specified.
3773 */
3774 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776
3777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003783 }
3784
Brad Ebinger884c07b2018-02-15 16:17:40 -08003785 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003786 * Sets the ImsService Package Name that Telephony will bind to.
3787 *
3788 * @param slotId the slot ID that the ImsService should bind for.
3789 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3790 * ImsService is the device default ImsService.
3791 * @param packageName The package name of the application that contains the ImsService to bind
3792 * to.
3793 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3794 * @hide
3795 */
3796 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003797 int[] subIds = SubscriptionManager.getSubId(slotId);
3798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3799 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3800 "setImsService");
3801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3805 isCarrierImsService, packageName);
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
3808 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003809 }
3810
3811 /**
3812 * Return the ImsService configuration.
3813 *
3814 * @param slotId The slot that the ImsService is associated with.
3815 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3816 * the device default.
3817 * @return the package name of the ImsService configuration.
3818 */
3819 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003820 int[] subIds = SubscriptionManager.getSubId(slotId);
3821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3822 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3823 "getImsService");
3824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3828 isCarrierImsService);
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003832 }
3833
Wink Saville36469e72014-06-11 15:17:00 -07003834 public void setImsRegistrationState(boolean registered) {
3835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836
3837 final long identity = Binder.clearCallingIdentity();
3838 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
Wink Saville36469e72014-06-11 15:17:00 -07003843 }
3844
3845 /**
Stuart Scott54788802015-03-30 13:18:01 -07003846 * Set the network selection mode to automatic.
3847 *
3848 */
3849 @Override
3850 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3852 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853
Pengquan Menge92a50d2018-09-21 15:54:48 -07003854 if (!isActiveSubscription(subId)) {
3855 return;
3856 }
3857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3861 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
3864 }
Stuart Scott54788802015-03-30 13:18:01 -07003865 }
3866
Pengquan Mengea84e042018-09-20 14:57:26 -07003867 /**
3868 * Ask the radio to connect to the input network and change selection mode to manual.
3869 *
3870 * @param subId the id of the subscription.
3871 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3872 * the operator to attach to.
3873 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3874 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3875 * normal network selection next time.
3876 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003877 */
3878 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003879 public boolean setNetworkSelectionModeManual(
3880 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3882 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003883
3884 if (!isActiveSubscription(subId)) {
3885 return false;
3886 }
3887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888 final long identity = Binder.clearCallingIdentity();
3889 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003890 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003892 if (DBG) {
3893 log("setNetworkSelectionModeManual: subId: " + subId
3894 + " operator: " + operatorInfo);
3895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003900 }
3901
3902 /**
3903 * Scans for available networks.
3904 */
3905 @Override
3906 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3908 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909
Pengquan Menga1bb6272018-09-06 09:59:22 -07003910 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911 try {
3912 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003913 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915 } finally {
3916 Binder.restoreCallingIdentity(identity);
3917 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003918 }
3919
3920 /**
yinxub1bed742017-04-17 11:45:04 -07003921 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003922 *
yinxub1bed742017-04-17 11:45:04 -07003923 * @param subId id of the subscription
3924 * @param request contains the radio access networks with bands/channels to scan
3925 * @param messenger callback messenger for scan results or errors
3926 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003927 * @return the id of the requested scan which can be used to stop the scan.
3928 */
3929 @Override
3930 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3931 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3933 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 return mNetworkScanRequestTracker.startNetworkScan(
3938 request, messenger, binder, getPhone(subId));
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
yinxu504e1392017-04-12 16:03:22 -07003942 }
3943
3944 /**
3945 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003946 *
3947 * @param subId id of the subscription
3948 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003949 */
3950 @Override
3951 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3953 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
3960 }
yinxu504e1392017-04-12 16:03:22 -07003961 }
3962
3963 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003964 * Get the calculated preferred network type.
3965 * Used for debugging incorrect network type.
3966 *
3967 * @return the preferred network type, defined in RILConstants.java.
3968 */
3969 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003970 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 final Phone defaultPhone = getDefaultPhone();
3972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3973 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003974 return RILConstants.PREFERRED_NETWORK_MODE;
3975 }
3976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003977 final long identity = Binder.clearCallingIdentity();
3978 try {
3979 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003980 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 } finally {
3982 Binder.restoreCallingIdentity(identity);
3983 }
Junda Liu84d15a22014-07-02 11:21:04 -07003984 }
3985
3986 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003987 * Get the preferred network type.
3988 * Used for device configuration by some CDMA operators.
3989 *
3990 * @return the preferred network type, defined in RILConstants.java.
3991 */
3992 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003993 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08003994 TelephonyPermissions
3995 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
3996 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997
3998 final long identity = Binder.clearCallingIdentity();
3999 try {
4000 if (DBG) log("getPreferredNetworkType");
4001 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4002 int networkType = (result != null ? result[0] : -1);
4003 if (DBG) log("getPreferredNetworkType: " + networkType);
4004 return networkType;
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004008 }
4009
4010 /**
4011 * Set the preferred network type.
4012 * Used for device configuration by some CDMA operators.
4013 *
4014 * @param networkType the preferred network type, defined in RILConstants.java.
4015 * @return true on success; false on any failure.
4016 */
4017 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004018 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4020 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4025 Boolean success = (Boolean) sendRequest(
4026 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4027 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4028 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004029 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4031 }
4032 return success;
4033 } finally {
4034 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004035 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004036 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004037
4038 /**
Junda Liu475951f2014-11-07 16:45:03 -08004039 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07004040 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004041 * tethering.
4042 *
4043 * @return 0: Not required. 1: required. 2: Not set.
4044 * @hide
4045 */
4046 @Override
4047 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004048 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049
4050 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004051 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004053 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004055 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004056 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 dunRequired = 1;
4058 }
4059 return dunRequired;
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004062 }
Junda Liu475951f2014-11-07 16:45:03 -08004063 }
4064
4065 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004066 * Set mobile data enabled
4067 * Used by the user through settings etc to turn on/off mobile data
4068 *
4069 * @param enable {@code true} turn turn data on, else {@code false}
4070 */
4071 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004072 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4074 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075
4076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 int phoneId = mSubscriptionController.getPhoneId(subId);
4079 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4080 Phone phone = PhoneFactory.getPhone(phoneId);
4081 if (phone != null) {
4082 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004083 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004085 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 }
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004089 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004090 }
4091
4092 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004093 * Get the user enabled state of Mobile Data.
4094 *
4095 * TODO: remove and use isUserDataEnabled.
4096 * This can't be removed now because some vendor codes
4097 * calls through ITelephony directly while they should
4098 * use TelephonyManager.
4099 *
4100 * @return true on enabled
4101 */
4102 @Override
4103 public boolean getDataEnabled(int subId) {
4104 return isUserDataEnabled(subId);
4105 }
4106
4107 /**
4108 * Get whether mobile data is enabled per user setting.
4109 *
4110 * There are other factors deciding whether mobile data is actually enabled, but they are
4111 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004112 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004113 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004114 *
4115 * @return {@code true} if data is enabled else {@code false}
4116 */
4117 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004118 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004119 try {
4120 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4121 null);
4122 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4124 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004126
4127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 int phoneId = mSubscriptionController.getPhoneId(subId);
4130 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4131 Phone phone = PhoneFactory.getPhone(phoneId);
4132 if (phone != null) {
4133 boolean retVal = phone.isUserDataEnabled();
4134 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4135 return retVal;
4136 } else {
4137 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4138 return false;
4139 }
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004142 }
4143 }
4144
4145 /**
4146 * Get whether mobile data is enabled.
4147 *
4148 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4149 * whether mobile data is actually enabled.
4150 *
4151 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4152 *
4153 * @return {@code true} if data is enabled else {@code false}
4154 */
4155 @Override
4156 public boolean isDataEnabled(int subId) {
4157 try {
4158 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4159 null);
4160 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4162 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004163 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164
4165 final long identity = Binder.clearCallingIdentity();
4166 try {
4167 int phoneId = mSubscriptionController.getPhoneId(subId);
4168 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4169 Phone phone = PhoneFactory.getPhone(phoneId);
4170 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004171 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4173 return retVal;
4174 } else {
4175 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4176 return false;
4177 }
4178 } finally {
4179 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004180 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004181 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004182
4183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004184 public int getCarrierPrivilegeStatus(int subId) {
4185 final Phone phone = getPhone(subId);
4186 if (phone == null) {
4187 loge("getCarrierPrivilegeStatus: Invalid subId");
4188 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4189 }
4190 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004191 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004192 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004193 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4194 }
4195 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004196 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004197 }
Junda Liu29340342014-07-10 15:23:27 -07004198
4199 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004200 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4201 final Phone phone = getPhone(subId);
4202 if (phone == null) {
4203 loge("getCarrierPrivilegeStatus: Invalid subId");
4204 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4205 }
4206 UiccProfile profile =
4207 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4208 if (profile == null) {
4209 loge("getCarrierPrivilegeStatus: No UICC");
4210 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4211 }
4212 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4213 }
4214
4215 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004216 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004217 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004218 if (TextUtils.isEmpty(pkgName))
4219 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004220 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004221 if (card == null) {
4222 loge("checkCarrierPrivilegesForPackage: No UICC");
4223 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4224 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004225 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4226 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004227 }
4228
4229 @Override
4230 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004231 if (TextUtils.isEmpty(pkgName))
4232 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004233 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4234 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4235 UiccCard card = UiccController.getInstance().getUiccCard(i);
4236 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004237 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004238 continue;
4239 }
4240
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004241 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004242 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4243 break;
4244 }
4245 }
4246
4247 return result;
Junda Liu29340342014-07-10 15:23:27 -07004248 }
Derek Tan89e89d42014-07-08 17:00:10 -07004249
4250 @Override
Junda Liue64de782015-04-16 17:19:16 -07004251 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4252 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4253 loge("phoneId " + phoneId + " is not valid.");
4254 return null;
4255 }
4256 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004257 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004258 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004259 return null ;
4260 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004261 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004262 }
4263
Amith Yamasani6e118872016-02-19 12:53:51 -08004264 @Override
4265 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004266 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004267 List<String> privilegedPackages = new ArrayList<>();
4268 List<PackageInfo> packages = null;
4269 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4270 UiccCard card = UiccController.getInstance().getUiccCard(i);
4271 if (card == null) {
4272 // No UICC in that slot.
4273 continue;
4274 }
4275 if (card.hasCarrierPrivilegeRules()) {
4276 if (packages == null) {
4277 // Only check packages in user 0 for now
4278 packages = pm.getInstalledPackagesAsUser(
4279 PackageManager.MATCH_DISABLED_COMPONENTS
4280 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4281 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4282 }
4283 for (int p = packages.size() - 1; p >= 0; p--) {
4284 PackageInfo pkgInfo = packages.get(p);
4285 if (pkgInfo != null && pkgInfo.packageName != null
4286 && card.getCarrierPrivilegeStatus(pkgInfo)
4287 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4288 privilegedPackages.add(pkgInfo.packageName);
4289 }
4290 }
4291 }
4292 }
4293 return privilegedPackages;
4294 }
4295
Wink Savilleb564aae2014-10-23 10:18:09 -07004296 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004297 final Phone phone = getPhone(subId);
4298 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004299 if (card == null) {
4300 loge("getIccId: No UICC");
4301 return null;
4302 }
4303 String iccId = card.getIccId();
4304 if (TextUtils.isEmpty(iccId)) {
4305 loge("getIccId: ICC ID is null or empty.");
4306 return null;
4307 }
4308 return iccId;
4309 }
4310
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004311 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004312 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4313 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004314 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4315 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 final long identity = Binder.clearCallingIdentity();
4318 try {
4319 final String iccId = getIccId(subId);
4320 final Phone phone = getPhone(subId);
4321 if (phone == null) {
4322 return false;
4323 }
4324 final String subscriberId = phone.getSubscriberId();
4325
4326 if (DBG_MERGE) {
4327 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4328 + subscriberId + " to " + number);
4329 }
4330
4331 if (TextUtils.isEmpty(iccId)) {
4332 return false;
4333 }
4334
4335 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4336
4337 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4338 if (alphaTag == null) {
4339 editor.remove(alphaTagPrefKey);
4340 } else {
4341 editor.putString(alphaTagPrefKey, alphaTag);
4342 }
4343
4344 // Record both the line number and IMSI for this ICCID, since we need to
4345 // track all merged IMSIs based on line number
4346 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4347 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4348 if (number == null) {
4349 editor.remove(numberPrefKey);
4350 editor.remove(subscriberPrefKey);
4351 } else {
4352 editor.putString(numberPrefKey, number);
4353 editor.putString(subscriberPrefKey, subscriberId);
4354 }
4355
4356 editor.commit();
4357 return true;
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004360 }
Derek Tan7226c842014-07-02 17:42:23 -07004361 }
4362
4363 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004364 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004365 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004367 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004368 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004369 return null;
4370 }
Derek Tan97ebb422014-09-05 16:55:38 -07004371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 String iccId = getIccId(subId);
4375 if (iccId != null) {
4376 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4377 if (DBG_MERGE) {
4378 log("getLine1NumberForDisplay returning "
4379 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4380 }
4381 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004382 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4384 return null;
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004387 }
Derek Tan7226c842014-07-02 17:42:23 -07004388 }
4389
4390 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004391 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004392 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004393 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004394 return null;
4395 }
Derek Tan97ebb422014-09-05 16:55:38 -07004396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 final long identity = Binder.clearCallingIdentity();
4398 try {
4399 String iccId = getIccId(subId);
4400 if (iccId != null) {
4401 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4402 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4403 }
4404 return null;
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004407 }
Derek Tan7226c842014-07-02 17:42:23 -07004408 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004409
4410 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004411 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004412 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4413 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004415 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4416 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004417 return null;
4418 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004419
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004420 final long identity = Binder.clearCallingIdentity();
4421 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004422 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423 final TelephonyManager tele = TelephonyManager.from(context);
4424 final SubscriptionManager sub = SubscriptionManager.from(context);
4425
4426 // Figure out what subscribers are currently active
4427 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4428 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4429 // the process, where TelephonyManager was instantiated.
4430 // Otherwise AppOps check will fail.
4431
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004432 final int[] subIds = sub.getActiveSubscriptionIdList();
4433 for (int subId : subIds) {
4434 activeSubscriberIds.add(tele.getSubscriberId(subId));
4435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436
4437 // First pass, find a number override for an active subscriber
4438 String mergeNumber = null;
4439 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4440 for (String key : prefs.keySet()) {
4441 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4442 final String subscriberId = (String) prefs.get(key);
4443 if (activeSubscriberIds.contains(subscriberId)) {
4444 final String iccId = key.substring(
4445 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4446 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4447 mergeNumber = (String) prefs.get(numberKey);
4448 if (DBG_MERGE) {
4449 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4450 + " for active subscriber " + subscriberId);
4451 }
4452 if (!TextUtils.isEmpty(mergeNumber)) {
4453 break;
4454 }
4455 }
4456 }
4457 }
4458
4459 // Shortcut when no active merged subscribers
4460 if (TextUtils.isEmpty(mergeNumber)) {
4461 return null;
4462 }
4463
4464 // Second pass, find all subscribers under that line override
4465 final ArraySet<String> result = new ArraySet<>();
4466 for (String key : prefs.keySet()) {
4467 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4468 final String number = (String) prefs.get(key);
4469 if (mergeNumber.equals(number)) {
4470 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4471 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4472 final String subscriberId = (String) prefs.get(subscriberKey);
4473 if (!TextUtils.isEmpty(subscriberId)) {
4474 result.add(subscriberId);
4475 }
4476 }
4477 }
4478 }
4479
4480 final String[] resultArray = result.toArray(new String[result.size()]);
4481 Arrays.sort(resultArray);
4482 if (DBG_MERGE) {
4483 Slog.d(LOG_TAG,
4484 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4485 }
4486 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004487 } finally {
4488 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004489 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004490 }
4491
4492 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004493 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004494 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4495 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496
4497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 final Phone phone = getPhone(subId);
4500 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004504 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004505
4506 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004507 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004508 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4509 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004510 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
4514 final Phone phone = getPhone(subId);
4515 if (phone == null) {
4516 return false;
4517 }
4518 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4519 cdmaNonRoamingList);
4520 } finally {
4521 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004522 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004523 }
4524
4525 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004526 @Deprecated
4527 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4528 enforceModifyPermission();
4529
4530 int returnValue = 0;
4531 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004532 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004533 if(result.exception == null) {
4534 if (result.result != null) {
4535 byte[] responseData = (byte[])(result.result);
4536 if(responseData.length > oemResp.length) {
4537 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4538 responseData.length + "bytes. Buffer Size is " +
4539 oemResp.length + "bytes.");
4540 }
4541 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4542 returnValue = responseData.length;
4543 }
4544 } else {
4545 CommandException ex = (CommandException) result.exception;
4546 returnValue = ex.getCommandError().ordinal();
4547 if(returnValue > 0) returnValue *= -1;
4548 }
4549 } catch (RuntimeException e) {
4550 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4551 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4552 if(returnValue > 0) returnValue *= -1;
4553 }
4554
4555 return returnValue;
4556 }
4557
4558 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004559 public void setRadioCapability(RadioAccessFamily[] rafs) {
4560 try {
4561 ProxyController.getInstance().setRadioCapability(rafs);
4562 } catch (RuntimeException e) {
4563 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4564 }
4565 }
4566
4567 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004568 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004569 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004570 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004571 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004572 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 final long identity = Binder.clearCallingIdentity();
4575 try {
chen xub97461a2018-10-26 14:17:57 -07004576 TelephonyPermissions
4577 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4578 mApp, phone.getSubId(), "getRadioAccessFamily");
4579 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
chen xub97461a2018-10-26 14:17:57 -07004583 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004584 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004585
4586 @Override
4587 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004588 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004593 ImsManager.getInstance(defaultPhone.getContext(),
4594 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004598 }
4599
4600 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004601 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004602 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004604 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004605 return false;
4606 }
Svet Ganovb320e182015-04-16 12:30:10 -07004607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 // Check the user preference and the system-level IMS setting. Even if the user has
4611 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4612 // In the long run, we may instead need to check if there exists a connection service
4613 // which can support video calling.
4614 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004615 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 return imsManager.isVtEnabledByPlatform()
4617 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4618 && imsManager.isVtEnabledByUser();
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004622 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004623
Andrew Leea1239f22015-03-02 17:44:07 -08004624 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4627 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4628 return false;
4629 }
4630
4631 final long identity = Binder.clearCallingIdentity();
4632 try {
4633 CarrierConfigManager configManager =
4634 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004635 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4637 } finally {
4638 Binder.restoreCallingIdentity(identity);
4639 }
Andrew Leea1239f22015-03-02 17:44:07 -08004640 }
4641
4642 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 public boolean isWorldPhone(int subId, String callingPackage) {
4644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4645 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4646 return false;
4647 }
4648
4649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 CarrierConfigManager configManager =
4652 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004653 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Andrew Leea1239f22015-03-02 17:44:07 -08004658 }
4659
Andrew Lee9431b832015-03-09 18:46:45 -07004660 @Override
4661 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004662 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004663 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004664 }
4665
4666 @Override
4667 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 final long identity = Binder.clearCallingIdentity();
4669 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004670 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671 } finally {
4672 Binder.restoreCallingIdentity(identity);
4673 }
Andrew Lee9431b832015-03-09 18:46:45 -07004674 }
4675
Hall Liuf6668912018-10-31 17:05:23 -07004676 /**
4677 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4678 * support for the feature and device firmware support.
4679 *
4680 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4681 */
4682 @Override
4683 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004685 final Phone phone = getPhone(subscriptionId);
4686 if (phone == null) {
4687 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4688 return false;
4689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004691 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4693 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004694 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 return isCarrierSupported && isDeviceSupported;
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
Hall Liu98187582018-01-22 19:15:32 -08004699 }
4700
Hall Liuf6668912018-10-31 17:05:23 -07004701 /**
4702 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4703 * both also support RTT.
4704 */
4705 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 final long identity = Binder.clearCallingIdentity();
4707 try {
Hall Liuf6668912018-10-31 17:05:23 -07004708 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004709 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004713 }
4714
Sanket Padawe7310cc72015-01-14 09:53:20 -08004715 /**
4716 * Returns the unique device ID of phone, for example, the IMEI for
4717 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4718 *
4719 * <p>Requires Permission:
4720 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4721 */
4722 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004723 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004724 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004725 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004726 return null;
4727 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004728 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004729 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4730 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004731 return null;
4732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733
4734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 return phone.getDeviceId();
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004740 }
4741
Ping Sunc67b7c22016-03-02 19:16:45 +08004742 /**
4743 * {@hide}
4744 * Returns the IMS Registration Status on a particular subid
4745 *
4746 * @param subId
4747 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004748 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004749 Phone phone = getPhone(subId);
4750 if (phone != null) {
4751 return phone.isImsRegistered();
4752 } else {
4753 return false;
4754 }
4755 }
4756
Santos Cordon7a1885b2015-02-03 11:15:19 -08004757 @Override
4758 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004765 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004766
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004767 /**
4768 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004769 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004770 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771 final long identity = Binder.clearCallingIdentity();
4772 try {
4773 Phone phone = getPhone(subId);
4774 if (phone != null) {
4775 return phone.isWifiCallingEnabled();
4776 } else {
4777 return false;
4778 }
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004781 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004782 }
4783
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004784 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004785 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004786 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004787 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004788 final long identity = Binder.clearCallingIdentity();
4789 try {
4790 Phone phone = getPhone(subId);
4791 if (phone != null) {
4792 return phone.isVideoEnabled();
4793 } else {
4794 return false;
4795 }
4796 } finally {
4797 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004798 }
4799 }
4800
4801 /**
4802 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4803 * defined in {@link ImsRegistrationImplBase}.
4804 */
4805 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806 final long identity = Binder.clearCallingIdentity();
4807 try {
4808 Phone phone = getPhone(subId);
4809 if (phone != null) {
4810 return phone.getImsRegistrationTech();
4811 } else {
4812 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4813 }
4814 } finally {
4815 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004816 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004817 }
4818
Stuart Scott8eef64f2015-04-08 15:13:54 -07004819 @Override
4820 public void factoryReset(int subId) {
4821 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004822 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4823 return;
4824 }
4825
Svet Ganovcc087f82015-05-12 20:35:54 -07004826 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004827
Svet Ganovcc087f82015-05-12 20:35:54 -07004828 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004829 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4830 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004831 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004832 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004833 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004834 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4835 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004836 }
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004839 }
4840 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004841
4842 @Override
4843 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004844 final long identity = Binder.clearCallingIdentity();
4845 try {
4846 // We query all subscriptions instead of just the active ones, because
4847 // this might be called early on in the provisioning flow when the
4848 // subscriptions potentially aren't active yet.
4849 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4850 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004851 return null;
4852 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 // This function may be called very early, say, from the setup wizard, at
4855 // which point we won't have a default subscription set. If that's the case
4856 // we just choose the first, which will be valid in "most cases".
4857 final int defaultSubId = getDefaultSubscription();
4858 SubscriptionInfo info = null;
4859 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4860 info = slist.get(0);
4861 } else {
4862 for (SubscriptionInfo item : slist) {
4863 if (item.getSubscriptionId() == defaultSubId) {
4864 info = item;
4865 break;
4866 }
4867 }
4868
4869 if (info == null) {
4870 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004871 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004872 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 // Try and fetch the locale from the carrier properties or from the SIM language
4875 // preferences (EF-PL and EF-LI)...
4876 final int mcc = info.getMcc();
4877 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4878 String simLanguage = null;
4879 if (defaultPhone != null) {
4880 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4881 if (localeFromDefaultSim != null) {
4882 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4883 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4884 return localeFromDefaultSim.toLanguageTag();
4885 } else {
4886 simLanguage = localeFromDefaultSim.getLanguage();
4887 }
4888 }
4889 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 // The SIM language preferences only store a language (e.g. fr = French), not an
4892 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4893 // the SIM and carrier preferences does not include a country we add the country
4894 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004895 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 if (mccLocale != null) {
4897 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4898 return mccLocale.toLanguageTag();
4899 }
4900
4901 if (DBG) log("No locale found - returning null");
4902 return null;
4903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004906 }
4907
4908 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004909 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004910 }
4911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 /**
4913 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4914 */
4915 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004916 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004917 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004918
Chenjie Yu1ba97252018-01-11 18:16:20 -08004919 private final ModemActivityInfo mLastModemActivityInfo =
4920 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4921
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004922 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004923 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4924 * representing the state of the modem.
4925 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004926 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4927 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004928 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004929 */
4930 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004931 public void requestModemActivityInfo(ResultReceiver result) {
4932 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004933 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934
4935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 ModemActivityInfo ret = null;
4938 synchronized (mLastModemActivityInfo) {
4939 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4940 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004941 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004942 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4944 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004945 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
4946 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 }
4948 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004949 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
4950 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 mLastModemActivityInfo.setIdleTimeMillis(
4952 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4953 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4954 mLastModemActivityInfo.setRxTimeMillis(
4955 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4956 mLastModemActivityInfo.setEnergyUsed(
4957 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4960 mLastModemActivityInfo.getSleepTimeMillis(),
4961 mLastModemActivityInfo.getIdleTimeMillis(),
4962 mLastModemActivityInfo.getTxTimeMillis(),
4963 mLastModemActivityInfo.getRxTimeMillis(),
4964 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 Bundle bundle = new Bundle();
4967 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4968 result.send(0, bundle);
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004971 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004972 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004973
Siddharth Rayb8114062018-06-17 15:02:38 -07004974 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4975 // less than total activity duration.
4976 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4977 if (info == null) {
4978 return false;
4979 }
4980 int activityDurationMs =
4981 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4982 int totalTxTimeMs = 0;
4983 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4984 totalTxTimeMs += info.getTxTimeMillis()[i];
4985 }
4986 return (info.isValid()
4987 && (info.getSleepTimeMillis() <= activityDurationMs)
4988 && (info.getIdleTimeMillis() <= activityDurationMs)
4989 && (info.getRxTimeMillis() <= activityDurationMs)
4990 && (totalTxTimeMs <= activityDurationMs));
4991 }
4992
Jack Yu85bd38a2015-11-09 11:34:32 -08004993 /**
4994 * {@hide}
4995 * Returns the service state information on specified subscription.
4996 */
4997 @Override
4998 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005000 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005001 return null;
5002 }
5003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 final long identity = Binder.clearCallingIdentity();
5005 try {
5006 final Phone phone = getPhone(subId);
5007 if (phone == null) {
5008 return null;
5009 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 return phone.getServiceState();
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005015 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005016
5017 /**
5018 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5019 *
5020 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5021 * voicemail ringtone.
5022 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5023 * PhoneAccount.
5024 */
5025 @Override
5026 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 final long identity = Binder.clearCallingIdentity();
5028 try {
5029 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5030 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005031 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005038 }
5039
5040 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005041 * Sets the per-account voicemail ringtone.
5042 *
5043 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5044 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5045 *
5046 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5047 * voicemail ringtone.
5048 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5049 * PhoneAccount.
5050 */
5051 @Override
5052 public void setVoicemailRingtoneUri(String callingPackage,
5053 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005054 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005055 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5056 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005057 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5059 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5060 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062
5063 final long identity = Binder.clearCallingIdentity();
5064 try {
5065 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5066 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005067 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 }
5069 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005072 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005073 }
5074
5075 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005076 * Returns whether vibration is set for voicemail notification in Phone settings.
5077 *
5078 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5079 * voicemail vibration setting.
5080 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5081 */
5082 @Override
5083 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084 final long identity = Binder.clearCallingIdentity();
5085 try {
5086 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5087 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005088 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
5094 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005095 }
5096
Youhan Wange64578a2016-05-02 15:32:42 -07005097 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005098 * Sets the per-account voicemail vibration.
5099 *
5100 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5101 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5102 *
5103 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5104 * voicemail vibration setting.
5105 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5106 * specific PhoneAccount.
5107 */
5108 @Override
5109 public void setVoicemailVibrationEnabled(String callingPackage,
5110 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005111 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005112 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5113 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005114 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5116 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5117 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005118 }
5119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 final long identity = Binder.clearCallingIdentity();
5121 try {
5122 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5123 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005124 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 }
5126 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005129 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005130 }
5131
5132 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005133 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5134 *
5135 * @throws SecurityException if the caller does not have the required permission
5136 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005137 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005138 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005139 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005140 }
5141
5142 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005143 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5144 * permission.
5145 *
5146 * @throws SecurityException if the caller does not have the required permission
5147 */
5148 private void enforceSendSmsPermission() {
5149 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5150 }
5151
5152 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005153 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005154 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005155 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005156 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005157 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005161 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 if (componentName == null) {
5163 throw new SecurityException(
5164 "Caller not current active visual voicemail package[null]");
5165 }
5166 String vvmPackage = componentName.getPackageName();
5167 if (!callingPackage.equals(vvmPackage)) {
5168 throw new SecurityException("Caller not current active visual voicemail package["
5169 + vvmPackage + "]");
5170 }
5171 } finally {
5172 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005173 }
5174 }
5175
5176 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005177 * Return the application ID for the app type.
5178 *
5179 * @param subId the subscription ID that this request applies to.
5180 * @param appType the uicc app type.
5181 * @return Application ID for specificied app type, or null if no uicc.
5182 */
5183 @Override
5184 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005185 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005186 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187
5188 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005189 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 if (phone == null) {
5191 return null;
5192 }
5193 String aid = null;
5194 try {
5195 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5196 .getApplicationByType(appType).getAid();
5197 } catch (Exception e) {
5198 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5199 }
5200 return aid;
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005203 }
Youhan Wange64578a2016-05-02 15:32:42 -07005204 }
5205
Youhan Wang4001d252016-05-11 10:29:41 -07005206 /**
5207 * Return the Electronic Serial Number.
5208 *
5209 * @param subId the subscription ID that this request applies to.
5210 * @return ESN or null if error.
5211 */
5212 @Override
5213 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005214 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005215 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216
5217 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005218 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 if (phone == null) {
5220 return null;
5221 }
5222 String esn = null;
5223 try {
5224 esn = phone.getEsn();
5225 } catch (Exception e) {
5226 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5227 }
5228 return esn;
5229 } finally {
5230 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005231 }
Youhan Wang4001d252016-05-11 10:29:41 -07005232 }
5233
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005234 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005235 * Return the Preferred Roaming List Version.
5236 *
5237 * @param subId the subscription ID that this request applies to.
5238 * @return PRLVersion or null if error.
5239 */
5240 @Override
5241 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005242 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005243 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244
5245 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005246 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 if (phone == null) {
5248 return null;
5249 }
5250 String cdmaPrlVersion = null;
5251 try {
5252 cdmaPrlVersion = phone.getCdmaPrlVersion();
5253 } catch (Exception e) {
5254 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5255 }
5256 return cdmaPrlVersion;
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005259 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005260 }
5261
5262 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005263 * Get snapshot of Telephony histograms
5264 * @return List of Telephony histograms
5265 * @hide
5266 */
5267 @Override
5268 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5270 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271
5272 final long identity = Binder.clearCallingIdentity();
5273 try {
5274 return RIL.getTelephonyRILTimingHistograms();
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005278 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005279
5280 /**
5281 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005282 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5283 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005284 * Require system privileges. In the future we may add this to carrier APIs.
5285 *
Michele Berionne482f8202018-11-27 18:57:59 -08005286 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005287 */
5288 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005289 @TelephonyManager.SetCarrierRestrictionResult
5290 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005291 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005292 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005293
Michele Berionne482f8202018-11-27 18:57:59 -08005294 if (carrierRestrictionRules == null) {
5295 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005296 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 final long identity = Binder.clearCallingIdentity();
5299 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005300 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005301 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005305 }
5306
5307 /**
5308 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005309 * Get the allowed carrier list and the excluded carrier list, including the priority between
5310 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005311 * Require system privileges. In the future we may add this to carrier APIs.
5312 *
Michele Berionne482f8202018-11-27 18:57:59 -08005313 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005314 */
5315 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005316 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005317 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319
5320 final long identity = Binder.clearCallingIdentity();
5321 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005322 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5323 if (response instanceof CarrierRestrictionRules) {
5324 return (CarrierRestrictionRules) response;
5325 }
5326 // Response is an Exception of some kind,
5327 // which is signalled to the user as a NULL retval
5328 return null;
5329 } catch (Exception e) {
5330 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5331 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005335 }
5336
fionaxu59545b42016-05-25 15:53:37 -07005337 /**
5338 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5339 * @param subId the subscription ID that this action applies to.
5340 * @param enabled control enable or disable metered apns.
5341 * {@hide}
5342 */
5343 @Override
5344 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5345 enforceModifyPermission();
5346 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347
5348 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005349 if (phone == null) {
5350 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5351 return;
5352 }
5353 try {
5354 phone.carrierActionSetMeteredApnsEnabled(enabled);
5355 } catch (Exception e) {
5356 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 } finally {
5358 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005359 }
5360 }
5361
5362 /**
5363 * Action set from carrier signalling broadcast receivers to enable/disable radio
5364 * @param subId the subscription ID that this action applies to.
5365 * @param enabled control enable or disable radio.
5366 * {@hide}
5367 */
5368 @Override
5369 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5370 enforceModifyPermission();
5371 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372
5373 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005374 if (phone == null) {
5375 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5376 return;
5377 }
5378 try {
5379 phone.carrierActionSetRadioEnabled(enabled);
5380 } catch (Exception e) {
5381 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 } finally {
5383 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005384 }
5385 }
5386
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005387 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005388 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5389 * network status based on which carrier apps could apply actions accordingly,
5390 * enable/disable default url handler for example.
5391 *
5392 * @param subId the subscription ID that this action applies to.
5393 * @param report control start/stop reporting the default network status.
5394 * {@hide}
5395 */
5396 @Override
5397 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5398 enforceModifyPermission();
5399 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400
5401 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005402 if (phone == null) {
5403 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5404 return;
5405 }
5406 try {
5407 phone.carrierActionReportDefaultNetworkStatus(report);
5408 } catch (Exception e) {
5409 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 } finally {
5411 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005412 }
5413 }
5414
5415 /**
fionaxud9622282017-07-17 17:51:30 -07005416 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5417 * @param subId the subscription ID that this action applies to.
5418 * {@hide}
5419 */
5420 @Override
5421 public void carrierActionResetAll(int subId) {
5422 enforceModifyPermission();
5423 final Phone phone = getPhone(subId);
5424 if (phone == null) {
5425 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5426 return;
5427 }
5428 try {
5429 phone.carrierActionResetAll();
5430 } catch (Exception e) {
5431 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5432 }
5433 }
5434
5435 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005436 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5437 * bug report is being generated.
5438 */
5439 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005440 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005441 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5442 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005443 writer.println("Permission Denial: can't dump Phone from pid="
5444 + Binder.getCallingPid()
5445 + ", uid=" + Binder.getCallingUid()
5446 + "without permission "
5447 + android.Manifest.permission.DUMP);
5448 return;
5449 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005450 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005451 }
Jack Yueb89b242016-06-22 13:27:47 -07005452
Brad Ebingerdac2f002018-04-03 15:17:52 -07005453 @Override
5454 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5455 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5456 throws RemoteException {
5457 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5458 }
5459
Jack Yueb89b242016-06-22 13:27:47 -07005460 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005461 * Get aggregated video call data usage since boot.
5462 *
5463 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5464 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005465 * {@hide}
5466 */
5467 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005468 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005469 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5470 null);
5471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 final long identity = Binder.clearCallingIdentity();
5473 try {
5474 // NetworkStatsService keeps tracking the active network interface and identity. It
5475 // records the delta with the corresponding network identity.
5476 // We just return the total video call data usage snapshot since boot.
5477 Phone phone = getPhone(subId);
5478 if (phone != null) {
5479 return phone.getVtDataUsage(perUidStats);
5480 }
5481 return null;
5482 } finally {
5483 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005484 }
Jack Yueb89b242016-06-22 13:27:47 -07005485 }
Jack Yu75ab2952016-07-08 14:29:33 -07005486
5487 /**
5488 * Policy control of data connection. Usually used when data limit is passed.
5489 * @param enabled True if enabling the data, otherwise disabling.
5490 * @param subId Subscription index
5491 * {@hide}
5492 */
5493 @Override
5494 public void setPolicyDataEnabled(boolean enabled, int subId) {
5495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496
5497 final long identity = Binder.clearCallingIdentity();
5498 try {
5499 Phone phone = getPhone(subId);
5500 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005501 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 }
5503 } finally {
5504 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005505 }
5506 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005507
5508 /**
5509 * Get Client request stats
5510 * @return List of Client Request Stats
5511 * @hide
5512 */
5513 @Override
5514 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005516 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005517 return null;
5518 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005519 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 if (phone != null) {
5524 return phone.getClientRequestStats();
5525 }
5526
5527 return null;
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005531 }
5532
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005533 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005534 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005535 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005536 }
Jack Yueb4124c2017-02-16 15:32:43 -08005537
5538 /**
Grace Chen70990072017-03-24 17:21:30 -07005539 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005540 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005541 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005542 * @param state State of SIM (power down, power up, pass through)
5543 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5544 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5545 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005546 *
5547 **/
5548 @Override
Grace Chen70990072017-03-24 17:21:30 -07005549 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005550 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005551 Phone phone = PhoneFactory.getPhone(slotIndex);
5552
vagdeviaf9a5b92018-08-15 16:01:53 -07005553 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005558 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 }
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005562 }
5563 }
Shuo Qiandd210312017-04-12 22:11:33 +00005564
Tyler Gunn65d45c22017-06-05 11:22:26 -07005565 private boolean isUssdApiAllowed(int subId) {
5566 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005567 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005568 if (configManager == null) {
5569 return false;
5570 }
5571 PersistableBundle pb = configManager.getConfigForSubId(subId);
5572 if (pb == null) {
5573 return false;
5574 }
5575 return pb.getBoolean(
5576 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5577 }
5578
Shuo Qiandd210312017-04-12 22:11:33 +00005579 /**
5580 * Check if phone is in emergency callback mode
5581 * @return true if phone is in emergency callback mode
5582 * @param subId sub id
5583 */
goneil9c5f4872017-12-05 14:07:56 -08005584 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005585 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005586 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005587 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588
5589 final long identity = Binder.clearCallingIdentity();
5590 try {
5591 if (phone != null) {
5592 return phone.isInEcm();
5593 } else {
5594 return false;
5595 }
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005598 }
5599 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005600
5601 /**
5602 * Get the current signal strength information for the given subscription.
5603 * Because this information is not updated when the device is in a low power state
5604 * it should not be relied-upon to be current.
5605 * @param subId Subscription index
5606 * @return the most recent cached signal strength info from the modem
5607 */
5608 @Override
5609 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 final long identity = Binder.clearCallingIdentity();
5611 try {
5612 Phone p = getPhone(subId);
5613 if (p == null) {
5614 return null;
5615 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 return p.getSignalStrength();
5618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005621 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005622
Pengquan Meng77b7f132018-08-22 14:49:57 -07005623 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005624 * Get the current modem radio state for the given slot.
5625 * @param slotIndex slot index.
5626 * @param callingPackage the name of the package making the call.
5627 * @return the current radio power state from the modem
5628 */
5629 @Override
5630 public int getRadioPowerState(int slotIndex, String callingPackage) {
5631 Phone phone = PhoneFactory.getPhone(slotIndex);
5632 if (phone != null) {
5633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5634 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5635 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5636 }
5637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 return phone.getRadioPowerState();
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
5644 }
5645 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5646 }
5647
5648 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005649 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5650 *
5651 * <p>Requires one of the following permissions:
5652 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5653 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5654 * privileges.
5655 *
5656 * @param subId subscription id
5657 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5658 * {@code false}.
5659 */
5660 @Override
5661 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005662 boolean isEnabled = false;
5663 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005664 try {
5665 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005666 null /* message */);
5667 Phone phone = getPhone(subId);
5668 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005669 } catch (Exception e) {
5670 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5671 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005675 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005676 }
5677
5678
5679 /**
5680 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5681 *
5682 * <p> Requires permission:
5683 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5684 * privileges.
5685 *
5686 * @param subId subscription id
5687 * @param isEnabled {@code true} means enable, {@code false} means disable.
5688 */
5689 @Override
5690 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005695
Pengquan Menga1bb6272018-09-06 09:59:22 -07005696 Phone phone = getPhone(subId);
5697 if (phone != null) {
5698 phone.setDataRoamingEnabled(isEnabled);
5699 }
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005702 }
5703 }
5704
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005705 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005706 public boolean isManualNetworkSelectionAllowed(int subId) {
5707 boolean isAllowed = true;
5708 final long identity = Binder.clearCallingIdentity();
5709 try {
5710 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5711 mApp, subId, "isManualNetworkSelectionAllowed");
5712 Phone phone = getPhone(subId);
5713 if (phone != null) {
5714 isAllowed = phone.isCspPlmnEnabled();
5715 }
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
5719 return isAllowed;
5720 }
5721
5722 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005723 public UiccCardInfo[] getUiccCardsInfo() {
5724 enforceReadPrivilegedPermission("getUiccCardsInfo");
5725
5726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5729 return cards.toArray(new UiccCardInfo[cards.size()]);
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
5733 }
5734
5735 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005736 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005737 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5742 if (slots == null) {
5743 Rlog.i(LOG_TAG, "slots is null.");
5744 return null;
5745 }
5746
5747 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5748 for (int i = 0; i < slots.length; i++) {
5749 UiccSlot slot = slots[i];
5750 if (slot == null) {
5751 continue;
5752 }
5753
5754 String cardId;
5755 UiccCard card = slot.getUiccCard();
5756 if (card != null) {
5757 cardId = card.getCardId();
5758 } else {
5759 cardId = slot.getIccId();
5760 }
5761
5762 int cardState = 0;
5763 switch (slot.getCardState()) {
5764 case CARDSTATE_ABSENT:
5765 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5766 break;
5767 case CARDSTATE_PRESENT:
5768 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5769 break;
5770 case CARDSTATE_ERROR:
5771 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5772 break;
5773 case CARDSTATE_RESTRICTED:
5774 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5775 break;
5776 default:
5777 break;
5778
5779 }
5780
5781 infos[i] = new UiccSlotInfo(
5782 slot.isActive(),
5783 slot.isEuicc(),
5784 cardId,
5785 cardState,
5786 slot.getPhoneId(),
5787 slot.isExtendedApduSupported());
5788 }
5789 return infos;
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005792 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005793 }
5794
5795 @Override
5796 public boolean switchSlots(int[] physicalSlots) {
5797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5802 } finally {
5803 Binder.restoreCallingIdentity(identity);
5804 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005805 }
Jack Yu4c988042018-02-27 15:30:01 -08005806
5807 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005808 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5810 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5811 return TelephonyManager.INVALID_CARD_ID;
5812 }
5813
5814 final long identity = Binder.clearCallingIdentity();
5815 try {
5816 return UiccController.getInstance().getCardIdForDefaultEuicc();
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
5819 }
5820 }
5821
5822 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005823 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5824 enforceModifyPermission();
5825 final Phone phone = getPhone(subId);
5826 if (phone == null) {
5827 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5828 return;
5829 }
5830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 phone.setRadioIndicationUpdateMode(filters, mode);
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
5836 }
Jack Yu4c988042018-02-27 15:30:01 -08005837 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005838
5839 /**
goneil47ffb6e2018-04-06 15:40:58 -07005840 * A test API to reload the UICC profile.
5841 *
5842 * <p>Requires that the calling app has permission
5843 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5844 * @hide
5845 */
5846 @Override
5847 public void refreshUiccProfile(int subId) {
5848 enforceModifyPermission();
5849
5850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 Phone phone = getPhone(subId);
5853 if (phone == null) {
5854 return;
5855 }
5856 UiccCard uiccCard = phone.getUiccCard();
5857 if (uiccCard == null) {
5858 return;
5859 }
5860 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5861 if (uiccProfile == null) {
5862 return;
5863 }
5864 uiccProfile.refresh();
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
5869
5870 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005871 * Returns false if the mobile data is disabled by default, otherwise return true.
5872 */
5873 private boolean getDefaultDataEnabled() {
5874 return "true".equalsIgnoreCase(
5875 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5876 }
5877
5878 /**
5879 * Returns true if the data roaming is enabled by default, i.e the system property
5880 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5881 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5882 */
5883 private boolean getDefaultDataRoamingEnabled(int subId) {
5884 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005885 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005886 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5887 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5888 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5889 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5890 return isDataRoamingEnabled;
5891 }
5892
5893 /**
5894 * Returns the default network type for the given {@code subId}, if the default network type is
5895 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5896 */
5897 private int getDefaultNetworkType(int subId) {
5898 return Integer.parseInt(
5899 TelephonyManager.getTelephonyProperty(
5900 mSubscriptionController.getPhoneId(subId),
5901 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5902 String.valueOf(Phone.PREFERRED_NT_MODE)));
5903 }
fionaxua13278b2018-03-21 00:08:13 -07005904
5905 @Override
5906 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5907 gid1, String gid2, String plmn, String spn) {
5908 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909
5910 final long identity = Binder.clearCallingIdentity();
5911 try {
5912 final Phone phone = getPhone(subId);
5913 if (phone == null) {
5914 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5915 return;
5916 }
5917 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005920 }
fionaxua13278b2018-03-21 00:08:13 -07005921 }
5922
5923 @Override
5924 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005925 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926
5927 final long identity = Binder.clearCallingIdentity();
5928 try {
5929 final Phone phone = getPhone(subId);
5930 if (phone == null) {
5931 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5932 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5933 }
5934 return phone.getCarrierIdListVersion();
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005937 }
fionaxua13278b2018-03-21 00:08:13 -07005938 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005939
5940 @Override
5941 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5943 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5944 return -1;
5945 }
5946
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
5953 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005954
5955 @Override
5956 public int getCdmaRoamingMode(int subId) {
5957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5958 mApp, subId, "getCdmaRoamingMode");
5959
5960 final long identity = Binder.clearCallingIdentity();
5961 try {
5962 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
5966 }
5967
5968 @Override
5969 public boolean setCdmaRoamingMode(int subId, int mode) {
5970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5971 mApp, subId, "setCdmaRoamingMode");
5972
5973 final long identity = Binder.clearCallingIdentity();
5974 try {
5975 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5976 } finally {
5977 Binder.restoreCallingIdentity(identity);
5978 }
5979 }
5980
5981 @Override
5982 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5984 mApp, subId, "setCdmaSubscriptionMode");
5985
5986 final long identity = Binder.clearCallingIdentity();
5987 try {
5988 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5989 } finally {
5990 Binder.restoreCallingIdentity(identity);
5991 }
5992 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005993
5994 private void ensureUserRunning(int userId) {
5995 if (!mUserManager.isUserRunning(userId)) {
5996 throw new IllegalStateException("User " + userId + " does not exist or not running");
5997 }
5998 }
5999
6000 /**
6001 * Returns a list of SMS apps on a given user.
6002 *
6003 * Only the shell user (UID 2000 or 0) can call it.
6004 * Target user must be running.
6005 */
6006 @Override
6007 public String[] getSmsApps(int userId) {
6008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6009 ensureUserRunning(userId);
6010
6011 final Collection<SmsApplicationData> apps =
6012 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6013
6014 String[] ret = new String[apps.size()];
6015 int i = 0;
6016 for (SmsApplicationData app : apps) {
6017 ret[i++] = app.mPackageName;
6018 }
6019 return ret;
6020 }
6021
6022 /**
6023 * Returns the default SMS app package name on a given user.
6024 *
6025 * Only the shell user (UID 2000 or 0) can call it.
6026 * Target user must be running.
6027 */
6028 @Override
6029 public String getDefaultSmsApp(int userId) {
6030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6031 ensureUserRunning(userId);
6032
6033 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6034 /* updateIfNeeded= */ true, userId);
6035 return cn == null ? null : cn.getPackageName();
6036 }
6037
6038 /**
6039 * Set a package as the default SMS app on a given user.
6040 *
6041 * Only the shell user (UID 2000 or 0) can call it.
6042 * Target user must be running.
6043 */
6044 @Override
6045 public void setDefaultSmsApp(int userId, String packageName) {
6046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6047 ensureUserRunning(userId);
6048
6049 boolean found = false;
6050 for (String pkg : getSmsApps(userId)) {
6051 if (TextUtils.equals(packageName, pkg)) {
6052 found = true;
6053 break;
6054 }
6055 }
6056 if (!found) {
6057 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6058 }
6059
6060 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6061 }
sqianc5eccab2018-10-19 18:46:41 -07006062
6063 @Override
6064 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6065 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6067 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6068 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6069 }
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
sqian854d44b2018-12-12 16:48:18 -08006072 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6073 for (Phone phone: PhoneFactory.getPhones()) {
6074 if (phone.getEmergencyNumberTracker() != null
6075 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6076 emergencyNumberListInternal.put(
6077 phone.getSubId(),
6078 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6079 }
sqian11b7a0e2018-12-05 18:48:28 -08006080 }
sqian854d44b2018-12-12 16:48:18 -08006081 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006082 } finally {
6083 Binder.restoreCallingIdentity(identity);
6084 }
sqianc5eccab2018-10-19 18:46:41 -07006085 }
6086
6087 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006088 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006089 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006090 if (!exactMatch) {
6091 TelephonyPermissions
6092 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006093 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006094 }
6095 final long identity = Binder.clearCallingIdentity();
6096 try {
sqian854d44b2018-12-12 16:48:18 -08006097 for (Phone phone: PhoneFactory.getPhones()) {
6098 if (phone.getEmergencyNumberTracker() != null
6099 && phone.getEmergencyNumberTracker() != null) {
6100 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6101 number, exactMatch)) {
6102 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006103 }
6104 }
sqian11b7a0e2018-12-05 18:48:28 -08006105 }
6106 return false;
6107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
6110 }
6111
sqianf4ca7ed2019-01-15 18:32:07 -08006112 /**
6113 * Update emergency number list for test mode.
6114 */
6115 @Override
6116 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6118 "updateEmergencyNumberListTestMode");
6119
6120 final long identity = Binder.clearCallingIdentity();
6121 try {
6122 for (Phone phone: PhoneFactory.getPhones()) {
6123 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6124 if (tracker != null) {
6125 tracker.executeEmergencyNumberTestModeCommand(action, num);
6126 }
6127 }
6128 } finally {
6129 Binder.restoreCallingIdentity(identity);
6130 }
6131 }
6132
6133 /**
6134 * Get the full emergency number list for test mode.
6135 */
6136 @Override
6137 public List<String> getEmergencyNumberListTestMode() {
6138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6139 "getEmergencyNumberListTestMode");
6140
6141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 Set<String> emergencyNumbers = new HashSet<>();
6144 for (Phone phone: PhoneFactory.getPhones()) {
6145 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6146 if (tracker != null) {
6147 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6148 emergencyNumbers.add(num.getNumber());
6149 }
6150 }
6151 }
6152 return new ArrayList<>(emergencyNumbers);
6153 } finally {
6154 Binder.restoreCallingIdentity(identity);
6155 }
6156 }
6157
chen xud6b45bd2018-10-30 22:27:10 -07006158 @Override
6159 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6160 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6161 Phone phone = getPhone(subId);
6162 if (phone == null) {
6163 return null;
6164 }
6165 final long identity = Binder.clearCallingIdentity();
6166 try {
6167 UiccProfile profile = UiccController.getInstance()
6168 .getUiccProfileForPhone(phone.getPhoneId());
6169 if (profile != null) {
6170 return profile.getCertsFromCarrierPrivilegeAccessRules();
6171 }
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 return null;
6176 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006177
6178 /**
6179 * Enable or disable a modem stack.
6180 */
6181 @Override
6182 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6183 enforceModifyPermission();
6184
6185 final long identity = Binder.clearCallingIdentity();
6186 try {
6187 Phone phone = PhoneFactory.getPhone(slotIndex);
6188 if (phone == null) {
6189 return false;
6190 } else {
6191 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6192 }
6193 } finally {
6194 Binder.restoreCallingIdentity(identity);
6195 }
6196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006197}