blob: ae27e675ef18642711fb7722772725860f444ff0 [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 Berionne0963c862018-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 Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-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 Ebinger4c460712018-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 Ebinger4c460712018-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 xu02581692018-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 Chenf144d942018-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;
sqian2fff4a32018-11-05 14:18:37 -0800129import 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;
Derek Tan740e1672017-06-27 14:56:27 -0700133import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.IccIoResult;
135import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800136import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700137import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800138import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000141import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700142import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800143import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700144import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800145import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700146import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700147import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700149import java.io.FileDescriptor;
150import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800154import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800155import java.util.HashMap;
Jake Hambye994d462014-02-03 13:10:13 -0800156import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100157import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159
160/**
161 * Implementation of the ITelephony interface.
162 */
Santos Cordon117fee72014-05-16 17:56:12 -0700163public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 private static final String LOG_TAG = "PhoneInterfaceManager";
165 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
166 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169 // Message codes used with mMainThreadHandler
170 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700171 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
172 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173 private static final int CMD_OPEN_CHANNEL = 9;
174 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
175 private static final int CMD_CLOSE_CHANNEL = 11;
176 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800177 private static final int CMD_NV_READ_ITEM = 13;
178 private static final int EVENT_NV_READ_ITEM_DONE = 14;
179 private static final int CMD_NV_WRITE_ITEM = 15;
180 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
181 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
182 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700183 private static final int CMD_RESET_MODEM_CONFIG = 19;
184 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800185 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
186 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
187 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
188 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800189 private static final int CMD_SEND_ENVELOPE = 25;
190 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000191 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
192 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700193 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
194 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
195 private static final int CMD_EXCHANGE_SIM_IO = 31;
196 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800197 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
198 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700199 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
200 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700201 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
202 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700203 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
204 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
205 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
206 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700207 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
208 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
209 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
210 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700211 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800212 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
213 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000214 private static final int CMD_SWITCH_SLOTS = 50;
215 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700216 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
217 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
218 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
219 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
220 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
221 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
222 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
223 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700224 private static final int CMD_GET_ALL_CELL_INFO = 60;
225 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
226 private static final int CMD_GET_CELL_LOCATION = 62;
227 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700228 private static final int CMD_MODEM_REBOOT = 64;
229 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700230 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
231 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800233 // Parameters of select command.
234 private static final int SELECT_COMMAND = 0xA4;
235 private static final int SELECT_P1 = 0x04;
236 private static final int SELECT_P2 = 0;
237 private static final int SELECT_P3 = 0x10;
238
Pengquan Meng85728fb2018-03-12 16:31:21 -0700239 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
240 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
241 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
242
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 /** The singleton instance. */
244 private static PhoneInterfaceManager sInstance;
245
Wink Saville3ab207e2014-11-20 13:07:20 -0800246 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800247 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700248 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private AppOpsManager mAppOps;
250 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800251 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700253 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
Derek Tan97ebb422014-09-05 16:55:38 -0700255 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
256 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700258
Derek Tan740e1672017-06-27 14:56:27 -0700259 // The AID of ISD-R.
260 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
261
yinxub1bed742017-04-17 11:45:04 -0700262 private NetworkScanRequestTracker mNetworkScanRequestTracker;
263
David Kelly5e06a7f2018-03-12 14:10:59 +0000264 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
265 private static final int MANUFACTURER_CODE_LENGTH = 8;
266
Derek Tan89e89d42014-07-08 17:00:10 -0700267 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700268 * A request object to use for transmitting data to an ICC.
269 */
270 private static final class IccAPDUArgument {
271 public int channel, cla, command, p1, p2, p3;
272 public String data;
273
274 public IccAPDUArgument(int channel, int cla, int command,
275 int p1, int p2, int p3, String data) {
276 this.channel = channel;
277 this.cla = cla;
278 this.command = command;
279 this.p1 = p1;
280 this.p2 = p2;
281 this.p3 = p3;
282 this.data = data;
283 }
284 }
285
286 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700287 * A request object to use for transmitting data to an ICC.
288 */
289 private static final class ManualNetworkSelectionArgument {
290 public OperatorInfo operatorInfo;
291 public boolean persistSelection;
292
293 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
294 this.operatorInfo = operatorInfo;
295 this.persistSelection = persistSelection;
296 }
297 }
298
299 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
301 * request after sending. The main thread will notify the request when it is complete.
302 */
303 private static final class MainThreadRequest {
304 /** The argument to use for the request */
305 public Object argument;
306 /** The result of the request that is run on the main thread */
307 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800308 // The subscriber id that this request applies to. Defaults to
309 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
310 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Nathan Harold92bed182018-10-12 18:16:49 -0700312 // In cases where subId is unavailable, the caller needs to specify the phone.
313 public Phone phone;
314
vagdevie435a3e2018-08-15 16:01:53 -0700315 public WorkSource workSource;
316
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317 public MainThreadRequest(Object argument) {
318 this.argument = argument;
319 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800320
Nathan Harold92bed182018-10-12 18:16:49 -0700321 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
322 this.argument = argument;
323 if (phone != null) {
324 this.phone = phone;
325 }
326 this.workSource = workSource;
327 }
328
vagdevie435a3e2018-08-15 16:01:53 -0700329 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800330 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800331 if (subId != null) {
332 this.subId = subId;
333 }
vagdevie435a3e2018-08-15 16:01:53 -0700334 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 }
337
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800338 private static final class IncomingThirdPartyCallArgs {
339 public final ComponentName component;
340 public final String callId;
341 public final String callerDisplayName;
342
343 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
344 String callerDisplayName) {
345 this.component = component;
346 this.callId = callId;
347 this.callerDisplayName = callerDisplayName;
348 }
349 }
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 /**
352 * A handler that processes messages on the main thread in the phone process. Since many
353 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
354 * inbound binder threads to the main thread in the phone process. The Binder thread
355 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
356 * on, which will be notified when the operation completes and will contain the result of the
357 * request.
358 *
359 * <p>If a MainThreadRequest object is provided in the msg.obj field,
360 * note that request.result must be set to something non-null for the calling thread to
361 * unblock.
362 */
363 private final class MainThreadHandler extends Handler {
364 @Override
365 public void handleMessage(Message msg) {
366 MainThreadRequest request;
367 Message onCompleted;
368 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800369 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700370 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800371 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
373 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700374 case CMD_HANDLE_USSD_REQUEST: {
375 request = (MainThreadRequest) msg.obj;
376 final Phone phone = getPhoneFromRequest(request);
377 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
378 String ussdRequest = ussdObject.first;
379 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700380
Pengquan Meng0c05b502018-09-06 09:59:22 -0700381 if (!isUssdApiAllowed(request.subId)) {
382 // Carrier does not support use of this API, return failure.
383 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
384 UssdResponse response = new UssdResponse(ussdRequest, null);
385 Bundle returnData = new Bundle();
386 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
387 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700388
Pengquan Meng0c05b502018-09-06 09:59:22 -0700389 request.result = true;
390 notifyRequester(request);
391 return;
392 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700393
Pengquan Meng0c05b502018-09-06 09:59:22 -0700394 try {
395 request.result = phone != null
396 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
397 } catch (CallStateException cse) {
398 request.result = false;
399 }
400 // Wake up the requesting thread
401 notifyRequester(request);
402 break;
pkanwar32d516d2016-10-14 19:37:38 -0700403 }
404
Yorke Lee716f67e2015-06-17 15:39:16 -0700405 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 final Phone phone = getPhoneFromRequest(request);
408 request.result = phone != null ?
409 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
410 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700412 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800419 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700420 if (uiccCard == null) {
421 loge("iccTransmitApduLogicalChannel: No UICC");
422 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700423 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
426 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 iccArgument.channel, iccArgument.cla, iccArgument.command,
429 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 break;
433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 ar = (AsyncResult) msg.obj;
436 request = (MainThreadRequest) ar.userObj;
437 if (ar.exception == null && ar.result != null) {
438 request.result = ar.result;
439 } else {
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
441 if (ar.result == null) {
442 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800443 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800445 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 } else {
447 loge("iccTransmitApduLogicalChannel: Unknown exception");
448 }
449 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700450 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
454 request = (MainThreadRequest) msg.obj;
455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduBasicChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700460 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 } else {
462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
463 request);
464 uiccCard.iccTransmitApduBasicChannel(
465 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
466 iccArgument.p3, iccArgument.data, onCompleted);
467 }
468 break;
469
470 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
471 ar = (AsyncResult) msg.obj;
472 request = (MainThreadRequest) ar.userObj;
473 if (ar.exception == null && ar.result != null) {
474 request.result = ar.result;
475 } else {
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
477 if (ar.result == null) {
478 loge("iccTransmitApduBasicChannel: Empty response");
479 } else if (ar.exception instanceof CommandException) {
480 loge("iccTransmitApduBasicChannel: CommandException: " +
481 ar.exception);
482 } else {
483 loge("iccTransmitApduBasicChannel: Unknown exception");
484 }
485 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 break;
488
489 case CMD_EXCHANGE_SIM_IO:
490 request = (MainThreadRequest) msg.obj;
491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 if (uiccCard == null) {
494 loge("iccExchangeSimIO: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 } else {
498 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
499 request);
500 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
501 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
502 iccArgument.data, onCompleted);
503 }
504 break;
505
506 case EVENT_EXCHANGE_SIM_IO_DONE:
507 ar = (AsyncResult) msg.obj;
508 request = (MainThreadRequest) ar.userObj;
509 if (ar.exception == null && ar.result != null) {
510 request.result = ar.result;
511 } else {
512 request.result = new IccIoResult(0x6f, 0, (byte[])null);
513 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 break;
516
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 case CMD_SEND_ENVELOPE:
518 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 if (uiccCard == null) {
521 loge("sendEnvelopeWithStatus: No UICC");
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700524 } else {
525 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
526 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
527 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 break;
529
530 case EVENT_SEND_ENVELOPE_DONE:
531 ar = (AsyncResult) msg.obj;
532 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700533 if (ar.exception == null && ar.result != null) {
534 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
537 if (ar.result == null) {
538 loge("sendEnvelopeWithStatus: Empty response");
539 } else if (ar.exception instanceof CommandException) {
540 loge("sendEnvelopeWithStatus: CommandException: " +
541 ar.exception);
542 } else {
543 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
544 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700546 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 break;
548
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 case CMD_OPEN_CHANNEL:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800552 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800555 request.result = new IccOpenLogicalChannelResponse(-1,
556 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 } else {
559 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800560 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
561 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
565 case EVENT_OPEN_CHANNEL_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 int[] result = (int[]) ar.result;
571 int channelId = result[0];
572 byte[] selectResponse = null;
573 if (result.length > 1) {
574 selectResponse = new byte[result.length - 1];
575 for (int i = 1; i < result.length; ++i) {
576 selectResponse[i - 1] = (byte) result[i];
577 }
578 }
579 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700580 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 if (ar.result == null) {
583 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 if (ar.exception != null) {
586 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
587 }
588
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700590 if (ar.exception instanceof CommandException) {
591 CommandException.Error error =
592 ((CommandException) (ar.exception)).getCommandError();
593 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700595 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 }
598 }
599 openChannelResp = new IccOpenLogicalChannelResponse(
600 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700602 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 break;
605
606 case CMD_CLOSE_CHANNEL:
607 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800608 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700609 if (uiccCard == null) {
610 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900611 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 } else {
614 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
615 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
616 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 break;
618
619 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800620 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
621 break;
622
623 case CMD_NV_READ_ITEM:
624 request = (MainThreadRequest) msg.obj;
625 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800626 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
627 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800628 break;
629
630 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800636 request.result = "";
637 if (ar.result == null) {
638 loge("nvReadItem: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("nvReadItem: CommandException: " +
641 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800643 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
645 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
Jake Hambye994d462014-02-03 13:10:13 -0800649 case CMD_NV_WRITE_ITEM:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
652 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800653 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700654 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800655 break;
656
657 case EVENT_NV_WRITE_ITEM_DONE:
658 handleNullReturnEvent(msg, "nvWriteItem");
659 break;
660
661 case CMD_NV_WRITE_CDMA_PRL:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800664 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
667 case EVENT_NV_WRITE_CDMA_PRL_DONE:
668 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
669 break;
670
chen xu1cc0abe2018-10-26 17:39:23 -0700671 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800672 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700673 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800674 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800675 break;
676
chen xu1cc0abe2018-10-26 17:39:23 -0700677 case EVENT_RESET_MODEM_CONFIG_DONE:
678 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800679 break;
680
Jake Hamby7c27be32014-03-03 13:25:59 -0800681 case CMD_GET_PREFERRED_NETWORK_TYPE:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700684 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800685 break;
686
687 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result; // Integer
692 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800693 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 if (ar.result == null) {
695 loge("getPreferredNetworkType: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("getPreferredNetworkType: CommandException: " +
698 ar.exception);
699 } else {
700 loge("getPreferredNetworkType: Unknown exception");
701 }
702 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700703 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case CMD_SET_PREFERRED_NETWORK_TYPE:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
709 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
714 handleNullReturnEvent(msg, "setPreferredNetworkType");
715 break;
716
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000717 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
718 request = (MainThreadRequest)msg.obj;
719 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800720 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
723 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
724 ar = (AsyncResult)msg.obj;
725 request = (MainThreadRequest)ar.userObj;
726 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700727 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000728 break;
729
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800730 case CMD_SET_VOICEMAIL_NUMBER:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
733 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800734 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
735 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 break;
737
738 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
739 handleNullReturnEvent(msg, "setVoicemailNumber");
740 break;
741
Stuart Scott54788802015-03-30 13:18:01 -0700742 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
745 request);
746 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
747 break;
748
749 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
750 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
751 break;
752
Shishir Agrawal302c8692015-06-19 13:49:39 -0700753 case CMD_PERFORM_NETWORK_SCAN:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
756 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
757 break;
758
759 case EVENT_PERFORM_NETWORK_SCAN_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 CellNetworkScanResult cellScanResult;
763 if (ar.exception == null && ar.result != null) {
764 cellScanResult = new CellNetworkScanResult(
765 CellNetworkScanResult.STATUS_SUCCESS,
766 (List<OperatorInfo>) ar.result);
767 } else {
768 if (ar.result == null) {
769 loge("getCellNetworkScanResults: Empty response");
770 }
771 if (ar.exception != null) {
772 loge("getCellNetworkScanResults: Exception: " + ar.exception);
773 }
774 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
775 if (ar.exception instanceof CommandException) {
776 CommandException.Error error =
777 ((CommandException) (ar.exception)).getCommandError();
778 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
779 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
780 } else if (error == CommandException.Error.GENERIC_FAILURE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
782 }
783 }
784 cellScanResult = new CellNetworkScanResult(errorCode, null);
785 }
786 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700787 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 break;
789
790 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
791 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700792 ManualNetworkSelectionArgument selArg =
793 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
795 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700796 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
797 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 break;
799
800 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 if (ar.exception == null) {
804 request.result = true;
805 } else {
806 request.result = false;
807 loge("setNetworkSelectionModeManual " + ar.exception);
808 }
809 notifyRequester(request);
810 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 break;
812
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700813 case CMD_GET_MODEM_ACTIVITY_INFO:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800816 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 break;
818
819 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 if (ar.result == null) {
826 loge("queryModemActivityInfo: Empty response");
827 } else if (ar.exception instanceof CommandException) {
828 loge("queryModemActivityInfo: CommandException: " +
829 ar.exception);
830 } else {
831 loge("queryModemActivityInfo: Unknown exception");
832 }
833 }
Amit Mahajand4766222016-01-28 15:28:28 -0800834 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
835 if (request.result == null) {
836 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
837 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700838 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 break;
840
Meng Wang1a7c35a2016-05-05 20:56:15 -0700841 case CMD_SET_ALLOWED_CARRIERS:
842 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800843 CarrierRestrictionRules argument =
844 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800846 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 break;
848
849 case EVENT_SET_ALLOWED_CARRIERS_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800855 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
856 if (ar.exception instanceof CommandException) {
857 loge("setAllowedCarriers: CommandException: " + ar.exception);
858 CommandException.Error error =
859 ((CommandException) (ar.exception)).getCommandError();
860 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
861 request.result =
862 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
863 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700864 } else {
865 loge("setAllowedCarriers: Unknown exception");
866 }
867 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700868 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 break;
870
871 case CMD_GET_ALLOWED_CARRIERS:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800874 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
877 case EVENT_GET_ALLOWED_CARRIERS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800883 request.result = new IllegalStateException(
884 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 if (ar.result == null) {
886 loge("getAllowedCarriers: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("getAllowedCarriers: CommandException: " +
889 ar.exception);
890 } else {
891 loge("getAllowedCarriers: Unknown exception");
892 }
893 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700894 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
Nathan Haroldb3014052017-01-25 15:57:32 -0800897 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
903 request.result = new IllegalArgumentException(
904 "Failed to retrieve Forbidden Plmns");
905 if (ar.result == null) {
906 loge("getForbiddenPlmns: Empty response");
907 } else {
908 loge("getForbiddenPlmns: Unknown exception");
909 }
910 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700911 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800912 break;
913
914 case CMD_GET_FORBIDDEN_PLMNS:
915 request = (MainThreadRequest) msg.obj;
916 uiccCard = getUiccCardFromRequest(request);
917 if (uiccCard == null) {
918 loge("getForbiddenPlmns() UiccCard is null");
919 request.result = new IllegalArgumentException(
920 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700921 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800922 break;
923 }
924 Integer appType = (Integer) request.argument;
925 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
926 if (uiccApp == null) {
927 loge("getForbiddenPlmns() no app with specified type -- "
928 + appType);
929 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700930 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 break;
932 } else {
933 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
934 + " specified type -- " + appType);
935 }
936 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
937 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
938 onCompleted);
939 break;
940
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000941 case CMD_SWITCH_SLOTS:
942 request = (MainThreadRequest) msg.obj;
943 int[] physicalSlots = (int[]) request.argument;
944 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
945 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
946 break;
947
948 case EVENT_SWITCH_SLOTS_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700952 notifyRequester(request);
953 break;
954 case CMD_GET_NETWORK_SELECTION_MODE:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
957 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
958 break;
959
960 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception != null) {
964 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
965 } else {
966 int mode = ((int[]) ar.result)[0];
967 if (mode == 0) {
968 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
969 } else {
970 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
971 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700973 notifyRequester(request);
974 break;
975 case CMD_GET_CDMA_ROAMING_MODE:
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
978 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
979 break;
980 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 if (ar.exception != null) {
984 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
985 } else {
986 request.result = ((int[]) ar.result)[0];
987 }
988 notifyRequester(request);
989 break;
990 case CMD_SET_CDMA_ROAMING_MODE:
991 request = (MainThreadRequest) msg.obj;
992 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
993 int mode = (int) request.argument;
994 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
995 break;
996 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = ar.exception == null;
1000 notifyRequester(request);
1001 break;
1002 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1005 int subscriptionMode = (int) request.argument;
1006 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1007 break;
1008 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 request.result = ar.exception == null;
1012 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001013 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001014 case CMD_GET_ALL_CELL_INFO:
1015 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001017 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 case EVENT_GET_ALL_CELL_INFO_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001022 // If a timeout occurs, the response will be null
1023 request.result = (ar.exception == null && ar.result != null)
1024 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001025 synchronized (request) {
1026 request.notifyAll();
1027 }
1028 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001029 case CMD_REQUEST_CELL_INFO_UPDATE:
1030 request = (MainThreadRequest) msg.obj;
1031 request.phone.requestCellInfoUpdate(request.workSource,
1032 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1033 break;
1034 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
1037 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1038 try {
1039 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001040 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001041 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1042 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001043 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001044 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001045 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001046 } else {
1047 // use the result as returned
1048 cb.onCellInfo((List<CellInfo>) ar.result);
1049 }
1050 } catch (RemoteException re) {
1051 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1052 }
1053 break;
1054 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 request = (MainThreadRequest) msg.obj;
1056 WorkSource ws = (WorkSource) request.argument;
1057 Phone phone = getPhoneFromRequest(request);
1058 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1059 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 if (ar.exception == null) {
1064 request.result = ar.result;
1065 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1068 ? new CdmaCellLocation() : new GsmCellLocation();
1069 }
1070
1071 synchronized (request) {
1072 request.notifyAll();
1073 }
1074 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001075 case CMD_MODEM_REBOOT:
1076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001078 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001079 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001080 case EVENT_CMD_MODEM_REBOOT_DONE:
1081 handleNullReturnEvent(msg, "rebootModem");
1082 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 default:
1084 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1085 break;
1086 }
1087 }
Jake Hambye994d462014-02-03 13:10:13 -08001088
Pengquan Meng0c05b502018-09-06 09:59:22 -07001089 private void notifyRequester(MainThreadRequest request) {
1090 synchronized (request) {
1091 request.notifyAll();
1092 }
1093 }
1094
Jake Hambye994d462014-02-03 13:10:13 -08001095 private void handleNullReturnEvent(Message msg, String command) {
1096 AsyncResult ar = (AsyncResult) msg.obj;
1097 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1098 if (ar.exception == null) {
1099 request.result = true;
1100 } else {
1101 request.result = false;
1102 if (ar.exception instanceof CommandException) {
1103 loge(command + ": CommandException: " + ar.exception);
1104 } else {
1105 loge(command + ": Unknown exception");
1106 }
1107 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001108 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 }
1111
1112 /**
1113 * Posts the specified command to be executed on the main thread,
1114 * waits for the request to complete, and returns the result.
1115 * @see #sendRequestAsync
1116 */
1117 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001118 return sendRequest(
1119 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001120 }
1121
1122 /**
1123 * Posts the specified command to be executed on the main thread,
1124 * waits for the request to complete, and returns the result.
1125 * @see #sendRequestAsync
1126 */
1127 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1128 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001129 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001130 }
1131
1132 /**
1133 * Posts the specified command to be executed on the main thread,
1134 * waits for the request to complete, and returns the result.
1135 * @see #sendRequestAsync
1136 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001137 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001138 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001139 }
1140
1141 /**
1142 * Posts the specified command to be executed on the main thread,
1143 * waits for the request to complete, and returns the result.
1144 * @see #sendRequestAsync
1145 */
Nathan Harold92bed182018-10-12 18:16:49 -07001146 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1147 return sendRequest(command, argument, subId, null, workSource);
1148 }
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 */
1155 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1156 return sendRequest(
1157 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1158 }
1159
1160 /**
1161 * Posts the specified command to be executed on the main thread,
1162 * waits for the request to complete, and returns the result.
1163 * @see #sendRequestAsync
1164 */
1165 private Object sendRequest(
1166 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1168 throw new RuntimeException("This method will deadlock if called from the main thread.");
1169 }
1170
Nathan Harold92bed182018-10-12 18:16:49 -07001171 MainThreadRequest request = null;
1172 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1173 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1174 } else if (phone != null) {
1175 request = new MainThreadRequest(argument, phone, workSource);
1176 } else {
1177 request = new MainThreadRequest(argument, subId, workSource);
1178 }
1179
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 Message msg = mMainThreadHandler.obtainMessage(command, request);
1181 msg.sendToTarget();
1182
1183 // Wait for the request to complete
1184 synchronized (request) {
1185 while (request.result == null) {
1186 try {
1187 request.wait();
1188 } catch (InterruptedException e) {
1189 // Do nothing, go back and wait until the request is complete
1190 }
1191 }
1192 }
1193 return request.result;
1194 }
1195
1196 /**
1197 * Asynchronous ("fire and forget") version of sendRequest():
1198 * Posts the specified command to be executed on the main thread, and
1199 * returns immediately.
1200 * @see #sendRequest
1201 */
1202 private void sendRequestAsync(int command) {
1203 mMainThreadHandler.sendEmptyMessage(command);
1204 }
1205
1206 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001207 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001208 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001209 */
1210 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001211 sendRequestAsync(command, argument, null, null);
1212 }
1213
1214 /**
1215 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1216 * @see {@link #sendRequest(int,Object)}
1217 */
1218 private void sendRequestAsync(
1219 int command, Object argument, Phone phone, WorkSource workSource) {
1220 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001221 Message msg = mMainThreadHandler.obtainMessage(command, request);
1222 msg.sendToTarget();
1223 }
1224
1225 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 * Initialize the singleton PhoneInterfaceManager instance.
1227 * This is only done once, at startup, from PhoneApp.onCreate().
1228 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001229 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 synchronized (PhoneInterfaceManager.class) {
1231 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001232 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 } else {
1234 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1235 }
1236 return sInstance;
1237 }
1238 }
1239
1240 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001241 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001244 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1246 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001247 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001248 mTelephonySharedPreferences =
1249 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001250 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001251 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 publish();
1254 }
1255
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001256 private Phone getDefaultPhone() {
1257 Phone thePhone = getPhone(getDefaultSubscription());
1258 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1259 }
1260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 private void publish() {
1262 if (DBG) log("publish: " + this);
1263
1264 ServiceManager.addService("phone", this);
1265 }
1266
Stuart Scott584921c2015-01-15 17:10:34 -08001267 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001268 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001269 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001270 }
1271
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001272 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1273 Phone phone = getPhoneFromRequest(request);
1274 return phone == null ? null :
1275 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1276 }
1277
Wink Saville36469e72014-06-11 15:17:00 -07001278 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001279 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001280 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282
1283 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001284 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001285 }
1286
Wink Savilleb564aae2014-10-23 10:18:09 -07001287 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 if (DBG) log("dial: " + number);
1289 // No permission check needed here: This is just a wrapper around the
1290 // ACTION_DIAL intent, which is available to any app since it puts up
1291 // the UI before it does anything.
1292
Malcolm Chend965c8b2018-02-28 15:00:40 -08001293 final long identity = Binder.clearCallingIdentity();
1294 try {
1295 String url = createTelUrl(number);
1296 if (url == null) {
1297 return;
1298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299
Malcolm Chend965c8b2018-02-28 15:00:40 -08001300 // PENDING: should we just silently fail if phone is offhook or ringing?
1301 PhoneConstants.State state = mCM.getState(subId);
1302 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1303 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1304 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1305 mApp.startActivity(intent);
1306 }
1307 } finally {
1308 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 }
1310 }
1311
1312 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001313 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Wink Savilleb564aae2014-10-23 10:18:09 -07001316 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 if (DBG) log("call: " + number);
1318
1319 // This is just a wrapper around the ACTION_CALL intent, but we still
1320 // need to do a permission check since we're calling startActivity()
1321 // from the context of the phone app.
1322 enforceCallPermission();
1323
1324 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1325 != AppOpsManager.MODE_ALLOWED) {
1326 return;
1327 }
1328
Malcolm Chend965c8b2018-02-28 15:00:40 -08001329 final long identity = Binder.clearCallingIdentity();
1330 try {
1331 String url = createTelUrl(number);
1332 if (url == null) {
1333 return;
1334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335
Malcolm Chend965c8b2018-02-28 15:00:40 -08001336 boolean isValid = false;
1337 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1338 if (slist != null) {
1339 for (SubscriptionInfo subInfoRecord : slist) {
1340 if (subInfoRecord.getSubscriptionId() == subId) {
1341 isValid = true;
1342 break;
1343 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001344 }
Wink Saville08874612014-08-31 19:19:58 -07001345 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001346 if (!isValid) {
1347 return;
1348 }
Wink Saville08874612014-08-31 19:19:58 -07001349
Malcolm Chend965c8b2018-02-28 15:00:40 -08001350 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1351 intent.putExtra(SUBSCRIPTION_KEY, subId);
1352 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1353 mApp.startActivity(intent);
1354 } finally {
1355 Binder.restoreCallingIdentity(identity);
1356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 }
1358
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Wink Savilleb564aae2014-10-23 10:18:09 -07001363 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001365 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1366 }
1367
1368 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001369 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001370 }
1371
Wink Savilleb564aae2014-10-23 10:18:09 -07001372 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001373 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001374 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1375 }
1376
1377 /** {@hide} */
1378 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001379 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001380 }
1381
Wink Savilleb564aae2014-10-23 10:18:09 -07001382 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001384
1385 final long identity = Binder.clearCallingIdentity();
1386 try {
1387 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1388 checkSimPin.start();
1389 return checkSimPin.unlockSim(null, pin);
1390 } finally {
1391 Binder.restoreCallingIdentity(identity);
1392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 }
1394
Wink Saville9de0f752013-10-22 19:04:03 -07001395 /** {@hide} */
1396 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001397 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001398 }
1399
Wink Savilleb564aae2014-10-23 10:18:09 -07001400 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001402
1403 final long identity = Binder.clearCallingIdentity();
1404 try {
1405 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1406 checkSimPuk.start();
1407 return checkSimPuk.unlockSim(puk, pin);
1408 } finally {
1409 Binder.restoreCallingIdentity(identity);
1410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 }
1412
1413 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001414 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 * a synchronous one.
1416 */
1417 private static class UnlockSim extends Thread {
1418
1419 private final IccCard mSimCard;
1420
1421 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001422 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1423 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424
1425 // For replies from SimCard interface
1426 private Handler mHandler;
1427
1428 // For async handler to identify request type
1429 private static final int SUPPLY_PIN_COMPLETE = 100;
1430
1431 public UnlockSim(IccCard simCard) {
1432 mSimCard = simCard;
1433 }
1434
1435 @Override
1436 public void run() {
1437 Looper.prepare();
1438 synchronized (UnlockSim.this) {
1439 mHandler = new Handler() {
1440 @Override
1441 public void handleMessage(Message msg) {
1442 AsyncResult ar = (AsyncResult) msg.obj;
1443 switch (msg.what) {
1444 case SUPPLY_PIN_COMPLETE:
1445 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1446 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001447 mRetryCount = msg.arg1;
1448 if (ar.exception != null) {
1449 if (ar.exception instanceof CommandException &&
1450 ((CommandException)(ar.exception)).getCommandError()
1451 == CommandException.Error.PASSWORD_INCORRECT) {
1452 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1453 } else {
1454 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1455 }
1456 } else {
1457 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 mDone = true;
1460 UnlockSim.this.notifyAll();
1461 }
1462 break;
1463 }
1464 }
1465 };
1466 UnlockSim.this.notifyAll();
1467 }
1468 Looper.loop();
1469 }
1470
1471 /*
1472 * Use PIN or PUK to unlock SIM card
1473 *
1474 * If PUK is null, unlock SIM card with PIN
1475 *
1476 * If PUK is not null, unlock SIM card with PUK and set PIN code
1477 */
Wink Saville9de0f752013-10-22 19:04:03 -07001478 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479
1480 while (mHandler == null) {
1481 try {
1482 wait();
1483 } catch (InterruptedException e) {
1484 Thread.currentThread().interrupt();
1485 }
1486 }
1487 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1488
1489 if (puk == null) {
1490 mSimCard.supplyPin(pin, callback);
1491 } else {
1492 mSimCard.supplyPuk(puk, pin, callback);
1493 }
1494
1495 while (!mDone) {
1496 try {
1497 Log.d(LOG_TAG, "wait for done");
1498 wait();
1499 } catch (InterruptedException e) {
1500 // Restore the interrupted status
1501 Thread.currentThread().interrupt();
1502 }
1503 }
1504 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001505 int[] resultArray = new int[2];
1506 resultArray[0] = mResult;
1507 resultArray[1] = mRetryCount;
1508 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 }
1510 }
1511
1512 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001513 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001514
1515 }
1516
Wink Savilleb564aae2014-10-23 10:18:09 -07001517 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001518 // No permission check needed here: this call is harmless, and it's
1519 // needed for the ServiceState.requestStateUpdate() call (which is
1520 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001521 final long identity = Binder.clearCallingIdentity();
1522 try {
1523 final Phone phone = getPhone(subId);
1524 if (phone != null) {
1525 phone.updateServiceLocation();
1526 }
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001532 @Override
1533 public boolean isRadioOn(String callingPackage) {
1534 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001535 }
1536
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001537 @Override
1538 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001540 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001541 return false;
1542 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001543
1544 final long identity = Binder.clearCallingIdentity();
1545 try {
1546 return isRadioOnForSubscriber(subId);
1547 } finally {
1548 Binder.restoreCallingIdentity(identity);
1549 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001550 }
1551
1552 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001553 final long identity = Binder.clearCallingIdentity();
1554 try {
1555 final Phone phone = getPhone(subId);
1556 if (phone != null) {
1557 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1558 } else {
1559 return false;
1560 }
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
1566 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001567 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 }
Wink Saville36469e72014-06-11 15:17:00 -07001569
Wink Savilleb564aae2014-10-23 10:18:09 -07001570 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001572
1573 final long identity = Binder.clearCallingIdentity();
1574 try {
1575 final Phone phone = getPhone(subId);
1576 if (phone != null) {
1577 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1578 }
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 }
Wink Saville36469e72014-06-11 15:17:00 -07001582 }
1583
1584 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001585 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001586 }
1587
Wink Savilleb564aae2014-10-23 10:18:09 -07001588 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001589 enforceModifyPermission();
Malcolm Chend965c8b2018-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 return false;
1596 }
1597 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1598 toggleRadioOnOffForSubscriber(subId);
1599 }
1600 return true;
1601 } finally {
1602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 }
Wink Saville36469e72014-06-11 15:17:00 -07001605
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001606 public boolean needMobileRadioShutdown() {
1607 /*
1608 * If any of the Radios are available, it will need to be
1609 * shutdown. So return true if any Radio is available.
1610 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001611 final long identity = Binder.clearCallingIdentity();
1612 try {
1613 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1614 Phone phone = PhoneFactory.getPhone(i);
1615 if (phone != null && phone.isRadioAvailable()) return true;
1616 }
1617 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1618 return false;
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001621 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001622 }
1623
Malcolm Chend965c8b2018-02-28 15:00:40 -08001624 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001625 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001626 enforceModifyPermission();
1627
1628 final long identity = Binder.clearCallingIdentity();
1629 try {
1630 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1631 logv("Shutting down Phone " + i);
1632 shutdownRadioUsingPhoneId(i);
1633 }
1634 } finally {
1635 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001636 }
1637 }
1638
1639 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001640 Phone phone = PhoneFactory.getPhone(phoneId);
1641 if (phone != null && phone.isRadioAvailable()) {
1642 phone.shutdownRadio();
1643 }
1644 }
1645
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001647 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001648
1649 final long identity = Binder.clearCallingIdentity();
1650 try {
1651 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1652 if (defaultPhone != null) {
1653 defaultPhone.setRadioPower(turnOn);
1654 return true;
1655 } else {
1656 loge("There's no default phone.");
1657 return false;
1658 }
1659 } finally {
1660 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001661 }
Wink Saville36469e72014-06-11 15:17:00 -07001662 }
1663
Wink Savilleb564aae2014-10-23 10:18:09 -07001664 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001666
1667 final long identity = Binder.clearCallingIdentity();
1668 try {
1669 final Phone phone = getPhone(subId);
1670 if (phone != null) {
1671 phone.setRadioPower(turnOn);
1672 return true;
1673 } else {
1674 return false;
1675 }
1676 } finally {
1677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680
Wink Saville36469e72014-06-11 15:17:00 -07001681 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 public boolean enableDataConnectivity() {
1684 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001685
1686 final long identity = Binder.clearCallingIdentity();
1687 try {
1688 int subId = mSubscriptionController.getDefaultDataSubId();
1689 final Phone phone = getPhone(subId);
1690 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001691 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001692 return true;
1693 } else {
1694 return false;
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Wink Saville36469e72014-06-11 15:17:00 -07001701 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 public boolean disableDataConnectivity() {
1704 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001705
1706 final long identity = Binder.clearCallingIdentity();
1707 try {
1708 int subId = mSubscriptionController.getDefaultDataSubId();
1709 final Phone phone = getPhone(subId);
1710 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001711 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001712 return true;
1713 } else {
1714 return false;
1715 }
1716 } finally {
1717 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 }
1720
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001722 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 final Phone phone = getPhone(subId);
1726 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001727 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001738 }
1739
pkanwarae03a6b2016-11-06 20:37:09 -08001740 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001741 enforceCallPermission();
1742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1746 return;
1747 }
1748 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1749 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1750 } finally {
1751 Binder.restoreCallingIdentity(identity);
1752 }
pkanwar32d516d2016-10-14 19:37:38 -07001753 };
1754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1761 return false;
1762 }
1763 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 }
1768
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001770 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001771 }
1772
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001773 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001774 final long identity = Binder.clearCallingIdentity();
1775 try {
1776 Phone phone = PhoneFactory.getPhone(slotIndex);
1777 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1778 PhoneConstantConversions.convertCallState(phone.getState());
1779 } finally {
1780 Binder.restoreCallingIdentity(identity);
1781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 }
1783
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001786 final long identity = Binder.clearCallingIdentity();
1787 try {
1788 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1789 if (phone != null) {
1790 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1791 } else {
1792 return PhoneConstantConversions.convertDataState(
1793 PhoneConstants.DataState.DISCONNECTED);
1794 }
1795 } finally {
1796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 }
1799
Sanket Padawe356d7632015-06-22 14:03:32 -07001800 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001802 final long identity = Binder.clearCallingIdentity();
1803 try {
1804 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1805 if (phone != null) {
1806 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1807 } else {
1808 return TelephonyManager.DATA_ACTIVITY_NONE;
1809 }
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
1815 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001816 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001817 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001818 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001819 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1820 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001821 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001824 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001825 final long identity = Binder.clearCallingIdentity();
1826 try {
1827 if (DBG_LOC) log("getCellLocation: is active user");
1828 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001829 int subId = mSubscriptionController.getDefaultDataSubId();
1830 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1831 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001832 return data;
1833 } finally {
1834 Binder.restoreCallingIdentity(identity);
1835 }
Svetoslav64fad262015-04-14 14:35:21 -07001836 }
1837
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001839 public String getNetworkCountryIsoForPhone(int phoneId) {
1840 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1841 // registered cell info, so return a NULL country instead.
1842 final long identity = Binder.clearCallingIdentity();
1843 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001844 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1845 // Get default phone in this case.
1846 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1847 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001848 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001849 // Todo: fix this when we can get the actual cellular network info when the device
1850 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001851 if (TelephonyManager.NETWORK_TYPE_IWLAN
1852 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1853 return "";
1854 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001855 Phone phone = PhoneFactory.getPhone(phoneId);
1856 if (phone != null) {
1857 ServiceStateTracker sst = phone.getServiceStateTracker();
1858 if (sst != null) {
1859 LocaleTracker lt = sst.getLocaleTracker();
1860 if (lt != null) {
1861 return lt.getCurrentCountry();
1862 }
1863 }
1864 }
1865 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001866 } finally {
1867 Binder.restoreCallingIdentity(identity);
1868 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001869 }
1870
1871 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001873 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001874 }
1875
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001877 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 mApp.enforceCallingOrSelfPermission(
1879 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001880
1881 final long identity = Binder.clearCallingIdentity();
1882 try {
1883 final Phone phone = getPhone(subId);
1884 if (phone != null) {
1885 phone.enableLocationUpdates();
1886 }
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
1892 @Override
1893 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001894 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001895 }
1896
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001898 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 mApp.enforceCallingOrSelfPermission(
1900 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001901
1902 final long identity = Binder.clearCallingIdentity();
1903 try {
1904 final Phone phone = getPhone(subId);
1905 if (phone != null) {
1906 phone.disableLocationUpdates();
1907 }
1908 } finally {
1909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
1912
Nathan Harold31d7ff32018-10-15 20:20:30 -07001913 /**
1914 * Returns the target SDK version number for a given package name.
1915 *
1916 * @return target SDK if the package is found or INT_MAX.
1917 */
1918 private int getTargetSdk(String packageName) {
1919 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001920 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1921 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001922 if (ai != null) return ai.targetSdkVersion;
1923 } catch (PackageManager.NameNotFoundException unexpected) {
1924 }
1925 return Integer.MAX_VALUE;
1926 }
1927
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 @Override
1929 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001930 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1931 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001932 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1933 throw new SecurityException(
1934 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1935 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001936
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1938 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1939 return null;
1940 }
Svetoslav64fad262015-04-14 14:35:21 -07001941
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001942 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943
Nathan Haroldf180aac2018-06-01 18:43:55 -07001944 List<CellInfo> info = getAllCellInfo(callingPackage);
1945 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946
Nathan Haroldf180aac2018-06-01 18:43:55 -07001947 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1948 for (CellInfo ci : info) {
1949 if (ci instanceof CellInfoGsm) {
1950 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1951 } else if (ci instanceof CellInfoWcdma) {
1952 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001955 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
1957
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001958 private List<CellInfo> getCachedCellInfo() {
1959 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1960 for (Phone phone : PhoneFactory.getPhones()) {
1961 List<CellInfo> info = phone.getAllCellInfo();
1962 if (info != null) cellInfos.addAll(info);
1963 }
1964 return cellInfos;
1965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966
1967 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001968 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001969 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001970 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001971 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001972 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001973 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001976 final int targetSdk = getTargetSdk(callingPackage);
1977 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1978 return getCachedCellInfo();
1979 }
1980
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001981 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001982 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001983 final long identity = Binder.clearCallingIdentity();
1984 try {
1985 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1986 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001987 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001988 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001989 if (info != null) cellInfos.addAll(info);
1990 }
1991 return cellInfos;
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995 }
1996
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001997 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001998 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1999 requestCellInfoUpdateInternal(
2000 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2001 }
2002
2003 @Override
2004 public void requestCellInfoUpdateWithWorkSource(
2005 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2006 enforceModifyPermission();
2007 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2008 }
2009
2010 private void requestCellInfoUpdateInternal(
2011 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002012 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002013 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002014 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2015 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002016 return;
2017 }
2018
2019 final Phone phone = getPhone(subId);
2020 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2021
2022 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2023 }
2024
2025 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002027 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002028 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002029
2030 final long identity = Binder.clearCallingIdentity();
2031 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002032 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002033 } finally {
2034 Binder.restoreCallingIdentity(identity);
2035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 }
2037
Shishir Agrawala9f32182016-04-12 12:00:16 -07002038 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002039 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002040 Phone phone = PhoneFactory.getPhone(slotIndex);
2041 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002042 return null;
2043 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002044 int subId = phone.getSubId();
2045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2046 mApp, subId, callingPackage, "getImeiForSlot")) {
2047 return null;
2048 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002049
2050 final long identity = Binder.clearCallingIdentity();
2051 try {
2052 return phone.getImei();
2053 } finally {
2054 Binder.restoreCallingIdentity(identity);
2055 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002056 }
2057
2058 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002059 public String getTypeAllocationCodeForSlot(int slotIndex) {
2060 Phone phone = PhoneFactory.getPhone(slotIndex);
2061 String tac = null;
2062 if (phone != null) {
2063 String imei = phone.getImei();
2064 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2065 }
2066 return tac;
2067 }
2068
2069 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002070 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002071 Phone phone = PhoneFactory.getPhone(slotIndex);
2072 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002073 return null;
2074 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002075
Jeff Davidson913390f2018-02-23 17:11:49 -08002076 int subId = phone.getSubId();
2077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2078 mApp, subId, callingPackage, "getMeidForSlot")) {
2079 return null;
2080 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 return phone.getMeid();
2085 } finally {
2086 Binder.restoreCallingIdentity(identity);
2087 }
Jack Yu2af8d712017-03-15 17:14:14 -07002088 }
2089
2090 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002091 public String getManufacturerCodeForSlot(int slotIndex) {
2092 Phone phone = PhoneFactory.getPhone(slotIndex);
2093 String manufacturerCode = null;
2094 if (phone != null) {
2095 String meid = phone.getMeid();
2096 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2097 }
2098 return manufacturerCode;
2099 }
2100
2101 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002102 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002103 Phone phone = PhoneFactory.getPhone(slotIndex);
2104 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002105 return null;
2106 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002107 int subId = phone.getSubId();
2108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2109 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2110 return null;
2111 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002112
2113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 return phone.getDeviceSvn();
2116 } finally {
2117 Binder.restoreCallingIdentity(identity);
2118 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002119 }
2120
fionaxu43304da2017-11-27 22:51:16 -08002121 @Override
2122 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002123 final long identity = Binder.clearCallingIdentity();
2124 try {
2125 final Phone phone = getPhone(subId);
2126 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2127 } finally {
2128 Binder.restoreCallingIdentity(identity);
2129 }
fionaxu43304da2017-11-27 22:51:16 -08002130 }
2131
2132 @Override
2133 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 final Phone phone = getPhone(subId);
2137 return phone == null ? null : phone.getCarrierName();
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
2140 }
fionaxu43304da2017-11-27 22:51:16 -08002141 }
2142
calvinpaneed9ae82018-11-01 19:43:06 +08002143 @Override
chen xuc93cc282018-11-04 17:17:00 -08002144 public int getSubscriptionPreciseCarrierId(int subId) {
2145 final long identity = Binder.clearCallingIdentity();
2146 try {
2147 final Phone phone = getPhone(subId);
2148 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2149 : phone.getPreciseCarrierId();
2150 } finally {
2151 Binder.restoreCallingIdentity(identity);
2152 }
2153 }
2154
2155 @Override
2156 public String getSubscriptionPreciseCarrierName(int subId) {
2157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 final Phone phone = getPhone(subId);
2160 return phone == null ? null : phone.getPreciseCarrierName();
2161 } finally {
2162 Binder.restoreCallingIdentity(identity);
2163 }
2164 }
2165
chen xu02581692018-11-11 19:03:44 -08002166 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002167 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2168 if (!isSubscriptionMccMnc) {
2169 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2170 }
chen xu02581692018-11-11 19:03:44 -08002171 final Phone phone = PhoneFactory.getPhone(slotIndex);
2172 if (phone == null) {
2173 return TelephonyManager.UNKNOWN_CARRIER_ID;
2174 }
2175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
2180 }
2181 }
2182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 //
2184 // Internal helper methods.
2185 //
2186
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002187 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2189 *
2190 * @throws SecurityException if the caller does not have the required permission
2191 */
2192 private void enforceModifyPermission() {
2193 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2194 }
2195
2196 /**
2197 * Make sure the caller has the CALL_PHONE permission.
2198 *
2199 * @throws SecurityException if the caller does not have the required permission
2200 */
2201 private void enforceCallPermission() {
2202 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2203 }
2204
Stuart Scott8eef64f2015-04-08 15:13:54 -07002205 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002206 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002207 "ConnectivityService");
2208 }
2209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 private String createTelUrl(String number) {
2211 if (TextUtils.isEmpty(number)) {
2212 return null;
2213 }
2214
Jake Hambye994d462014-02-03 13:10:13 -08002215 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217
Ihab Awadf9e92732013-12-05 18:02:52 -08002218 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2220 }
2221
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002222 private static void logv(String msg) {
2223 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2224 }
2225
Ihab Awadf9e92732013-12-05 18:02:52 -08002226 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2228 }
2229
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002232 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002233 }
2234
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002236 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002237 final long identity = Binder.clearCallingIdentity();
2238 try {
2239 final Phone phone = PhoneFactory.getPhone(slotIndex);
2240 if (phone == null) {
2241 return PhoneConstants.PHONE_TYPE_NONE;
2242 } else {
2243 return phone.getPhoneType();
2244 }
2245 } finally {
2246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 }
2249
2250 /**
2251 * Returns the CDMA ERI icon index to display
2252 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002253 @Override
2254 public int getCdmaEriIconIndex(String callingPackage) {
2255 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002256 }
2257
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002261 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 return -1;
2263 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002264
2265 final long identity = Binder.clearCallingIdentity();
2266 try {
2267 final Phone phone = getPhone(subId);
2268 if (phone != null) {
2269 return phone.getCdmaEriIconIndex();
2270 } else {
2271 return -1;
2272 }
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 }
2277
2278 /**
2279 * Returns the CDMA ERI icon mode,
2280 * 0 - ON
2281 * 1 - FLASHING
2282 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002283 @Override
2284 public int getCdmaEriIconMode(String callingPackage) {
2285 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002286 }
2287
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002289 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002291 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002292 return -1;
2293 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002294
2295 final long identity = Binder.clearCallingIdentity();
2296 try {
2297 final Phone phone = getPhone(subId);
2298 if (phone != null) {
2299 return phone.getCdmaEriIconMode();
2300 } else {
2301 return -1;
2302 }
2303 } finally {
2304 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
2308 /**
2309 * Returns the CDMA ERI text,
2310 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002311 @Override
2312 public String getCdmaEriText(String callingPackage) {
2313 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002314 }
2315
Sanket Padawe356d7632015-06-22 14:03:32 -07002316 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002319 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002320 return null;
2321 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002322
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 final Phone phone = getPhone(subId);
2326 if (phone != null) {
2327 return phone.getCdmaEriText();
2328 } else {
2329 return null;
2330 }
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335
2336 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002337 * Returns the CDMA MDN.
2338 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2342 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002347 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002348 return phone.getLine1Number();
2349 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002350 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002351 return null;
2352 }
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002355 }
2356 }
2357
2358 /**
2359 * Returns the CDMA MIN.
2360 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002362 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2364 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
2369 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2370 return phone.getCdmaMin();
2371 } else {
2372 return null;
2373 }
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002376 }
2377 }
2378
Hall Liud892bec2018-11-30 14:51:45 -08002379 @Override
2380 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2381 INumberVerificationCallback callback, String callingPackage) {
2382 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2383 != PERMISSION_GRANTED) {
2384 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2385 }
2386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2387
2388 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2389 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2390 throw new SecurityException("Calling package must be configured in the device config");
2391 }
2392
2393 if (range == null) {
2394 throw new NullPointerException("Range must be non-null");
2395 }
2396
2397 timeoutMillis = Math.min(timeoutMillis,
2398 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2399
2400 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2401 }
2402
Junda Liuca05d5d2014-08-14 22:36:34 -07002403 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 * Returns true if CDMA provisioning needs to run.
2405 */
2406 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002407 final long identity = Binder.clearCallingIdentity();
2408 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002409 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002410 } finally {
2411 Binder.restoreCallingIdentity(identity);
2412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 }
2414
2415 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002416 * Sets the voice mail number of a given subId.
2417 */
2418 @Override
2419 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002420 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002421
2422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2425 new Pair<String, String>(alphaTag, number), new Integer(subId));
2426 return success;
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
2429 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002430 }
2431
Ta-wei Yen87c49842016-05-13 21:19:52 -07002432 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002433 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002435 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002436 if (!TextUtils.equals(callingPackage, systemDialer)) {
2437 throw new SecurityException("caller must be system dialer");
2438 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002439
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2443 if (phoneAccountHandle == null) {
2444 return null;
2445 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002446 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002447 } finally {
2448 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002449 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002450 }
2451
2452 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002453 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002454 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002456 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002457 return null;
2458 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002459
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002460 final long identity = Binder.clearCallingIdentity();
2461 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002462 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002463 } finally {
2464 Binder.restoreCallingIdentity(identity);
2465 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002466 }
2467
2468 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002469 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2470 VisualVoicemailSmsFilterSettings settings) {
2471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002472
2473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002476 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002477 } finally {
2478 Binder.restoreCallingIdentity(identity);
2479 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002480 }
2481
2482 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002483 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002485
2486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002489 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002493 }
2494
2495 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002496 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2497 String callingPackage, int subId) {
2498 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002503 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002504 } finally {
2505 Binder.restoreCallingIdentity(identity);
2506 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002507 }
2508
2509 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002510 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002511 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002512
2513 final long identity = Binder.clearCallingIdentity();
2514 try {
2515 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002516 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002517 } finally {
2518 Binder.restoreCallingIdentity(identity);
2519 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002520 }
2521
2522 @Override
2523 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2524 String number, int port, String text, PendingIntent sentIntent) {
2525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002526 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002527 enforceSendSmsPermission();
2528 // Make the calls as the phone process.
2529 final long identity = Binder.clearCallingIdentity();
2530 try {
2531 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2532 if (port == 0) {
2533 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2534 sentIntent, null, false);
2535 } else {
2536 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2537 smsManager.sendDataMessageWithSelfPermissions(number, null,
2538 (short) port, data, sentIntent, null);
2539 }
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
2542 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002543 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002544 /**
fionaxu0152e512016-11-14 13:36:14 -08002545 * Sets the voice activation state of a given subId.
2546 */
2547 @Override
2548 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2550 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002551
2552 final long identity = Binder.clearCallingIdentity();
2553 try {
2554 final Phone phone = getPhone(subId);
2555 if (phone != null) {
2556 phone.setVoiceActivationState(activationState);
2557 } else {
2558 loge("setVoiceActivationState fails with invalid subId: " + subId);
2559 }
2560 } finally {
2561 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002562 }
2563 }
2564
2565 /**
2566 * Sets the data activation state of a given subId.
2567 */
2568 @Override
2569 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2571 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 final Phone phone = getPhone(subId);
2576 if (phone != null) {
2577 phone.setDataActivationState(activationState);
2578 } else {
2579 loge("setVoiceActivationState fails with invalid subId: " + subId);
2580 }
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002583 }
2584 }
2585
2586 /**
2587 * Returns the voice activation state of a given subId.
2588 */
2589 @Override
2590 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002591 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002592
fionaxu0152e512016-11-14 13:36:14 -08002593 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 if (phone != null) {
2597 return phone.getVoiceActivationState();
2598 } else {
2599 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2600 }
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002603 }
2604 }
2605
2606 /**
2607 * Returns the data activation state of a given subId.
2608 */
2609 @Override
2610 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002611 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002612
fionaxu0152e512016-11-14 13:36:14 -08002613 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 if (phone != null) {
2617 return phone.getDataActivationState();
2618 } else {
2619 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002623 }
2624 }
2625
2626 /**
Wink Saville36469e72014-06-11 15:17:00 -07002627 * Returns the unread count of voicemails for a subId
2628 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002630 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2632 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2633 return 0;
2634 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 final Phone phone = getPhone(subId);
2638 if (phone != null) {
2639 return phone.getVoiceMessageCount();
2640 } else {
2641 return 0;
2642 }
2643 } finally {
2644 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 }
2647
2648 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002649 * returns true, if the device is in a state where both voice and data
2650 * are supported simultaneously. This can change based on location or network condition.
2651 */
2652 @Override
2653 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone phone = getPhone(subId);
2657 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002661 }
2662
2663 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002664 * Send the dialer code if called from the current default dialer or the caller has
2665 * carrier privilege.
2666 * @param inputCode The dialer code to send
2667 */
2668 @Override
2669 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002670 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002671 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002672 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2673 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002674 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002675 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2676 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002677 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002678
2679 final long identity = Binder.clearCallingIdentity();
2680 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002681 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
fionaxu235cc5e2017-03-06 22:25:57 -08002685 }
2686
2687 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002688 * Returns the data network type.
2689 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 *
2691 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2692 */
2693 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002694 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 final Phone phone = getPhone(getDefaultSubscription());
2698 if (phone != null) {
2699 return phone.getServiceState().getDataNetworkType();
2700 } else {
2701 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2702 }
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002705 }
Wink Saville36469e72014-06-11 15:17:00 -07002706 }
2707
Pengquan Meng0c05b502018-09-06 09:59:22 -07002708 @Override
2709 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002710 if (!isActiveSubscription(subId)) {
2711 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2712 }
2713
Pengquan Meng0c05b502018-09-06 09:59:22 -07002714 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2715 }
2716
Brad Ebinger4c460712018-10-01 10:40:55 -07002717 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002718 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2719 throws RemoteException {
2720 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002721 final long token = Binder.clearCallingIdentity();
2722 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002724 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002725 .addRegistrationCallbackForSubscription(c, subId);
2726 } finally {
2727 Binder.restoreCallingIdentity(token);
2728 }
2729 }
2730
2731 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002732 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2733 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2735 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2736 }
2737 Binder.withCleanCallingIdentity(() -> {
2738 try {
2739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002740 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002741 .removeRegistrationCallbackForSubscription(c, subId);
2742 } catch (IllegalArgumentException e) {
2743 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2744 + "is inactive, ignoring unregister.");
2745 // If the subscription is no longer active, just return, since the callback
2746 // will already have been removed internally.
2747 }
2748 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002749 }
2750
2751 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002752 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2753 throws RemoteException {
2754 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2756 final long token = Binder.clearCallingIdentity();
2757 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002758 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002759 .addCapabilitiesCallbackForSubscription(c, subId);
2760 } finally {
2761 Binder.restoreCallingIdentity(token);
2762 }
2763 }
2764
2765 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002766 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2767 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002768
2769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2770 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2771 }
2772 Binder.withCleanCallingIdentity(() -> {
2773 try {
2774 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002775 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002776 .removeCapabilitiesCallbackForSubscription(c, subId);
2777 } catch (IllegalArgumentException e) {
2778 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2779 + "is inactive, ignoring unregister.");
2780 // If the subscription is no longer active, just return, since the callback
2781 // will already have been removed internally.
2782 }
2783 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002784 }
2785
2786 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002787 public boolean isCapable(int subId, int capability, int regTech) {
2788 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2790 final long token = Binder.clearCallingIdentity();
2791 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002792 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002793 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2794 } catch (ImsException e) {
2795 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2796 return false;
2797 } finally {
2798 Binder.restoreCallingIdentity(token);
2799 }
2800 }
2801
2802 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002803 public boolean isAvailable(int subId, int capability, int regTech) {
2804 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002805 final long token = Binder.clearCallingIdentity();
2806 try {
2807 Phone phone = getPhone(subId);
2808 if (phone == null) return false;
2809 return phone.isImsCapabilityAvailable(capability, regTech);
2810 } finally {
2811 Binder.restoreCallingIdentity(token);
2812 }
2813 }
2814
2815 @Override
2816 public boolean isAdvancedCallingSettingEnabled(int subId) {
2817 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2818 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2819 final long token = Binder.clearCallingIdentity();
2820 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002821 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002822 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2823 } finally {
2824 Binder.restoreCallingIdentity(token);
2825 }
2826 }
2827
2828 @Override
2829 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2831 "setAdvancedCallingSetting");
2832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002835 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002836 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
2839 }
2840 }
2841
2842 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002843 public boolean isVtSettingEnabled(int subId) {
2844 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002848 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002849 getSlotIndexOrException(subId)).isVtEnabledByUser();
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
2853 }
2854
2855 @Override
2856 public void setVtSetting(int subId, boolean isEnabled) {
2857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2858 "setVtSetting");
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002862 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002863 } finally {
2864 Binder.restoreCallingIdentity(identity);
2865 }
2866 }
2867
2868 @Override
2869 public boolean isVoWiFiSettingEnabled(int subId) {
2870 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002874 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002875 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2876 } finally {
2877 Binder.restoreCallingIdentity(identity);
2878 }
2879 }
2880
2881 @Override
2882 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2884 "setVoWiFiSetting");
2885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002888 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002889 } finally {
2890 Binder.restoreCallingIdentity(identity);
2891 }
2892 }
2893
2894 @Override
2895 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2896 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002900 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002901 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
2905 }
2906
2907 @Override
2908 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2910 "setVoWiFiRoamingSetting");
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002914 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002915 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
2918 }
2919 }
2920
2921 @Override
2922 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2924 "setVoWiFiNonPersistent");
2925 final long identity = Binder.clearCallingIdentity();
2926 try {
2927 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002928 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002929 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
2933 }
2934
2935 @Override
2936 public int getVoWiFiModeSetting(int subId) {
2937 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002941 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002942 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
2946 }
2947
2948 @Override
2949 public void setVoWiFiModeSetting(int subId, int mode) {
2950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2951 "setVoWiFiModeSetting");
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002955 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002956 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
2960 }
2961
2962 @Override
2963 public int getVoWiFiRoamingModeSetting(int subId) {
2964 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002968 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002969 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
2973 }
2974
2975 @Override
2976 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2978 "setVoWiFiRoamingModeSetting");
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002982 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002983 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
2987 }
2988
2989 @Override
2990 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2992 "setRttCapabilityEnabled");
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002996 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002997 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
3001 }
3002
3003 @Override
3004 public boolean isTtyOverVolteEnabled(int subId) {
3005 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003009 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003010 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003016 @Override
3017 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3018 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003022 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003023 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
3027 }
3028
3029 @Override
3030 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3031 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3032 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003033 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3034 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3035 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003036 try {
3037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003038 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003039 .removeProvisioningCallbackForSubscription(callback, subId);
3040 } catch (IllegalArgumentException e) {
3041 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3042 + "is inactive, ignoring unregister.");
3043 // If the subscription is no longer active, just return, since the callback will already
3044 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
3048 }
3049
3050 @Override
3051 public int getImsProvisioningInt(int subId, int key) {
3052 enforceReadPrivilegedPermission("getImsProvisioningInt");
3053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003056 return ImsManager.getInstance(mApp,
3057 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003058 } catch (ImsException e) {
3059 throw new IllegalArgumentException(e.getMessage());
3060 } finally {
3061 Binder.restoreCallingIdentity(identity);
3062 }
3063 }
3064
3065 @Override
3066 public String getImsProvisioningString(int subId, int key) {
3067 enforceReadPrivilegedPermission("getImsProvisioningString");
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003071 return ImsManager.getInstance(mApp,
3072 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003073 } catch (ImsException e) {
3074 throw new IllegalArgumentException(e.getMessage());
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3083 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003087 return ImsManager.getInstance(mApp,
3088 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003089 } catch (ImsException e) {
3090 throw new IllegalArgumentException(e.getMessage());
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
3094 }
3095
3096 @Override
3097 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3099 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003103 return ImsManager.getInstance(mApp,
3104 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003105 } catch (ImsException e) {
3106 throw new IllegalArgumentException(e.getMessage());
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
3110 }
3111
Brad Ebinger4c460712018-10-01 10:40:55 -07003112 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3113 int slotId = SubscriptionManager.getSlotIndex(subId);
3114 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3115 throw new IllegalArgumentException("Invalid Subscription Id.");
3116 }
3117 return slotId;
3118 }
3119
Wink Saville36469e72014-06-11 15:17:00 -07003120 /**
3121 * Returns the network type for a subId
3122 */
3123 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003124 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003126 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003127 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3128 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003129
Malcolm Chend965c8b2018-02-28 15:00:40 -08003130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 final Phone phone = getPhone(subId);
3133 if (phone != null) {
3134 return phone.getServiceState().getDataNetworkType();
3135 } else {
3136 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3137 }
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 }
3142
3143 /**
3144 * Returns the data network type
3145 */
3146 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003147 public int getDataNetworkType(String callingPackage) {
3148 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003149 }
3150
3151 /**
3152 * Returns the data network type for a subId
3153 */
3154 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003155 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003157 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003158 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3159 }
3160
Malcolm Chend965c8b2018-02-28 15:00:40 -08003161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 final Phone phone = getPhone(subId);
3164 if (phone != null) {
3165 return phone.getServiceState().getDataNetworkType();
3166 } else {
3167 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3168 }
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 }
3173
3174 /**
Wink Saville36469e72014-06-11 15:17:00 -07003175 * Returns the Voice network type for a subId
3176 */
3177 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003178 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003180 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003181 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3182 }
3183
Malcolm Chend965c8b2018-02-28 15:00:40 -08003184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 final Phone phone = getPhone(subId);
3187 if (phone != null) {
3188 return phone.getServiceState().getVoiceNetworkType();
3189 } else {
3190 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3191 }
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196
3197 /**
3198 * @return true if a ICC card is present
3199 */
3200 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003201 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003202 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3203 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003204 }
3205
3206 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003207 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003208 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003209 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003210 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 final Phone phone = PhoneFactory.getPhone(slotIndex);
3214 if (phone != null) {
3215 return phone.getIccCard().hasIccCard();
3216 } else {
3217 return false;
3218 }
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 }
3223
3224 /**
3225 * Return if the current radio is LTE on CDMA. This
3226 * is a tri-state return value as for a period of time
3227 * the mode may be unknown.
3228 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003229 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003230 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003231 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003233 @Override
3234 public int getLteOnCdmaMode(String callingPackage) {
3235 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003239 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003241 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003242 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3243 }
3244
Malcolm Chend965c8b2018-02-28 15:00:40 -08003245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 final Phone phone = getPhone(subId);
3248 if (phone == null) {
3249 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3250 } else {
3251 return phone.getLteOnCdmaMode();
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003255 }
Wink Saville36469e72014-06-11 15:17:00 -07003256 }
3257
Wink Saville36469e72014-06-11 15:17:00 -07003258 /**
3259 * {@hide}
3260 * Returns Default subId, 0 in the case of single standby.
3261 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003262 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003263 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003264 }
3265
Shishir Agrawala9f32182016-04-12 12:00:16 -07003266 private int getSlotForDefaultSubscription() {
3267 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3268 }
3269
Wink Savilleb564aae2014-10-23 10:18:09 -07003270 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003271 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003273
Pengquan Meng466e2482018-09-21 15:54:48 -07003274 private boolean isActiveSubscription(int subId) {
3275 return mSubscriptionController.isActiveSubId(subId);
3276 }
3277
Ihab Awadf2177b72013-11-25 13:33:23 -08003278 /**
3279 * @see android.telephony.TelephonyManager.WifiCallingChoices
3280 */
3281 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003282 final long identity = Binder.clearCallingIdentity();
3283 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003284 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003285 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3286 getWhenToMakeWifiCallsDefaultPreference());
3287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003290 }
3291
3292 /**
3293 * @see android.telephony.TelephonyManager.WifiCallingChoices
3294 */
3295 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003299 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003300 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003304 }
3305
Sailesh Nepald1e68152013-12-12 19:08:02 -08003306 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003307 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003308 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003309 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003310
Shishir Agrawal566b7612013-10-28 14:41:00 -07003311 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003312 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3313 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3315 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003317
Malcolm Chend965c8b2018-02-28 15:00:40 -08003318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 if (TextUtils.equals(ISDR_AID, aid)) {
3321 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003322 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3323 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003324 if (bestComponent == null
3325 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3326 loge("The calling package is not allowed to access ISD-R.");
3327 throw new SecurityException(
3328 "The calling package is not allowed to access ISD-R.");
3329 }
Derek Tan740e1672017-06-27 14:56:27 -07003330 }
Derek Tan740e1672017-06-27 14:56:27 -07003331
Malcolm Chend965c8b2018-02-28 15:00:40 -08003332 if (DBG) {
3333 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3334 }
3335 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3336 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3337 if (DBG) log("iccOpenLogicalChannel: " + response);
3338 return response;
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003342 }
3343
3344 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003345 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3347 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003348
Malcolm Chend965c8b2018-02-28 15:00:40 -08003349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3352 if (channel < 0) {
3353 return false;
3354 }
3355 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3356 if (DBG) log("iccCloseLogicalChannel: " + success);
3357 return success;
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003360 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003361 }
3362
3363 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003364 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003365 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3367 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003368
Malcolm Chend965c8b2018-02-28 15:00:40 -08003369 final long identity = Binder.clearCallingIdentity();
3370 try {
3371 if (DBG) {
3372 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3373 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3374 + p3 + " data=" + data);
3375 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003376
Malcolm Chend965c8b2018-02-28 15:00:40 -08003377 if (channel < 0) {
3378 return "";
3379 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003380
Malcolm Chend965c8b2018-02-28 15:00:40 -08003381 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3382 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3383 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003384
Malcolm Chend965c8b2018-02-28 15:00:40 -08003385 // Append the returned status code to the end of the response payload.
3386 String s = Integer.toHexString(
3387 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3388 if (response.payload != null) {
3389 s = IccUtils.bytesToHexString(response.payload) + s;
3390 }
3391 return s;
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003394 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003395 }
Jake Hambye994d462014-02-03 13:10:13 -08003396
Evan Charltonc66da362014-05-16 14:06:40 -07003397 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003398 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3399 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3401 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003403
Malcolm Chend965c8b2018-02-28 15:00:40 -08003404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3407 && TextUtils.equals(ISDR_AID, data)) {
3408 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003409 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3410 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003411 if (bestComponent == null
3412 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3413 loge("The calling package is not allowed to select ISD-R.");
3414 throw new SecurityException(
3415 "The calling package is not allowed to select ISD-R.");
3416 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003417 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003418
Malcolm Chend965c8b2018-02-28 15:00:40 -08003419 if (DBG) {
3420 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3421 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3422 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003423
Malcolm Chend965c8b2018-02-28 15:00:40 -08003424 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3425 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3426 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003427
Malcolm Chend965c8b2018-02-28 15:00:40 -08003428 // Append the returned status code to the end of the response payload.
3429 String s = Integer.toHexString(
3430 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3431 if (response.payload != null) {
3432 s = IccUtils.bytesToHexString(response.payload) + s;
3433 }
3434 return s;
3435 } finally {
3436 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003437 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003438 }
3439
3440 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003441 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003442 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3444 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003445
Malcolm Chend965c8b2018-02-28 15:00:40 -08003446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 if (DBG) {
3449 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3450 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3451 }
3452
3453 IccIoResult response =
3454 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3455 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3456 subId);
3457
3458 if (DBG) {
3459 log("Exchange SIM_IO [R]" + response);
3460 }
3461
3462 byte[] result = null;
3463 int length = 2;
3464 if (response.payload != null) {
3465 length = 2 + response.payload.length;
3466 result = new byte[length];
3467 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3468 } else {
3469 result = new byte[length];
3470 }
3471
3472 result[length - 1] = (byte) response.sw2;
3473 result[length - 2] = (byte) response.sw1;
3474 return result;
3475 } finally {
3476 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003477 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003478 }
3479
Nathan Haroldb3014052017-01-25 15:57:32 -08003480 /**
3481 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3482 * on a particular subscription
3483 */
sqianb6e41952018-03-12 14:54:01 -07003484 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3486 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3487 return null;
3488 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003489
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 if (appType != TelephonyManager.APPTYPE_USIM
3493 && appType != TelephonyManager.APPTYPE_SIM) {
3494 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3495 return null;
3496 }
3497 Object response = sendRequest(
3498 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3499 if (response instanceof String[]) {
3500 return (String[]) response;
3501 }
3502 // Response is an Exception of some kind,
3503 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003504 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003505 } finally {
3506 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003507 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003508 }
3509
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003510 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003511 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3513 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003514
Malcolm Chend965c8b2018-02-28 15:00:40 -08003515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3518 if (response.payload == null) {
3519 return "";
3520 }
Evan Charltonc66da362014-05-16 14:06:40 -07003521
Malcolm Chend965c8b2018-02-28 15:00:40 -08003522 // Append the returned status code to the end of the response payload.
3523 String s = Integer.toHexString(
3524 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3525 s = IccUtils.bytesToHexString(response.payload) + s;
3526 return s;
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Evan Charltonc66da362014-05-16 14:06:40 -07003530 }
3531
Jake Hambye994d462014-02-03 13:10:13 -08003532 /**
3533 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3534 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3535 *
3536 * @param itemID the ID of the item to read
3537 * @return the NV item as a String, or null on error.
3538 */
3539 @Override
3540 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003541 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3543 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003548 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003549 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3550 return value;
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Jake Hambye994d462014-02-03 13:10:13 -08003554 }
3555
3556 /**
3557 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3558 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3559 *
3560 * @param itemID the ID of the item to read
3561 * @param itemValue the value to write, as a String
3562 * @return true on success; false on any failure
3563 */
3564 @Override
3565 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003566 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3568 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3573 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003574 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003575 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3576 return success;
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
Jake Hambye994d462014-02-03 13:10:13 -08003580 }
3581
3582 /**
3583 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3584 * Used for device configuration by some CDMA operators.
3585 *
3586 * @param preferredRoamingList byte array containing the new PRL
3587 * @return true on success; false on any failure
3588 */
3589 @Override
3590 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3592 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003593
3594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3597 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3598 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3599 return success;
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
Jake Hambye994d462014-02-03 13:10:13 -08003603 }
3604
3605 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003606 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003607 * Used for device configuration by some CDMA operators.
3608 *
chen xu1cc0abe2018-10-26 17:39:23 -07003609 * @param slotIndex - device slot.
3610 *
Jake Hambye994d462014-02-03 13:10:13 -08003611 * @return true on success; false on any failure
3612 */
3613 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003614 public boolean resetModemConfig(int slotIndex) {
3615 Phone phone = PhoneFactory.getPhone(slotIndex);
3616 if (phone != null) {
3617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3618 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003619
chen xu1cc0abe2018-10-26 17:39:23 -07003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3623 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3624 return success;
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003628 }
chen xu1cc0abe2018-10-26 17:39:23 -07003629 return false;
3630 }
3631
3632 /**
3633 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3634 *
3635 * @param slotIndex - device slot.
3636 *
3637 * @return true on success; false on any failure
3638 */
3639 @Override
3640 public boolean rebootModem(int slotIndex) {
3641 Phone phone = PhoneFactory.getPhone(slotIndex);
3642 if (phone != null) {
3643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3644 mApp, phone.getSubId(), "rebootModem");
3645
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3649 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3650 return success;
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
3653 }
3654 }
3655 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003656 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003657
Svet Ganovb320e182015-04-16 12:30:10 -07003658 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003659 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003661 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003662 return new String[0];
3663 }
3664
Malcolm Chend965c8b2018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003667 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
Wink Saville36469e72014-06-11 15:17:00 -07003671 }
3672
Brad Ebinger51f743a2017-01-23 13:50:20 -08003673 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003674 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3675 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003676 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003677 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003678 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003679
3680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 PhoneFactory.getImsResolver().enableIms(slotId);
3683 } finally {
3684 Binder.restoreCallingIdentity(identity);
3685 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003686 }
3687
3688 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003689 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3690 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003691 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003692 public void disableIms(int slotId) {
3693 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003694
3695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 PhoneFactory.getImsResolver().disableIms(slotId);
3698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003701 }
3702
3703 /**
3704 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3705 * feature or {@link null} if the service is not available. If the feature is available, the
3706 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3707 */
3708 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003709 IImsServiceFeatureCallback callback) {
3710 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003711
3712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003718 }
3719
3720 /**
3721 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3722 * feature during emergency calling or {@link null} if the service is not available. If the
3723 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3724 * listener for feature updates.
3725 */
3726 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3727 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003728
3729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003735 }
3736
Brad Ebinger5f64b052017-12-14 14:26:15 -08003737 /**
3738 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3739 * specified.
3740 */
3741 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3742 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003750 }
3751
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003752 /**
3753 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3754 * specified.
3755 */
3756 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3757 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003758
3759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003765 }
3766
Brad Ebinger884c07b2018-02-15 16:17:40 -08003767 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003768 * Sets the ImsService Package Name that Telephony will bind to.
3769 *
3770 * @param slotId the slot ID that the ImsService should bind for.
3771 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3772 * ImsService is the device default ImsService.
3773 * @param packageName The package name of the application that contains the ImsService to bind
3774 * to.
3775 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3776 * @hide
3777 */
3778 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003779 int[] subIds = SubscriptionManager.getSubId(slotId);
3780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3781 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3782 "setImsService");
3783
Malcolm Chend965c8b2018-02-28 15:00:40 -08003784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3787 isCarrierImsService, packageName);
3788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003791 }
3792
3793 /**
3794 * Return the ImsService configuration.
3795 *
3796 * @param slotId The slot that the ImsService is associated with.
3797 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3798 * the device default.
3799 * @return the package name of the ImsService configuration.
3800 */
3801 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003802 int[] subIds = SubscriptionManager.getSubId(slotId);
3803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3804 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3805 "getImsService");
3806
Malcolm Chend965c8b2018-02-28 15:00:40 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3810 isCarrierImsService);
3811 } finally {
3812 Binder.restoreCallingIdentity(identity);
3813 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003814 }
3815
Wink Saville36469e72014-06-11 15:17:00 -07003816 public void setImsRegistrationState(boolean registered) {
3817 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003818
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003821 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
Wink Saville36469e72014-06-11 15:17:00 -07003825 }
3826
3827 /**
Stuart Scott54788802015-03-30 13:18:01 -07003828 * Set the network selection mode to automatic.
3829 *
3830 */
3831 @Override
3832 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3834 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003835
Pengquan Meng466e2482018-09-21 15:54:48 -07003836 if (!isActiveSubscription(subId)) {
3837 return;
3838 }
3839
Malcolm Chend965c8b2018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3843 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
Stuart Scott54788802015-03-30 13:18:01 -07003847 }
3848
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003849 /**
3850 * Ask the radio to connect to the input network and change selection mode to manual.
3851 *
3852 * @param subId the id of the subscription.
3853 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3854 * the operator to attach to.
3855 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3856 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3857 * normal network selection next time.
3858 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003859 */
3860 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003861 public boolean setNetworkSelectionModeManual(
3862 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3864 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003865
3866 if (!isActiveSubscription(subId)) {
3867 return false;
3868 }
3869
Malcolm Chend965c8b2018-02-28 15:00:40 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003872 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003874 if (DBG) {
3875 log("setNetworkSelectionModeManual: subId: " + subId
3876 + " operator: " + operatorInfo);
3877 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003878 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003882 }
3883
3884 /**
3885 * Scans for available networks.
3886 */
3887 @Override
3888 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3890 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003891
Pengquan Meng0c05b502018-09-06 09:59:22 -07003892 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003893 try {
3894 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003895 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003896 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003900 }
3901
3902 /**
yinxub1bed742017-04-17 11:45:04 -07003903 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003904 *
yinxub1bed742017-04-17 11:45:04 -07003905 * @param subId id of the subscription
3906 * @param request contains the radio access networks with bands/channels to scan
3907 * @param messenger callback messenger for scan results or errors
3908 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003909 * @return the id of the requested scan which can be used to stop the scan.
3910 */
3911 @Override
3912 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3913 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3915 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003916
3917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 return mNetworkScanRequestTracker.startNetworkScan(
3920 request, messenger, binder, getPhone(subId));
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
yinxu504e1392017-04-12 16:03:22 -07003924 }
3925
3926 /**
3927 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003928 *
3929 * @param subId id of the subscription
3930 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003931 */
3932 @Override
3933 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3935 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003936
3937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
3942 }
yinxu504e1392017-04-12 16:03:22 -07003943 }
3944
3945 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003946 * Get the calculated preferred network type.
3947 * Used for debugging incorrect network type.
3948 *
3949 * @return the preferred network type, defined in RILConstants.java.
3950 */
3951 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003952 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003953 final Phone defaultPhone = getDefaultPhone();
3954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3955 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003956 return RILConstants.PREFERRED_NETWORK_MODE;
3957 }
3958
Malcolm Chend965c8b2018-02-28 15:00:40 -08003959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003962 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
Junda Liu84d15a22014-07-02 11:21:04 -07003966 }
3967
3968 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003969 * Get the preferred network type.
3970 * Used for device configuration by some CDMA operators.
3971 *
3972 * @return the preferred network type, defined in RILConstants.java.
3973 */
3974 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003975 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3977 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003978
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 if (DBG) log("getPreferredNetworkType");
3982 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3983 int networkType = (result != null ? result[0] : -1);
3984 if (DBG) log("getPreferredNetworkType: " + networkType);
3985 return networkType;
3986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003989 }
3990
3991 /**
3992 * Set the preferred network type.
3993 * Used for device configuration by some CDMA operators.
3994 *
3995 * @param networkType the preferred network type, defined in RILConstants.java.
3996 * @return true on success; false on any failure.
3997 */
3998 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003999 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4001 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004002
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4006 Boolean success = (Boolean) sendRequest(
4007 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4008 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4009 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004010 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004011 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4012 }
4013 return success;
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004016 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004017 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004018
4019 /**
Junda Liu475951f2014-11-07 16:45:03 -08004020 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004021 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004022 * tethering.
4023 *
4024 * @return 0: Not required. 1: required. 2: Not set.
4025 * @hide
4026 */
4027 @Override
4028 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004029 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004030
4031 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004032 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004033 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004034 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004035 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004036 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004037 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004038 dunRequired = 1;
4039 }
4040 return dunRequired;
4041 } finally {
4042 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004043 }
Junda Liu475951f2014-11-07 16:45:03 -08004044 }
4045
4046 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004047 * Set mobile data enabled
4048 * Used by the user through settings etc to turn on/off mobile data
4049 *
4050 * @param enable {@code true} turn turn data on, else {@code false}
4051 */
4052 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004053 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4055 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004056
4057 final long identity = Binder.clearCallingIdentity();
4058 try {
4059 int phoneId = mSubscriptionController.getPhoneId(subId);
4060 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4061 Phone phone = PhoneFactory.getPhone(phoneId);
4062 if (phone != null) {
4063 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004064 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004065 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004066 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004067 }
4068 } finally {
4069 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004070 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004071 }
4072
4073 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004074 * Get the user enabled state of Mobile Data.
4075 *
4076 * TODO: remove and use isUserDataEnabled.
4077 * This can't be removed now because some vendor codes
4078 * calls through ITelephony directly while they should
4079 * use TelephonyManager.
4080 *
4081 * @return true on enabled
4082 */
4083 @Override
4084 public boolean getDataEnabled(int subId) {
4085 return isUserDataEnabled(subId);
4086 }
4087
4088 /**
4089 * Get whether mobile data is enabled per user setting.
4090 *
4091 * There are other factors deciding whether mobile data is actually enabled, but they are
4092 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004093 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004094 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004095 *
4096 * @return {@code true} if data is enabled else {@code false}
4097 */
4098 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004099 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004100 try {
4101 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4102 null);
4103 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4105 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004106 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004107
4108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 int phoneId = mSubscriptionController.getPhoneId(subId);
4111 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4112 Phone phone = PhoneFactory.getPhone(phoneId);
4113 if (phone != null) {
4114 boolean retVal = phone.isUserDataEnabled();
4115 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4116 return retVal;
4117 } else {
4118 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4119 return false;
4120 }
4121 } finally {
4122 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004123 }
4124 }
4125
4126 /**
4127 * Get whether mobile data is enabled.
4128 *
4129 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4130 * whether mobile data is actually enabled.
4131 *
4132 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4133 *
4134 * @return {@code true} if data is enabled else {@code false}
4135 */
4136 @Override
4137 public boolean isDataEnabled(int subId) {
4138 try {
4139 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4140 null);
4141 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4143 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004144 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004145
4146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 int phoneId = mSubscriptionController.getPhoneId(subId);
4149 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4150 Phone phone = PhoneFactory.getPhone(phoneId);
4151 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004152 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004153 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4154 return retVal;
4155 } else {
4156 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4157 return false;
4158 }
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004161 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004162 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004163
4164 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004165 public int getCarrierPrivilegeStatus(int subId) {
4166 final Phone phone = getPhone(subId);
4167 if (phone == null) {
4168 loge("getCarrierPrivilegeStatus: Invalid subId");
4169 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4170 }
4171 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004172 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004173 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4175 }
4176 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004177 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004178 }
Junda Liu29340342014-07-10 15:23:27 -07004179
4180 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004181 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4182 final Phone phone = getPhone(subId);
4183 if (phone == null) {
4184 loge("getCarrierPrivilegeStatus: Invalid subId");
4185 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4186 }
4187 UiccProfile profile =
4188 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4189 if (profile == null) {
4190 loge("getCarrierPrivilegeStatus: No UICC");
4191 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4192 }
4193 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4194 }
4195
4196 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004197 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004198 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004199 if (TextUtils.isEmpty(pkgName))
4200 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004201 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004202 if (card == null) {
4203 loge("checkCarrierPrivilegesForPackage: No UICC");
4204 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4205 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004206 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4207 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004208 }
4209
4210 @Override
4211 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004212 if (TextUtils.isEmpty(pkgName))
4213 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004214 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4215 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4216 UiccCard card = UiccController.getInstance().getUiccCard(i);
4217 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004218 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004219 continue;
4220 }
4221
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004222 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004223 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4224 break;
4225 }
4226 }
4227
4228 return result;
Junda Liu29340342014-07-10 15:23:27 -07004229 }
Derek Tan89e89d42014-07-08 17:00:10 -07004230
4231 @Override
Junda Liue64de782015-04-16 17:19:16 -07004232 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4233 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4234 loge("phoneId " + phoneId + " is not valid.");
4235 return null;
4236 }
4237 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004238 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004239 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004240 return null ;
4241 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004242 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004243 }
4244
Amith Yamasani6e118872016-02-19 12:53:51 -08004245 @Override
4246 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004247 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004248 List<String> privilegedPackages = new ArrayList<>();
4249 List<PackageInfo> packages = null;
4250 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4251 UiccCard card = UiccController.getInstance().getUiccCard(i);
4252 if (card == null) {
4253 // No UICC in that slot.
4254 continue;
4255 }
4256 if (card.hasCarrierPrivilegeRules()) {
4257 if (packages == null) {
4258 // Only check packages in user 0 for now
4259 packages = pm.getInstalledPackagesAsUser(
4260 PackageManager.MATCH_DISABLED_COMPONENTS
4261 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4262 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4263 }
4264 for (int p = packages.size() - 1; p >= 0; p--) {
4265 PackageInfo pkgInfo = packages.get(p);
4266 if (pkgInfo != null && pkgInfo.packageName != null
4267 && card.getCarrierPrivilegeStatus(pkgInfo)
4268 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4269 privilegedPackages.add(pkgInfo.packageName);
4270 }
4271 }
4272 }
4273 }
4274 return privilegedPackages;
4275 }
4276
Wink Savilleb564aae2014-10-23 10:18:09 -07004277 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004278 final Phone phone = getPhone(subId);
4279 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004280 if (card == null) {
4281 loge("getIccId: No UICC");
4282 return null;
4283 }
4284 String iccId = card.getIccId();
4285 if (TextUtils.isEmpty(iccId)) {
4286 loge("getIccId: ICC ID is null or empty.");
4287 return null;
4288 }
4289 return iccId;
4290 }
4291
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004292 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004293 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4294 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004295 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4296 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004297
Malcolm Chend965c8b2018-02-28 15:00:40 -08004298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 final String iccId = getIccId(subId);
4301 final Phone phone = getPhone(subId);
4302 if (phone == null) {
4303 return false;
4304 }
4305 final String subscriberId = phone.getSubscriberId();
4306
4307 if (DBG_MERGE) {
4308 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4309 + subscriberId + " to " + number);
4310 }
4311
4312 if (TextUtils.isEmpty(iccId)) {
4313 return false;
4314 }
4315
4316 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4317
4318 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4319 if (alphaTag == null) {
4320 editor.remove(alphaTagPrefKey);
4321 } else {
4322 editor.putString(alphaTagPrefKey, alphaTag);
4323 }
4324
4325 // Record both the line number and IMSI for this ICCID, since we need to
4326 // track all merged IMSIs based on line number
4327 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4328 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4329 if (number == null) {
4330 editor.remove(numberPrefKey);
4331 editor.remove(subscriberPrefKey);
4332 } else {
4333 editor.putString(numberPrefKey, number);
4334 editor.putString(subscriberPrefKey, subscriberId);
4335 }
4336
4337 editor.commit();
4338 return true;
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004341 }
Derek Tan7226c842014-07-02 17:42:23 -07004342 }
4343
4344 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004345 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004346 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004348 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004349 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004350 return null;
4351 }
Derek Tan97ebb422014-09-05 16:55:38 -07004352
Malcolm Chend965c8b2018-02-28 15:00:40 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 String iccId = getIccId(subId);
4356 if (iccId != null) {
4357 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4358 if (DBG_MERGE) {
4359 log("getLine1NumberForDisplay returning "
4360 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4361 }
4362 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004363 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004364 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4365 return null;
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004368 }
Derek Tan7226c842014-07-02 17:42:23 -07004369 }
4370
4371 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004372 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004374 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004375 return null;
4376 }
Derek Tan97ebb422014-09-05 16:55:38 -07004377
Malcolm Chend965c8b2018-02-28 15:00:40 -08004378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 String iccId = getIccId(subId);
4381 if (iccId != null) {
4382 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4383 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4384 }
4385 return null;
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004388 }
Derek Tan7226c842014-07-02 17:42:23 -07004389 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004390
4391 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004392 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004393 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4394 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004396 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4397 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004398 return null;
4399 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004400
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004403 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004404 final TelephonyManager tele = TelephonyManager.from(context);
4405 final SubscriptionManager sub = SubscriptionManager.from(context);
4406
4407 // Figure out what subscribers are currently active
4408 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4409 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4410 // the process, where TelephonyManager was instantiated.
4411 // Otherwise AppOps check will fail.
4412
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004413 final int[] subIds = sub.getActiveSubscriptionIdList();
4414 for (int subId : subIds) {
4415 activeSubscriberIds.add(tele.getSubscriberId(subId));
4416 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004417
4418 // First pass, find a number override for an active subscriber
4419 String mergeNumber = null;
4420 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4421 for (String key : prefs.keySet()) {
4422 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4423 final String subscriberId = (String) prefs.get(key);
4424 if (activeSubscriberIds.contains(subscriberId)) {
4425 final String iccId = key.substring(
4426 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4427 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4428 mergeNumber = (String) prefs.get(numberKey);
4429 if (DBG_MERGE) {
4430 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4431 + " for active subscriber " + subscriberId);
4432 }
4433 if (!TextUtils.isEmpty(mergeNumber)) {
4434 break;
4435 }
4436 }
4437 }
4438 }
4439
4440 // Shortcut when no active merged subscribers
4441 if (TextUtils.isEmpty(mergeNumber)) {
4442 return null;
4443 }
4444
4445 // Second pass, find all subscribers under that line override
4446 final ArraySet<String> result = new ArraySet<>();
4447 for (String key : prefs.keySet()) {
4448 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4449 final String number = (String) prefs.get(key);
4450 if (mergeNumber.equals(number)) {
4451 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4452 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4453 final String subscriberId = (String) prefs.get(subscriberKey);
4454 if (!TextUtils.isEmpty(subscriberId)) {
4455 result.add(subscriberId);
4456 }
4457 }
4458 }
4459 }
4460
4461 final String[] resultArray = result.toArray(new String[result.size()]);
4462 Arrays.sort(resultArray);
4463 if (DBG_MERGE) {
4464 Slog.d(LOG_TAG,
4465 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4466 }
4467 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004468 } finally {
4469 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004470 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004471 }
4472
4473 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004474 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4476 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004477
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 final Phone phone = getPhone(subId);
4481 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004485 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004486
4487 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004488 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004489 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4490 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004491 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004492
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
4495 final Phone phone = getPhone(subId);
4496 if (phone == null) {
4497 return false;
4498 }
4499 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4500 cdmaNonRoamingList);
4501 } finally {
4502 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004503 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004504 }
4505
4506 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004507 @Deprecated
4508 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4509 enforceModifyPermission();
4510
4511 int returnValue = 0;
4512 try {
vagdevie435a3e2018-08-15 16:01:53 -07004513 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004514 if(result.exception == null) {
4515 if (result.result != null) {
4516 byte[] responseData = (byte[])(result.result);
4517 if(responseData.length > oemResp.length) {
4518 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4519 responseData.length + "bytes. Buffer Size is " +
4520 oemResp.length + "bytes.");
4521 }
4522 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4523 returnValue = responseData.length;
4524 }
4525 } else {
4526 CommandException ex = (CommandException) result.exception;
4527 returnValue = ex.getCommandError().ordinal();
4528 if(returnValue > 0) returnValue *= -1;
4529 }
4530 } catch (RuntimeException e) {
4531 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4532 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4533 if(returnValue > 0) returnValue *= -1;
4534 }
4535
4536 return returnValue;
4537 }
4538
4539 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004540 public void setRadioCapability(RadioAccessFamily[] rafs) {
4541 try {
4542 ProxyController.getInstance().setRadioCapability(rafs);
4543 } catch (RuntimeException e) {
4544 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4545 }
4546 }
4547
4548 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004549 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004550 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004551 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004552 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004553 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004554 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004555 final long identity = Binder.clearCallingIdentity();
4556 try {
chen xufeeed752018-10-26 14:17:57 -07004557 TelephonyPermissions
4558 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4559 mApp, phone.getSubId(), "getRadioAccessFamily");
4560 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
chen xufeeed752018-10-26 14:17:57 -07004564 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004565 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004566
4567 @Override
4568 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004569 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004570 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004571
4572 final long identity = Binder.clearCallingIdentity();
4573 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004574 ImsManager.getInstance(defaultPhone.getContext(),
4575 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004579 }
4580
4581 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004582 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004583 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004585 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004586 return false;
4587 }
Svet Ganovb320e182015-04-16 12:30:10 -07004588
Malcolm Chend965c8b2018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
4590 try {
4591 // Check the user preference and the system-level IMS setting. Even if the user has
4592 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4593 // In the long run, we may instead need to check if there exists a connection service
4594 // which can support video calling.
4595 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004596 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004597 return imsManager.isVtEnabledByPlatform()
4598 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4599 && imsManager.isVtEnabledByUser();
4600 } finally {
4601 Binder.restoreCallingIdentity(identity);
4602 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004603 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004604
Andrew Leea1239f22015-03-02 17:44:07 -08004605 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004606 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4608 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4609 return false;
4610 }
4611
4612 final long identity = Binder.clearCallingIdentity();
4613 try {
4614 CarrierConfigManager configManager =
4615 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004616 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004617 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
Andrew Leea1239f22015-03-02 17:44:07 -08004621 }
4622
4623 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004624 public boolean isWorldPhone(int subId, String callingPackage) {
4625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4626 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4627 return false;
4628 }
4629
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 CarrierConfigManager configManager =
4633 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004634 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004635 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
Andrew Leea1239f22015-03-02 17:44:07 -08004639 }
4640
Andrew Lee9431b832015-03-09 18:46:45 -07004641 @Override
4642 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004643 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004644 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004645 }
4646
4647 @Override
4648 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004649 final long identity = Binder.clearCallingIdentity();
4650 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004651 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Andrew Lee9431b832015-03-09 18:46:45 -07004655 }
4656
Hall Liuf6668912018-10-31 17:05:23 -07004657 /**
4658 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4659 * support for the feature and device firmware support.
4660 *
4661 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4662 */
4663 @Override
4664 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004665 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004666 final Phone phone = getPhone(subscriptionId);
4667 if (phone == null) {
4668 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4669 return false;
4670 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004671 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004672 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004673 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4674 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004675 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004676 return isCarrierSupported && isDeviceSupported;
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
4679 }
Hall Liu98187582018-01-22 19:15:32 -08004680 }
4681
Hall Liuf6668912018-10-31 17:05:23 -07004682 /**
4683 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4684 * both also support RTT.
4685 */
4686 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004687 final long identity = Binder.clearCallingIdentity();
4688 try {
Hall Liuf6668912018-10-31 17:05:23 -07004689 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004690 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004694 }
4695
Sanket Padawe7310cc72015-01-14 09:53:20 -08004696 /**
4697 * Returns the unique device ID of phone, for example, the IMEI for
4698 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4699 *
4700 * <p>Requires Permission:
4701 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4702 */
4703 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004704 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004705 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004706 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004707 return null;
4708 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004709 int subId = phone.getSubId();
4710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4711 mApp, subId, callingPackage, "getDeviceId")) {
4712 return null;
4713 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004714
4715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 return phone.getDeviceId();
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004721 }
4722
Ping Sunc67b7c22016-03-02 19:16:45 +08004723 /**
4724 * {@hide}
4725 * Returns the IMS Registration Status on a particular subid
4726 *
4727 * @param subId
4728 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004729 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004730 Phone phone = getPhone(subId);
4731 if (phone != null) {
4732 return phone.isImsRegistered();
4733 } else {
4734 return false;
4735 }
4736 }
4737
Santos Cordon7a1885b2015-02-03 11:15:19 -08004738 @Override
4739 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004746 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004747
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004748 /**
4749 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004750 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004751 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004752 final long identity = Binder.clearCallingIdentity();
4753 try {
4754 Phone phone = getPhone(subId);
4755 if (phone != null) {
4756 return phone.isWifiCallingEnabled();
4757 } else {
4758 return false;
4759 }
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004762 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004763 }
4764
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004765 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004766 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004767 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004768 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 Phone phone = getPhone(subId);
4772 if (phone != null) {
4773 return phone.isVideoEnabled();
4774 } else {
4775 return false;
4776 }
4777 } finally {
4778 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004779 }
4780 }
4781
4782 /**
4783 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4784 * defined in {@link ImsRegistrationImplBase}.
4785 */
4786 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004787 final long identity = Binder.clearCallingIdentity();
4788 try {
4789 Phone phone = getPhone(subId);
4790 if (phone != null) {
4791 return phone.getImsRegistrationTech();
4792 } else {
4793 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4794 }
4795 } finally {
4796 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004797 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004798 }
4799
Stuart Scott8eef64f2015-04-08 15:13:54 -07004800 @Override
4801 public void factoryReset(int subId) {
4802 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004803 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4804 return;
4805 }
4806
Svet Ganovcc087f82015-05-12 20:35:54 -07004807 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004808
Svet Ganovcc087f82015-05-12 20:35:54 -07004809 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004810 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4811 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004812 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004813 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004814 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004815 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4816 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004817 }
4818 } finally {
4819 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004820 }
4821 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004822
4823 @Override
4824 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004825 final long identity = Binder.clearCallingIdentity();
4826 try {
4827 // We query all subscriptions instead of just the active ones, because
4828 // this might be called early on in the provisioning flow when the
4829 // subscriptions potentially aren't active yet.
4830 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4831 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004832 return null;
4833 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004834
Malcolm Chend965c8b2018-02-28 15:00:40 -08004835 // This function may be called very early, say, from the setup wizard, at
4836 // which point we won't have a default subscription set. If that's the case
4837 // we just choose the first, which will be valid in "most cases".
4838 final int defaultSubId = getDefaultSubscription();
4839 SubscriptionInfo info = null;
4840 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4841 info = slist.get(0);
4842 } else {
4843 for (SubscriptionInfo item : slist) {
4844 if (item.getSubscriptionId() == defaultSubId) {
4845 info = item;
4846 break;
4847 }
4848 }
4849
4850 if (info == null) {
4851 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004852 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004853 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004854
Malcolm Chend965c8b2018-02-28 15:00:40 -08004855 // Try and fetch the locale from the carrier properties or from the SIM language
4856 // preferences (EF-PL and EF-LI)...
4857 final int mcc = info.getMcc();
4858 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4859 String simLanguage = null;
4860 if (defaultPhone != null) {
4861 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4862 if (localeFromDefaultSim != null) {
4863 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4864 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4865 return localeFromDefaultSim.toLanguageTag();
4866 } else {
4867 simLanguage = localeFromDefaultSim.getLanguage();
4868 }
4869 }
4870 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004871
Malcolm Chend965c8b2018-02-28 15:00:40 -08004872 // The SIM language preferences only store a language (e.g. fr = French), not an
4873 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4874 // the SIM and carrier preferences does not include a country we add the country
4875 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004876 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004877 if (mccLocale != null) {
4878 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4879 return mccLocale.toLanguageTag();
4880 }
4881
4882 if (DBG) log("No locale found - returning null");
4883 return null;
4884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004887 }
4888
4889 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004890 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004891 }
4892
Malcolm Chend965c8b2018-02-28 15:00:40 -08004893 /**
4894 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4895 */
4896 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004897 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004898 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004899
Chenjie Yu1ba97252018-01-11 18:16:20 -08004900 private final ModemActivityInfo mLastModemActivityInfo =
4901 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4902
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004903 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004904 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4905 * representing the state of the modem.
4906 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004907 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4908 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004909 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004910 */
4911 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004912 public void requestModemActivityInfo(ResultReceiver result) {
4913 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004914 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004915
4916 final long identity = Binder.clearCallingIdentity();
4917 try {
4918 ModemActivityInfo ret = null;
4919 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004920 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4921 CMD_GET_MODEM_ACTIVITY_INFO,
4922 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004923 if (isModemActivityInfoValid(info)) {
4924 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4925 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4926 mergedTxTimeMs[i] =
4927 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4928 }
4929 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4930 mLastModemActivityInfo.setSleepTimeMillis(
4931 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4932 mLastModemActivityInfo.setIdleTimeMillis(
4933 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4934 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4935 mLastModemActivityInfo.setRxTimeMillis(
4936 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4937 mLastModemActivityInfo.setEnergyUsed(
4938 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004939 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004940 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4941 mLastModemActivityInfo.getSleepTimeMillis(),
4942 mLastModemActivityInfo.getIdleTimeMillis(),
4943 mLastModemActivityInfo.getTxTimeMillis(),
4944 mLastModemActivityInfo.getRxTimeMillis(),
4945 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004946 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004947 Bundle bundle = new Bundle();
4948 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4949 result.send(0, bundle);
4950 } finally {
4951 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004952 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004953 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004954
Siddharth Rayf5d29552018-06-17 15:02:38 -07004955 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4956 // less than total activity duration.
4957 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4958 if (info == null) {
4959 return false;
4960 }
4961 int activityDurationMs =
4962 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4963 int totalTxTimeMs = 0;
4964 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4965 totalTxTimeMs += info.getTxTimeMillis()[i];
4966 }
4967 return (info.isValid()
4968 && (info.getSleepTimeMillis() <= activityDurationMs)
4969 && (info.getIdleTimeMillis() <= activityDurationMs)
4970 && (info.getRxTimeMillis() <= activityDurationMs)
4971 && (totalTxTimeMs <= activityDurationMs));
4972 }
4973
Jack Yu85bd38a2015-11-09 11:34:32 -08004974 /**
4975 * {@hide}
4976 * Returns the service state information on specified subscription.
4977 */
4978 @Override
4979 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004981 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004982 return null;
4983 }
4984
Malcolm Chend965c8b2018-02-28 15:00:40 -08004985 final long identity = Binder.clearCallingIdentity();
4986 try {
4987 final Phone phone = getPhone(subId);
4988 if (phone == null) {
4989 return null;
4990 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004991
Malcolm Chend965c8b2018-02-28 15:00:40 -08004992 return phone.getServiceState();
4993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004996 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004997
4998 /**
4999 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5000 *
5001 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5002 * voicemail ringtone.
5003 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5004 * PhoneAccount.
5005 */
5006 @Override
5007 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005008 final long identity = Binder.clearCallingIdentity();
5009 try {
5010 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5011 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005012 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005013 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005014
Malcolm Chend965c8b2018-02-28 15:00:40 -08005015 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5016 } finally {
5017 Binder.restoreCallingIdentity(identity);
5018 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005019 }
5020
5021 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005022 * Sets the per-account voicemail ringtone.
5023 *
5024 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5025 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5026 *
5027 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5028 * voicemail ringtone.
5029 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5030 * PhoneAccount.
5031 */
5032 @Override
5033 public void setVoicemailRingtoneUri(String callingPackage,
5034 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005035 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5037 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005038 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5040 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5041 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005042 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005043
5044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5047 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005048 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005049 }
5050 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005053 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005054 }
5055
5056 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005057 * Returns whether vibration is set for voicemail notification in Phone settings.
5058 *
5059 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5060 * voicemail vibration setting.
5061 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5062 */
5063 @Override
5064 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5068 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005069 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005070 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005071
Malcolm Chend965c8b2018-02-28 15:00:40 -08005072 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
5075 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005076 }
5077
Youhan Wange64578a2016-05-02 15:32:42 -07005078 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005079 * Sets the per-account voicemail vibration.
5080 *
5081 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5082 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5083 *
5084 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5085 * voicemail vibration setting.
5086 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5087 * specific PhoneAccount.
5088 */
5089 @Override
5090 public void setVoicemailVibrationEnabled(String callingPackage,
5091 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005092 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005093 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5094 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005095 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5097 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5098 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005099 }
5100
Malcolm Chend965c8b2018-02-28 15:00:40 -08005101 final long identity = Binder.clearCallingIdentity();
5102 try {
5103 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5104 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005105 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005106 }
5107 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5108 } finally {
5109 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005110 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005111 }
5112
5113 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005114 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5115 *
5116 * @throws SecurityException if the caller does not have the required permission
5117 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005118 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005119 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005120 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005121 }
5122
5123 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005124 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5125 * permission.
5126 *
5127 * @throws SecurityException if the caller does not have the required permission
5128 */
5129 private void enforceSendSmsPermission() {
5130 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5131 }
5132
5133 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005134 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005135 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005136 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005137 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005138 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005142 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143 if (componentName == null) {
5144 throw new SecurityException(
5145 "Caller not current active visual voicemail package[null]");
5146 }
5147 String vvmPackage = componentName.getPackageName();
5148 if (!callingPackage.equals(vvmPackage)) {
5149 throw new SecurityException("Caller not current active visual voicemail package["
5150 + vvmPackage + "]");
5151 }
5152 } finally {
5153 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005154 }
5155 }
5156
5157 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005158 * Return the application ID for the app type.
5159 *
5160 * @param subId the subscription ID that this request applies to.
5161 * @param appType the uicc app type.
5162 * @return Application ID for specificied app type, or null if no uicc.
5163 */
5164 @Override
5165 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005166 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005167 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005168
5169 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005170 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171 if (phone == null) {
5172 return null;
5173 }
5174 String aid = null;
5175 try {
5176 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5177 .getApplicationByType(appType).getAid();
5178 } catch (Exception e) {
5179 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5180 }
5181 return aid;
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005184 }
Youhan Wange64578a2016-05-02 15:32:42 -07005185 }
5186
Youhan Wang4001d252016-05-11 10:29:41 -07005187 /**
5188 * Return the Electronic Serial Number.
5189 *
5190 * @param subId the subscription ID that this request applies to.
5191 * @return ESN or null if error.
5192 */
5193 @Override
5194 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005195 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005196 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005197
5198 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005199 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005200 if (phone == null) {
5201 return null;
5202 }
5203 String esn = null;
5204 try {
5205 esn = phone.getEsn();
5206 } catch (Exception e) {
5207 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5208 }
5209 return esn;
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005212 }
Youhan Wang4001d252016-05-11 10:29:41 -07005213 }
5214
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005215 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005216 * Return the Preferred Roaming List Version.
5217 *
5218 * @param subId the subscription ID that this request applies to.
5219 * @return PRLVersion or null if error.
5220 */
5221 @Override
5222 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005223 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005224 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005225
5226 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005227 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228 if (phone == null) {
5229 return null;
5230 }
5231 String cdmaPrlVersion = null;
5232 try {
5233 cdmaPrlVersion = phone.getCdmaPrlVersion();
5234 } catch (Exception e) {
5235 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5236 }
5237 return cdmaPrlVersion;
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005240 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005241 }
5242
5243 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005244 * Get snapshot of Telephony histograms
5245 * @return List of Telephony histograms
5246 * @hide
5247 */
5248 @Override
5249 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5251 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005252
5253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 return RIL.getTelephonyRILTimingHistograms();
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005259 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005260
5261 /**
5262 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005263 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5264 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005265 * Require system privileges. In the future we may add this to carrier APIs.
5266 *
Michele Berionne0963c862018-11-27 18:57:59 -08005267 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005268 */
5269 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005270 @TelephonyManager.SetCarrierRestrictionResult
5271 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005272 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005274
Michele Berionne0963c862018-11-27 18:57:59 -08005275 if (carrierRestrictionRules == null) {
5276 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005277 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005278
Malcolm Chend965c8b2018-02-28 15:00:40 -08005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005281 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005282 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005286 }
5287
5288 /**
5289 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005290 * Get the allowed carrier list and the excluded carrier list, including the priority between
5291 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005292 * Require system privileges. In the future we may add this to carrier APIs.
5293 *
Michele Berionne0963c862018-11-27 18:57:59 -08005294 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005295 */
5296 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005297 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005298 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005299 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005303 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5304 if (response instanceof CarrierRestrictionRules) {
5305 return (CarrierRestrictionRules) response;
5306 }
5307 // Response is an Exception of some kind,
5308 // which is signalled to the user as a NULL retval
5309 return null;
5310 } catch (Exception e) {
5311 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5312 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005316 }
5317
fionaxu59545b42016-05-25 15:53:37 -07005318 /**
5319 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5320 * @param subId the subscription ID that this action applies to.
5321 * @param enabled control enable or disable metered apns.
5322 * {@hide}
5323 */
5324 @Override
5325 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5326 enforceModifyPermission();
5327 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005328
5329 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005330 if (phone == null) {
5331 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5332 return;
5333 }
5334 try {
5335 phone.carrierActionSetMeteredApnsEnabled(enabled);
5336 } catch (Exception e) {
5337 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005340 }
5341 }
5342
5343 /**
5344 * Action set from carrier signalling broadcast receivers to enable/disable radio
5345 * @param subId the subscription ID that this action applies to.
5346 * @param enabled control enable or disable radio.
5347 * {@hide}
5348 */
5349 @Override
5350 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5351 enforceModifyPermission();
5352 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005353
5354 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005355 if (phone == null) {
5356 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5357 return;
5358 }
5359 try {
5360 phone.carrierActionSetRadioEnabled(enabled);
5361 } catch (Exception e) {
5362 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005363 } finally {
5364 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005365 }
5366 }
5367
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005368 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005369 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5370 * network status based on which carrier apps could apply actions accordingly,
5371 * enable/disable default url handler for example.
5372 *
5373 * @param subId the subscription ID that this action applies to.
5374 * @param report control start/stop reporting the default network status.
5375 * {@hide}
5376 */
5377 @Override
5378 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5379 enforceModifyPermission();
5380 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005381
5382 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005383 if (phone == null) {
5384 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5385 return;
5386 }
5387 try {
5388 phone.carrierActionReportDefaultNetworkStatus(report);
5389 } catch (Exception e) {
5390 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005391 } finally {
5392 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005393 }
5394 }
5395
5396 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005397 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5398 * bug report is being generated.
5399 */
5400 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005401 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005402 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5403 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005404 writer.println("Permission Denial: can't dump Phone from pid="
5405 + Binder.getCallingPid()
5406 + ", uid=" + Binder.getCallingUid()
5407 + "without permission "
5408 + android.Manifest.permission.DUMP);
5409 return;
5410 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005411 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005412 }
Jack Yueb89b242016-06-22 13:27:47 -07005413
Brad Ebingerdac2f002018-04-03 15:17:52 -07005414 @Override
5415 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5416 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5417 throws RemoteException {
5418 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5419 }
5420
Jack Yueb89b242016-06-22 13:27:47 -07005421 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005422 * Get aggregated video call data usage since boot.
5423 *
5424 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5425 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005426 * {@hide}
5427 */
5428 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005429 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005430 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5431 null);
5432
Malcolm Chend965c8b2018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 // NetworkStatsService keeps tracking the active network interface and identity. It
5436 // records the delta with the corresponding network identity.
5437 // We just return the total video call data usage snapshot since boot.
5438 Phone phone = getPhone(subId);
5439 if (phone != null) {
5440 return phone.getVtDataUsage(perUidStats);
5441 }
5442 return null;
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005445 }
Jack Yueb89b242016-06-22 13:27:47 -07005446 }
Jack Yu75ab2952016-07-08 14:29:33 -07005447
5448 /**
5449 * Policy control of data connection. Usually used when data limit is passed.
5450 * @param enabled True if enabling the data, otherwise disabling.
5451 * @param subId Subscription index
5452 * {@hide}
5453 */
5454 @Override
5455 public void setPolicyDataEnabled(boolean enabled, int subId) {
5456 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005457
5458 final long identity = Binder.clearCallingIdentity();
5459 try {
5460 Phone phone = getPhone(subId);
5461 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005462 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005463 }
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005466 }
5467 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005468
5469 /**
5470 * Get Client request stats
5471 * @return List of Client Request Stats
5472 * @hide
5473 */
5474 @Override
5475 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005477 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005478 return null;
5479 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005480 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005481
Malcolm Chend965c8b2018-02-28 15:00:40 -08005482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 if (phone != null) {
5485 return phone.getClientRequestStats();
5486 }
5487
5488 return null;
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005492 }
5493
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005494 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005495 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005496 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005497 }
Jack Yueb4124c2017-02-16 15:32:43 -08005498
5499 /**
Grace Chen70990072017-03-24 17:21:30 -07005500 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005501 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005502 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005503 * @param state State of SIM (power down, power up, pass through)
5504 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5505 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5506 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005507 *
5508 **/
5509 @Override
Grace Chen70990072017-03-24 17:21:30 -07005510 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005511 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005512 Phone phone = PhoneFactory.getPhone(slotIndex);
5513
vagdevie435a3e2018-08-15 16:01:53 -07005514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5515
Malcolm Chend965c8b2018-02-28 15:00:40 -08005516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005519 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005520 }
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005523 }
5524 }
Shuo Qiandd210312017-04-12 22:11:33 +00005525
Tyler Gunn65d45c22017-06-05 11:22:26 -07005526 private boolean isUssdApiAllowed(int subId) {
5527 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005528 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005529 if (configManager == null) {
5530 return false;
5531 }
5532 PersistableBundle pb = configManager.getConfigForSubId(subId);
5533 if (pb == null) {
5534 return false;
5535 }
5536 return pb.getBoolean(
5537 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5538 }
5539
Shuo Qiandd210312017-04-12 22:11:33 +00005540 /**
5541 * Check if phone is in emergency callback mode
5542 * @return true if phone is in emergency callback mode
5543 * @param subId sub id
5544 */
goneil9c5f4872017-12-05 14:07:56 -08005545 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005546 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005547 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005548 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005549
5550 final long identity = Binder.clearCallingIdentity();
5551 try {
5552 if (phone != null) {
5553 return phone.isInEcm();
5554 } else {
5555 return false;
5556 }
5557 } finally {
5558 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005559 }
5560 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005561
5562 /**
5563 * Get the current signal strength information for the given subscription.
5564 * Because this information is not updated when the device is in a low power state
5565 * it should not be relied-upon to be current.
5566 * @param subId Subscription index
5567 * @return the most recent cached signal strength info from the modem
5568 */
5569 @Override
5570 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005571 final long identity = Binder.clearCallingIdentity();
5572 try {
5573 Phone p = getPhone(subId);
5574 if (p == null) {
5575 return null;
5576 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005577
Malcolm Chend965c8b2018-02-28 15:00:40 -08005578 return p.getSignalStrength();
5579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005582 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005583
Pengquan Meng9140aec2018-08-22 14:49:57 -07005584 /**
chen xu907e5a22018-10-11 13:21:04 -07005585 * Get the current modem radio state for the given slot.
5586 * @param slotIndex slot index.
5587 * @param callingPackage the name of the package making the call.
5588 * @return the current radio power state from the modem
5589 */
5590 @Override
5591 public int getRadioPowerState(int slotIndex, String callingPackage) {
5592 Phone phone = PhoneFactory.getPhone(slotIndex);
5593 if (phone != null) {
5594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5595 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5596 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5597 }
5598
5599 final long identity = Binder.clearCallingIdentity();
5600 try {
5601 return phone.getRadioPowerState();
5602 } finally {
5603 Binder.restoreCallingIdentity(identity);
5604 }
5605 }
5606 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5607 }
5608
5609 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005610 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5611 *
5612 * <p>Requires one of the following permissions:
5613 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5614 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5615 * privileges.
5616 *
5617 * @param subId subscription id
5618 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5619 * {@code false}.
5620 */
5621 @Override
5622 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005623 boolean isEnabled = false;
5624 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005625 try {
5626 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005627 null /* message */);
5628 Phone phone = getPhone(subId);
5629 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005630 } catch (Exception e) {
5631 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5632 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005633 } finally {
5634 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005635 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005636 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005637 }
5638
5639
5640 /**
5641 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5642 *
5643 * <p> Requires permission:
5644 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5645 * privileges.
5646 *
5647 * @param subId subscription id
5648 * @param isEnabled {@code true} means enable, {@code false} means disable.
5649 */
5650 @Override
5651 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5655 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005656
Pengquan Meng0c05b502018-09-06 09:59:22 -07005657 Phone phone = getPhone(subId);
5658 if (phone != null) {
5659 phone.setDataRoamingEnabled(isEnabled);
5660 }
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005663 }
5664 }
5665
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005666 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005667 public boolean isManualNetworkSelectionAllowed(int subId) {
5668 boolean isAllowed = true;
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5672 mApp, subId, "isManualNetworkSelectionAllowed");
5673 Phone phone = getPhone(subId);
5674 if (phone != null) {
5675 isAllowed = phone.isCspPlmnEnabled();
5676 }
5677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
5680 return isAllowed;
5681 }
5682
5683 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005684 public UiccCardInfo[] getUiccCardsInfo() {
5685 enforceReadPrivilegedPermission("getUiccCardsInfo");
5686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5690 return cards.toArray(new UiccCardInfo[cards.size()]);
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
5694 }
5695
5696 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005697 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005698 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005699
Malcolm Chend965c8b2018-02-28 15:00:40 -08005700 final long identity = Binder.clearCallingIdentity();
5701 try {
5702 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5703 if (slots == null) {
5704 Rlog.i(LOG_TAG, "slots is null.");
5705 return null;
5706 }
5707
5708 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5709 for (int i = 0; i < slots.length; i++) {
5710 UiccSlot slot = slots[i];
5711 if (slot == null) {
5712 continue;
5713 }
5714
5715 String cardId;
5716 UiccCard card = slot.getUiccCard();
5717 if (card != null) {
5718 cardId = card.getCardId();
5719 } else {
5720 cardId = slot.getIccId();
5721 }
5722
5723 int cardState = 0;
5724 switch (slot.getCardState()) {
5725 case CARDSTATE_ABSENT:
5726 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5727 break;
5728 case CARDSTATE_PRESENT:
5729 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5730 break;
5731 case CARDSTATE_ERROR:
5732 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5733 break;
5734 case CARDSTATE_RESTRICTED:
5735 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5736 break;
5737 default:
5738 break;
5739
5740 }
5741
5742 infos[i] = new UiccSlotInfo(
5743 slot.isActive(),
5744 slot.isEuicc(),
5745 cardId,
5746 cardState,
5747 slot.getPhoneId(),
5748 slot.isExtendedApduSupported());
5749 }
5750 return infos;
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005753 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005754 }
5755
5756 @Override
5757 public boolean switchSlots(int[] physicalSlots) {
5758 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005759
5760 final long identity = Binder.clearCallingIdentity();
5761 try {
5762 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005766 }
Jack Yu4c988042018-02-27 15:30:01 -08005767
5768 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005769 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5771 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5772 return TelephonyManager.INVALID_CARD_ID;
5773 }
5774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 return UiccController.getInstance().getCardIdForDefaultEuicc();
5778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
5781 }
5782
5783 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005784 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5785 enforceModifyPermission();
5786 final Phone phone = getPhone(subId);
5787 if (phone == null) {
5788 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5789 return;
5790 }
5791
Malcolm Chend965c8b2018-02-28 15:00:40 -08005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 phone.setRadioIndicationUpdateMode(filters, mode);
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Jack Yu4c988042018-02-27 15:30:01 -08005798 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005799
5800 /**
goneil47ffb6e2018-04-06 15:40:58 -07005801 * A test API to reload the UICC profile.
5802 *
5803 * <p>Requires that the calling app has permission
5804 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5805 * @hide
5806 */
5807 @Override
5808 public void refreshUiccProfile(int subId) {
5809 enforceModifyPermission();
5810
5811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 Phone phone = getPhone(subId);
5814 if (phone == null) {
5815 return;
5816 }
5817 UiccCard uiccCard = phone.getUiccCard();
5818 if (uiccCard == null) {
5819 return;
5820 }
5821 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5822 if (uiccProfile == null) {
5823 return;
5824 }
5825 uiccProfile.refresh();
5826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
5829 }
5830
5831 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005832 * Returns false if the mobile data is disabled by default, otherwise return true.
5833 */
5834 private boolean getDefaultDataEnabled() {
5835 return "true".equalsIgnoreCase(
5836 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5837 }
5838
5839 /**
5840 * Returns true if the data roaming is enabled by default, i.e the system property
5841 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5842 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5843 */
5844 private boolean getDefaultDataRoamingEnabled(int subId) {
5845 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005846 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005847 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5848 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5849 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5850 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5851 return isDataRoamingEnabled;
5852 }
5853
5854 /**
5855 * Returns the default network type for the given {@code subId}, if the default network type is
5856 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5857 */
5858 private int getDefaultNetworkType(int subId) {
5859 return Integer.parseInt(
5860 TelephonyManager.getTelephonyProperty(
5861 mSubscriptionController.getPhoneId(subId),
5862 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5863 String.valueOf(Phone.PREFERRED_NT_MODE)));
5864 }
fionaxua13278b2018-03-21 00:08:13 -07005865
5866 @Override
5867 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5868 gid1, String gid2, String plmn, String spn) {
5869 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005870
5871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 final Phone phone = getPhone(subId);
5874 if (phone == null) {
5875 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5876 return;
5877 }
5878 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5879 } finally {
5880 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005881 }
fionaxua13278b2018-03-21 00:08:13 -07005882 }
5883
5884 @Override
5885 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005886 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005887
5888 final long identity = Binder.clearCallingIdentity();
5889 try {
5890 final Phone phone = getPhone(subId);
5891 if (phone == null) {
5892 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5893 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5894 }
5895 return phone.getCarrierIdListVersion();
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005898 }
fionaxua13278b2018-03-21 00:08:13 -07005899 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005900
5901 @Override
5902 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5904 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5905 return -1;
5906 }
5907
5908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
5914 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005915
5916 @Override
5917 public int getCdmaRoamingMode(int subId) {
5918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5919 mApp, subId, "getCdmaRoamingMode");
5920
5921 final long identity = Binder.clearCallingIdentity();
5922 try {
5923 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
5927 }
5928
5929 @Override
5930 public boolean setCdmaRoamingMode(int subId, int mode) {
5931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5932 mApp, subId, "setCdmaRoamingMode");
5933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
5936 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
5940 }
5941
5942 @Override
5943 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5945 mApp, subId, "setCdmaSubscriptionMode");
5946
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
5953 }
chen xu7ee67862018-10-30 22:27:10 -07005954
sqian2fff4a32018-11-05 14:18:37 -08005955 private void ensureUserRunning(int userId) {
5956 if (!mUserManager.isUserRunning(userId)) {
5957 throw new IllegalStateException("User " + userId + " does not exist or not running");
5958 }
5959 }
5960
5961 /**
5962 * Returns a list of SMS apps on a given user.
5963 *
5964 * Only the shell user (UID 2000 or 0) can call it.
5965 * Target user must be running.
5966 */
5967 @Override
5968 public String[] getSmsApps(int userId) {
5969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5970 ensureUserRunning(userId);
5971
5972 final Collection<SmsApplicationData> apps =
5973 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5974
5975 String[] ret = new String[apps.size()];
5976 int i = 0;
5977 for (SmsApplicationData app : apps) {
5978 ret[i++] = app.mPackageName;
5979 }
5980 return ret;
5981 }
5982
5983 /**
5984 * Returns the default SMS app package name on a given user.
5985 *
5986 * Only the shell user (UID 2000 or 0) can call it.
5987 * Target user must be running.
5988 */
5989 @Override
5990 public String getDefaultSmsApp(int userId) {
5991 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5992 ensureUserRunning(userId);
5993
5994 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5995 /* updateIfNeeded= */ true, userId);
5996 return cn == null ? null : cn.getPackageName();
5997 }
5998
5999 /**
6000 * Set a package as the default SMS app on a given user.
6001 *
6002 * Only the shell user (UID 2000 or 0) can call it.
6003 * Target user must be running.
6004 */
6005 @Override
6006 public void setDefaultSmsApp(int userId, String packageName) {
6007 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6008 ensureUserRunning(userId);
6009
6010 boolean found = false;
6011 for (String pkg : getSmsApps(userId)) {
6012 if (TextUtils.equals(packageName, pkg)) {
6013 found = true;
6014 break;
6015 }
6016 }
6017 if (!found) {
6018 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6019 }
6020
6021 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6022 }
6023
chen xu7ee67862018-10-30 22:27:10 -07006024 @Override
sqian04b86072018-11-07 14:02:21 -08006025 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6026 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6028 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6029 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6030 }
6031 final long identity = Binder.clearCallingIdentity();
6032 try {
sqian991b35e2018-12-12 16:48:18 -08006033 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6034 for (Phone phone: PhoneFactory.getPhones()) {
6035 if (phone.getEmergencyNumberTracker() != null
6036 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6037 emergencyNumberListInternal.put(
6038 phone.getSubId(),
6039 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6040 }
sqian03bca152018-12-05 18:48:28 -08006041 }
sqian991b35e2018-12-12 16:48:18 -08006042 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006043 } finally {
6044 Binder.restoreCallingIdentity(identity);
6045 }
sqian04b86072018-11-07 14:02:21 -08006046 }
6047
6048 @Override
sqian03bca152018-12-05 18:48:28 -08006049 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6050 final Phone defaultPhone = getDefaultPhone();
6051 if (!exactMatch) {
6052 TelephonyPermissions
6053 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6054 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6055 }
6056 final long identity = Binder.clearCallingIdentity();
6057 try {
sqian991b35e2018-12-12 16:48:18 -08006058 for (Phone phone: PhoneFactory.getPhones()) {
6059 if (phone.getEmergencyNumberTracker() != null
6060 && phone.getEmergencyNumberTracker() != null) {
6061 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6062 number, exactMatch)) {
6063 return true;
sqian03bca152018-12-05 18:48:28 -08006064 }
6065 }
sqian03bca152018-12-05 18:48:28 -08006066 }
6067 return false;
6068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
6071 }
6072
sqian04b86072018-11-07 14:02:21 -08006073 @Override
chen xu7ee67862018-10-30 22:27:10 -07006074 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6075 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6076 Phone phone = getPhone(subId);
6077 if (phone == null) {
6078 return null;
6079 }
6080 final long identity = Binder.clearCallingIdentity();
6081 try {
6082 UiccProfile profile = UiccController.getInstance()
6083 .getUiccProfileForPhone(phone.getPhoneId());
6084 if (profile != null) {
6085 return profile.getCertsFromCarrierPrivilegeAccessRules();
6086 }
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
6090 return null;
6091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006092}