blob: a41e9d9c8ada0bee28fd920cea42af4f91cceba1 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000081import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070082import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070083import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070084import android.telephony.cdma.CdmaCellLocation;
calvinpaneed9ae82018-11-01 19:43:06 +080085import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070086import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070087import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080088import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070089import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080090import android.telephony.ims.aidl.IImsMmTelFeature;
91import android.telephony.ims.aidl.IImsRcsFeature;
92import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070093import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080094import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080098import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080099import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800100
Brad Ebinger4c460712018-10-01 10:40:55 -0700101import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700102import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800103import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700104import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700105import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700106import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800107import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700108import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800111import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800113import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700114import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100115import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700116import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700117import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700119import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800120import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700121import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700122import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700123import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700124import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700125import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700126import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800127import com.android.internal.telephony.SmsApplication;
128import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800129import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800130import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700131import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700132import com.android.internal.telephony.uicc.IccIoResult;
133import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800134import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700135import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800136import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700137import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800138import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000139import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700140import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800141import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700142import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800143import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700144import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700145import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800146
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700147import java.io.FileDescriptor;
148import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800149import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800151import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800152import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800153import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100154import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800155import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156
157/**
158 * Implementation of the ITelephony interface.
159 */
Santos Cordon117fee72014-05-16 17:56:12 -0700160public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161 private static final String LOG_TAG = "PhoneInterfaceManager";
162 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
163 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800164 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165
166 // Message codes used with mMainThreadHandler
167 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700168 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
169 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170 private static final int CMD_OPEN_CHANNEL = 9;
171 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
172 private static final int CMD_CLOSE_CHANNEL = 11;
173 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800174 private static final int CMD_NV_READ_ITEM = 13;
175 private static final int EVENT_NV_READ_ITEM_DONE = 14;
176 private static final int CMD_NV_WRITE_ITEM = 15;
177 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
178 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
179 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700180 private static final int CMD_RESET_MODEM_CONFIG = 19;
181 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800182 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
183 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
184 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
185 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800186 private static final int CMD_SEND_ENVELOPE = 25;
187 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000188 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
189 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700190 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
191 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
192 private static final int CMD_EXCHANGE_SIM_IO = 31;
193 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800194 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
195 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700196 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
197 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700198 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
199 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700200 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
201 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
202 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
203 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700204 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
205 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
206 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
207 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700208 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800209 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
210 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000211 private static final int CMD_SWITCH_SLOTS = 50;
212 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700213 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
214 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
215 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
216 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
217 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
218 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
219 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
220 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700221 private static final int CMD_GET_ALL_CELL_INFO = 60;
222 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
223 private static final int CMD_GET_CELL_LOCATION = 62;
224 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700225 private static final int CMD_MODEM_REBOOT = 64;
226 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700227 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
228 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800230 // Parameters of select command.
231 private static final int SELECT_COMMAND = 0xA4;
232 private static final int SELECT_P1 = 0x04;
233 private static final int SELECT_P2 = 0;
234 private static final int SELECT_P3 = 0x10;
235
Pengquan Meng85728fb2018-03-12 16:31:21 -0700236 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
237 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
238 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
239
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240 /** The singleton instance. */
241 private static PhoneInterfaceManager sInstance;
242
Wink Saville3ab207e2014-11-20 13:07:20 -0800243 private PhoneGlobals mApp;
244 private Phone mPhone;
245 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700246 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800247 private AppOpsManager mAppOps;
248 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800249 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800250 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700251 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252
Derek Tan97ebb422014-09-05 16:55:38 -0700253 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
254 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800255 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700256
Derek Tan740e1672017-06-27 14:56:27 -0700257 // The AID of ISD-R.
258 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
259
yinxub1bed742017-04-17 11:45:04 -0700260 private NetworkScanRequestTracker mNetworkScanRequestTracker;
261
David Kelly5e06a7f2018-03-12 14:10:59 +0000262 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
263 private static final int MANUFACTURER_CODE_LENGTH = 8;
264
Derek Tan89e89d42014-07-08 17:00:10 -0700265 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700266 * A request object to use for transmitting data to an ICC.
267 */
268 private static final class IccAPDUArgument {
269 public int channel, cla, command, p1, p2, p3;
270 public String data;
271
272 public IccAPDUArgument(int channel, int cla, int command,
273 int p1, int p2, int p3, String data) {
274 this.channel = channel;
275 this.cla = cla;
276 this.command = command;
277 this.p1 = p1;
278 this.p2 = p2;
279 this.p3 = p3;
280 this.data = data;
281 }
282 }
283
284 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700285 * A request object to use for transmitting data to an ICC.
286 */
287 private static final class ManualNetworkSelectionArgument {
288 public OperatorInfo operatorInfo;
289 public boolean persistSelection;
290
291 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
292 this.operatorInfo = operatorInfo;
293 this.persistSelection = persistSelection;
294 }
295 }
296
297 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
299 * request after sending. The main thread will notify the request when it is complete.
300 */
301 private static final class MainThreadRequest {
302 /** The argument to use for the request */
303 public Object argument;
304 /** The result of the request that is run on the main thread */
305 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800306 // The subscriber id that this request applies to. Defaults to
307 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
308 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309
Nathan Harold92bed182018-10-12 18:16:49 -0700310 // In cases where subId is unavailable, the caller needs to specify the phone.
311 public Phone phone;
312
vagdevie435a3e2018-08-15 16:01:53 -0700313 public WorkSource workSource;
314
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 public MainThreadRequest(Object argument) {
316 this.argument = argument;
317 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800318
Nathan Harold92bed182018-10-12 18:16:49 -0700319 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
320 this.argument = argument;
321 if (phone != null) {
322 this.phone = phone;
323 }
324 this.workSource = workSource;
325 }
326
vagdevie435a3e2018-08-15 16:01:53 -0700327 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800328 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800329 if (subId != null) {
330 this.subId = subId;
331 }
vagdevie435a3e2018-08-15 16:01:53 -0700332 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 }
335
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800336 private static final class IncomingThirdPartyCallArgs {
337 public final ComponentName component;
338 public final String callId;
339 public final String callerDisplayName;
340
341 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
342 String callerDisplayName) {
343 this.component = component;
344 this.callId = callId;
345 this.callerDisplayName = callerDisplayName;
346 }
347 }
348
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 /**
350 * A handler that processes messages on the main thread in the phone process. Since many
351 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
352 * inbound binder threads to the main thread in the phone process. The Binder thread
353 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
354 * on, which will be notified when the operation completes and will contain the result of the
355 * request.
356 *
357 * <p>If a MainThreadRequest object is provided in the msg.obj field,
358 * note that request.result must be set to something non-null for the calling thread to
359 * unblock.
360 */
361 private final class MainThreadHandler extends Handler {
362 @Override
363 public void handleMessage(Message msg) {
364 MainThreadRequest request;
365 Message onCompleted;
366 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800367 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700368 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
370 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700371 case CMD_HANDLE_USSD_REQUEST: {
372 request = (MainThreadRequest) msg.obj;
373 final Phone phone = getPhoneFromRequest(request);
374 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
375 String ussdRequest = ussdObject.first;
376 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700377
Pengquan Meng0c05b502018-09-06 09:59:22 -0700378 if (!isUssdApiAllowed(request.subId)) {
379 // Carrier does not support use of this API, return failure.
380 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
381 UssdResponse response = new UssdResponse(ussdRequest, null);
382 Bundle returnData = new Bundle();
383 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
384 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700385
Pengquan Meng0c05b502018-09-06 09:59:22 -0700386 request.result = true;
387 notifyRequester(request);
388 return;
389 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700390
Pengquan Meng0c05b502018-09-06 09:59:22 -0700391 try {
392 request.result = phone != null
393 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
394 } catch (CallStateException cse) {
395 request.result = false;
396 }
397 // Wake up the requesting thread
398 notifyRequester(request);
399 break;
pkanwar32d516d2016-10-14 19:37:38 -0700400 }
401
Yorke Lee716f67e2015-06-17 15:39:16 -0700402 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700404 final Phone phone = getPhoneFromRequest(request);
405 request.result = phone != null ?
406 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
407 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700409 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800416 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 if (uiccCard == null) {
418 loge("iccTransmitApduLogicalChannel: No UICC");
419 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700420 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700421 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
423 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 iccArgument.channel, iccArgument.cla, iccArgument.command,
426 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 break;
430
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 ar = (AsyncResult) msg.obj;
433 request = (MainThreadRequest) ar.userObj;
434 if (ar.exception == null && ar.result != null) {
435 request.result = ar.result;
436 } else {
437 request.result = new IccIoResult(0x6F, 0, (byte[])null);
438 if (ar.result == null) {
439 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800440 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800442 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 } else {
444 loge("iccTransmitApduLogicalChannel: Unknown exception");
445 }
446 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700447 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 break;
449
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
451 request = (MainThreadRequest) msg.obj;
452 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800453 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 if (uiccCard == null) {
455 loge("iccTransmitApduBasicChannel: No UICC");
456 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700457 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 } else {
459 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
460 request);
461 uiccCard.iccTransmitApduBasicChannel(
462 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
463 iccArgument.p3, iccArgument.data, onCompleted);
464 }
465 break;
466
467 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
468 ar = (AsyncResult) msg.obj;
469 request = (MainThreadRequest) ar.userObj;
470 if (ar.exception == null && ar.result != null) {
471 request.result = ar.result;
472 } else {
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 if (ar.result == null) {
475 loge("iccTransmitApduBasicChannel: Empty response");
476 } else if (ar.exception instanceof CommandException) {
477 loge("iccTransmitApduBasicChannel: CommandException: " +
478 ar.exception);
479 } else {
480 loge("iccTransmitApduBasicChannel: Unknown exception");
481 }
482 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700483 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 break;
485
486 case CMD_EXCHANGE_SIM_IO:
487 request = (MainThreadRequest) msg.obj;
488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 if (uiccCard == null) {
491 loge("iccExchangeSimIO: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 } else {
495 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
496 request);
497 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
498 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
499 iccArgument.data, onCompleted);
500 }
501 break;
502
503 case EVENT_EXCHANGE_SIM_IO_DONE:
504 ar = (AsyncResult) msg.obj;
505 request = (MainThreadRequest) ar.userObj;
506 if (ar.exception == null && ar.result != null) {
507 request.result = ar.result;
508 } else {
509 request.result = new IccIoResult(0x6f, 0, (byte[])null);
510 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700511 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 break;
513
Derek Tan4d5e5c12014-02-04 11:54:58 -0800514 case CMD_SEND_ENVELOPE:
515 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800516 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700517 if (uiccCard == null) {
518 loge("sendEnvelopeWithStatus: No UICC");
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700520 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700521 } else {
522 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
523 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
524 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800525 break;
526
527 case EVENT_SEND_ENVELOPE_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800532 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
534 if (ar.result == null) {
535 loge("sendEnvelopeWithStatus: Empty response");
536 } else if (ar.exception instanceof CommandException) {
537 loge("sendEnvelopeWithStatus: CommandException: " +
538 ar.exception);
539 } else {
540 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
541 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800542 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700543 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 break;
545
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 case CMD_OPEN_CHANNEL:
547 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800548 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800549 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800552 request.result = new IccOpenLogicalChannelResponse(-1,
553 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700554 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 } else {
556 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800557 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
558 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 break;
561
562 case EVENT_OPEN_CHANNEL_DONE:
563 ar = (AsyncResult) msg.obj;
564 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 int[] result = (int[]) ar.result;
568 int channelId = result[0];
569 byte[] selectResponse = null;
570 if (result.length > 1) {
571 selectResponse = new byte[result.length - 1];
572 for (int i = 1; i < result.length; ++i) {
573 selectResponse[i - 1] = (byte) result[i];
574 }
575 }
576 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700577 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 if (ar.result == null) {
580 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 if (ar.exception != null) {
583 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
584 }
585
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700586 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700587 if (ar.exception instanceof CommandException) {
588 CommandException.Error error =
589 ((CommandException) (ar.exception)).getCommandError();
590 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700592 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 }
595 }
596 openChannelResp = new IccOpenLogicalChannelResponse(
597 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700599 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
603 case CMD_CLOSE_CHANNEL:
604 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800605 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 if (uiccCard == null) {
607 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900608 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700610 } else {
611 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
612 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
613 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 break;
615
616 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800617 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
618 break;
619
620 case CMD_NV_READ_ITEM:
621 request = (MainThreadRequest) msg.obj;
622 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700623 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800624 break;
625
626 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800632 request.result = "";
633 if (ar.result == null) {
634 loge("nvReadItem: Empty response");
635 } else if (ar.exception instanceof CommandException) {
636 loge("nvReadItem: CommandException: " +
637 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800639 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 }
641 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 break;
644
Jake Hambye994d462014-02-03 13:10:13 -0800645 case CMD_NV_WRITE_ITEM:
646 request = (MainThreadRequest) msg.obj;
647 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
648 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700649 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
650 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800651 break;
652
653 case EVENT_NV_WRITE_ITEM_DONE:
654 handleNullReturnEvent(msg, "nvWriteItem");
655 break;
656
657 case CMD_NV_WRITE_CDMA_PRL:
658 request = (MainThreadRequest) msg.obj;
659 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
660 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
661 break;
662
663 case EVENT_NV_WRITE_CDMA_PRL_DONE:
664 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
665 break;
666
chen xu1cc0abe2018-10-26 17:39:23 -0700667 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800668 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700669 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
670 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
chen xu1cc0abe2018-10-26 17:39:23 -0700673 case EVENT_RESET_MODEM_CONFIG_DONE:
674 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800675 break;
676
Jake Hamby7c27be32014-03-03 13:25:59 -0800677 case CMD_GET_PREFERRED_NETWORK_TYPE:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700680 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800681 break;
682
683 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
684 ar = (AsyncResult) msg.obj;
685 request = (MainThreadRequest) ar.userObj;
686 if (ar.exception == null && ar.result != null) {
687 request.result = ar.result; // Integer
688 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800689 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800690 if (ar.result == null) {
691 loge("getPreferredNetworkType: Empty response");
692 } else if (ar.exception instanceof CommandException) {
693 loge("getPreferredNetworkType: CommandException: " +
694 ar.exception);
695 } else {
696 loge("getPreferredNetworkType: Unknown exception");
697 }
698 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700699 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 break;
701
702 case CMD_SET_PREFERRED_NETWORK_TYPE:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
705 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700706 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 break;
708
709 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
710 handleNullReturnEvent(msg, "setPreferredNetworkType");
711 break;
712
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000713 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
714 request = (MainThreadRequest)msg.obj;
715 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700716 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000717 break;
718
719 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
720 ar = (AsyncResult)msg.obj;
721 request = (MainThreadRequest)ar.userObj;
722 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700723 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000724 break;
725
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800726 case CMD_SET_VOICEMAIL_NUMBER:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
729 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800730 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
731 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800732 break;
733
734 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
735 handleNullReturnEvent(msg, "setVoicemailNumber");
736 break;
737
Stuart Scott54788802015-03-30 13:18:01 -0700738 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
741 request);
742 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
743 break;
744
745 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
746 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
747 break;
748
Shishir Agrawal302c8692015-06-19 13:49:39 -0700749 case CMD_PERFORM_NETWORK_SCAN:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
752 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
753 break;
754
755 case EVENT_PERFORM_NETWORK_SCAN_DONE:
756 ar = (AsyncResult) msg.obj;
757 request = (MainThreadRequest) ar.userObj;
758 CellNetworkScanResult cellScanResult;
759 if (ar.exception == null && ar.result != null) {
760 cellScanResult = new CellNetworkScanResult(
761 CellNetworkScanResult.STATUS_SUCCESS,
762 (List<OperatorInfo>) ar.result);
763 } else {
764 if (ar.result == null) {
765 loge("getCellNetworkScanResults: Empty response");
766 }
767 if (ar.exception != null) {
768 loge("getCellNetworkScanResults: Exception: " + ar.exception);
769 }
770 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
771 if (ar.exception instanceof CommandException) {
772 CommandException.Error error =
773 ((CommandException) (ar.exception)).getCommandError();
774 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
775 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
776 } else if (error == CommandException.Error.GENERIC_FAILURE) {
777 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
778 }
779 }
780 cellScanResult = new CellNetworkScanResult(errorCode, null);
781 }
782 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700784 break;
785
786 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
787 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700788 ManualNetworkSelectionArgument selArg =
789 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
791 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700792 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
793 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 break;
795
796 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700797 ar = (AsyncResult) msg.obj;
798 request = (MainThreadRequest) ar.userObj;
799 if (ar.exception == null) {
800 request.result = true;
801 } else {
802 request.result = false;
803 loge("setNetworkSelectionModeManual " + ar.exception);
804 }
805 notifyRequester(request);
806 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 break;
808
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700809 case CMD_GET_MODEM_ACTIVITY_INFO:
810 request = (MainThreadRequest) msg.obj;
811 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700812 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700813 break;
814
815 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
816 ar = (AsyncResult) msg.obj;
817 request = (MainThreadRequest) ar.userObj;
818 if (ar.exception == null && ar.result != null) {
819 request.result = ar.result;
820 } else {
821 if (ar.result == null) {
822 loge("queryModemActivityInfo: Empty response");
823 } else if (ar.exception instanceof CommandException) {
824 loge("queryModemActivityInfo: CommandException: " +
825 ar.exception);
826 } else {
827 loge("queryModemActivityInfo: Unknown exception");
828 }
829 }
Amit Mahajand4766222016-01-28 15:28:28 -0800830 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
831 if (request.result == null) {
832 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
833 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700834 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700835 break;
836
Meng Wang1a7c35a2016-05-05 20:56:15 -0700837 case CMD_SET_ALLOWED_CARRIERS:
838 request = (MainThreadRequest) msg.obj;
839 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
840 mPhone.setAllowedCarriers(
841 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700842 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700843 break;
844
845 case EVENT_SET_ALLOWED_CARRIERS_DONE:
846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
848 if (ar.exception == null && ar.result != null) {
849 request.result = ar.result;
850 } else {
851 if (ar.result == null) {
852 loge("setAllowedCarriers: Empty response");
853 } else if (ar.exception instanceof CommandException) {
854 loge("setAllowedCarriers: CommandException: " +
855 ar.exception);
856 } else {
857 loge("setAllowedCarriers: Unknown exception");
858 }
859 }
860 // Result cannot be null. Return -1 on error.
861 if (request.result == null) {
862 request.result = new int[]{-1};
863 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700864 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700865 break;
866
867 case CMD_GET_ALLOWED_CARRIERS:
868 request = (MainThreadRequest) msg.obj;
869 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700870 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700871 break;
872
873 case EVENT_GET_ALLOWED_CARRIERS_DONE:
874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null && ar.result != null) {
877 request.result = ar.result;
878 } else {
879 if (ar.result == null) {
880 loge("getAllowedCarriers: Empty response");
881 } else if (ar.exception instanceof CommandException) {
882 loge("getAllowedCarriers: CommandException: " +
883 ar.exception);
884 } else {
885 loge("getAllowedCarriers: Unknown exception");
886 }
887 }
888 // Result cannot be null. Return empty list of CarrierIdentifier.
889 if (request.result == null) {
890 request.result = new ArrayList<CarrierIdentifier>(0);
891 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700892 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 break;
894
Nathan Haroldb3014052017-01-25 15:57:32 -0800895 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result;
900 } else {
901 request.result = new IllegalArgumentException(
902 "Failed to retrieve Forbidden Plmns");
903 if (ar.result == null) {
904 loge("getForbiddenPlmns: Empty response");
905 } else {
906 loge("getForbiddenPlmns: Unknown exception");
907 }
908 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700909 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800910 break;
911
912 case CMD_GET_FORBIDDEN_PLMNS:
913 request = (MainThreadRequest) msg.obj;
914 uiccCard = getUiccCardFromRequest(request);
915 if (uiccCard == null) {
916 loge("getForbiddenPlmns() UiccCard is null");
917 request.result = new IllegalArgumentException(
918 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700919 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800920 break;
921 }
922 Integer appType = (Integer) request.argument;
923 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
924 if (uiccApp == null) {
925 loge("getForbiddenPlmns() no app with specified type -- "
926 + appType);
927 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700928 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800929 break;
930 } else {
931 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
932 + " specified type -- " + appType);
933 }
934 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
935 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
936 onCompleted);
937 break;
938
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000939 case CMD_SWITCH_SLOTS:
940 request = (MainThreadRequest) msg.obj;
941 int[] physicalSlots = (int[]) request.argument;
942 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
943 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
944 break;
945
946 case EVENT_SWITCH_SLOTS_DONE:
947 ar = (AsyncResult) msg.obj;
948 request = (MainThreadRequest) ar.userObj;
949 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700950 notifyRequester(request);
951 break;
952 case CMD_GET_NETWORK_SELECTION_MODE:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
955 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
956 break;
957
958 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
959 ar = (AsyncResult) msg.obj;
960 request = (MainThreadRequest) ar.userObj;
961 if (ar.exception != null) {
962 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
963 } else {
964 int mode = ((int[]) ar.result)[0];
965 if (mode == 0) {
966 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
967 } else {
968 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
969 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000970 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700971 notifyRequester(request);
972 break;
973 case CMD_GET_CDMA_ROAMING_MODE:
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
976 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
977 break;
978 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
979 ar = (AsyncResult) msg.obj;
980 request = (MainThreadRequest) ar.userObj;
981 if (ar.exception != null) {
982 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
983 } else {
984 request.result = ((int[]) ar.result)[0];
985 }
986 notifyRequester(request);
987 break;
988 case CMD_SET_CDMA_ROAMING_MODE:
989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
991 int mode = (int) request.argument;
992 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
993 break;
994 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = ar.exception == null;
998 notifyRequester(request);
999 break;
1000 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1001 request = (MainThreadRequest) msg.obj;
1002 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1003 int subscriptionMode = (int) request.argument;
1004 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1005 break;
1006 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
1009 request.result = ar.exception == null;
1010 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001011 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001012 case CMD_GET_ALL_CELL_INFO:
1013 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001014 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001015 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001017 case EVENT_GET_ALL_CELL_INFO_DONE:
1018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001020 // If a timeout occurs, the response will be null
1021 request.result = (ar.exception == null && ar.result != null)
1022 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001023 synchronized (request) {
1024 request.notifyAll();
1025 }
1026 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001027 case CMD_REQUEST_CELL_INFO_UPDATE:
1028 request = (MainThreadRequest) msg.obj;
1029 request.phone.requestCellInfoUpdate(request.workSource,
1030 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1031 break;
1032 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1033 ar = (AsyncResult) msg.obj;
1034 request = (MainThreadRequest) ar.userObj;
1035 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1036 try {
1037 if (ar.exception != null) {
1038 // something went wrong... the response is null
1039 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1040 cb.onCellInfo(null);
1041 } else if (ar.result == null) {
1042 // timeout occurred, so force the result to non-null "empty"
1043 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1044 cb.onCellInfo(new ArrayList<CellInfo>());
1045 } else {
1046 // use the result as returned
1047 cb.onCellInfo((List<CellInfo>) ar.result);
1048 }
1049 } catch (RemoteException re) {
1050 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1051 }
1052 break;
1053 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 request = (MainThreadRequest) msg.obj;
1055 WorkSource ws = (WorkSource) request.argument;
1056 Phone phone = getPhoneFromRequest(request);
1057 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1058 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
1062 if (ar.exception == null) {
1063 request.result = ar.result;
1064 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1067 ? new CdmaCellLocation() : new GsmCellLocation();
1068 }
1069
1070 synchronized (request) {
1071 request.notifyAll();
1072 }
1073 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001074 case CMD_MODEM_REBOOT:
1075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1077 mPhone.rebootModem(onCompleted);
1078 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001079 case EVENT_CMD_MODEM_REBOOT_DONE:
1080 handleNullReturnEvent(msg, "rebootModem");
1081 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 default:
1083 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1084 break;
1085 }
1086 }
Jake Hambye994d462014-02-03 13:10:13 -08001087
Pengquan Meng0c05b502018-09-06 09:59:22 -07001088 private void notifyRequester(MainThreadRequest request) {
1089 synchronized (request) {
1090 request.notifyAll();
1091 }
1092 }
1093
Jake Hambye994d462014-02-03 13:10:13 -08001094 private void handleNullReturnEvent(Message msg, String command) {
1095 AsyncResult ar = (AsyncResult) msg.obj;
1096 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1097 if (ar.exception == null) {
1098 request.result = true;
1099 } else {
1100 request.result = false;
1101 if (ar.exception instanceof CommandException) {
1102 loge(command + ": CommandException: " + ar.exception);
1103 } else {
1104 loge(command + ": Unknown exception");
1105 }
1106 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001107 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001109 }
1110
1111 /**
1112 * Posts the specified command to be executed on the main thread,
1113 * waits for the request to complete, and returns the result.
1114 * @see #sendRequestAsync
1115 */
1116 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001117 return sendRequest(
1118 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001119 }
1120
1121 /**
1122 * Posts the specified command to be executed on the main thread,
1123 * waits for the request to complete, and returns the result.
1124 * @see #sendRequestAsync
1125 */
1126 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1127 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001128 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001129 }
1130
1131 /**
1132 * Posts the specified command to be executed on the main thread,
1133 * waits for the request to complete, and returns the result.
1134 * @see #sendRequestAsync
1135 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001136 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001137 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001138 }
1139
1140 /**
1141 * Posts the specified command to be executed on the main thread,
1142 * waits for the request to complete, and returns the result.
1143 * @see #sendRequestAsync
1144 */
Nathan Harold92bed182018-10-12 18:16:49 -07001145 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1146 return sendRequest(command, argument, subId, null, workSource);
1147 }
1148
1149 /**
1150 * Posts the specified command to be executed on the main thread,
1151 * waits for the request to complete, and returns the result.
1152 * @see #sendRequestAsync
1153 */
1154 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1155 return sendRequest(
1156 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1157 }
1158
1159 /**
1160 * Posts the specified command to be executed on the main thread,
1161 * waits for the request to complete, and returns the result.
1162 * @see #sendRequestAsync
1163 */
1164 private Object sendRequest(
1165 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001166 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1167 throw new RuntimeException("This method will deadlock if called from the main thread.");
1168 }
1169
Nathan Harold92bed182018-10-12 18:16:49 -07001170 MainThreadRequest request = null;
1171 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1172 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1173 } else if (phone != null) {
1174 request = new MainThreadRequest(argument, phone, workSource);
1175 } else {
1176 request = new MainThreadRequest(argument, subId, workSource);
1177 }
1178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001179 Message msg = mMainThreadHandler.obtainMessage(command, request);
1180 msg.sendToTarget();
1181
1182 // Wait for the request to complete
1183 synchronized (request) {
1184 while (request.result == null) {
1185 try {
1186 request.wait();
1187 } catch (InterruptedException e) {
1188 // Do nothing, go back and wait until the request is complete
1189 }
1190 }
1191 }
1192 return request.result;
1193 }
1194
1195 /**
1196 * Asynchronous ("fire and forget") version of sendRequest():
1197 * Posts the specified command to be executed on the main thread, and
1198 * returns immediately.
1199 * @see #sendRequest
1200 */
1201 private void sendRequestAsync(int command) {
1202 mMainThreadHandler.sendEmptyMessage(command);
1203 }
1204
1205 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001206 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001207 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001208 */
1209 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001210 sendRequestAsync(command, argument, null, null);
1211 }
1212
1213 /**
1214 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1215 * @see {@link #sendRequest(int,Object)}
1216 */
1217 private void sendRequestAsync(
1218 int command, Object argument, Phone phone, WorkSource workSource) {
1219 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001220 Message msg = mMainThreadHandler.obtainMessage(command, request);
1221 msg.sendToTarget();
1222 }
1223
1224 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 * Initialize the singleton PhoneInterfaceManager instance.
1226 * This is only done once, at startup, from PhoneApp.onCreate().
1227 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001228 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 synchronized (PhoneInterfaceManager.class) {
1230 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001231 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 } else {
1233 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1234 }
1235 return sInstance;
1236 }
1237 }
1238
1239 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001240 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 mApp = app;
1242 mPhone = phone;
1243 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();
Andrew Leedf14ead2014-10-17 14:22:52 -07001247 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001248 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001249 mSubscriptionController = SubscriptionController.getInstance();
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
1256 private void publish() {
1257 if (DBG) log("publish: " + this);
1258
1259 ServiceManager.addService("phone", this);
1260 }
1261
Stuart Scott584921c2015-01-15 17:10:34 -08001262 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001263 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1264 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001265 }
1266
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001267 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1268 Phone phone = getPhoneFromRequest(request);
1269 return phone == null ? null :
1270 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1271 }
1272
Wink Saville36469e72014-06-11 15:17:00 -07001273 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001274 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001275 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277
1278 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001279 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001280 }
1281
Wink Savilleb564aae2014-10-23 10:18:09 -07001282 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 if (DBG) log("dial: " + number);
1284 // No permission check needed here: This is just a wrapper around the
1285 // ACTION_DIAL intent, which is available to any app since it puts up
1286 // the UI before it does anything.
1287
Malcolm Chend965c8b2018-02-28 15:00:40 -08001288 final long identity = Binder.clearCallingIdentity();
1289 try {
1290 String url = createTelUrl(number);
1291 if (url == null) {
1292 return;
1293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294
Malcolm Chend965c8b2018-02-28 15:00:40 -08001295 // PENDING: should we just silently fail if phone is offhook or ringing?
1296 PhoneConstants.State state = mCM.getState(subId);
1297 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1298 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1299 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1300 mApp.startActivity(intent);
1301 }
1302 } finally {
1303 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 }
1305 }
1306
1307 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
1310
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 if (DBG) log("call: " + number);
1313
1314 // This is just a wrapper around the ACTION_CALL intent, but we still
1315 // need to do a permission check since we're calling startActivity()
1316 // from the context of the phone app.
1317 enforceCallPermission();
1318
1319 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1320 != AppOpsManager.MODE_ALLOWED) {
1321 return;
1322 }
1323
Malcolm Chend965c8b2018-02-28 15:00:40 -08001324 final long identity = Binder.clearCallingIdentity();
1325 try {
1326 String url = createTelUrl(number);
1327 if (url == null) {
1328 return;
1329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330
Malcolm Chend965c8b2018-02-28 15:00:40 -08001331 boolean isValid = false;
1332 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1333 if (slist != null) {
1334 for (SubscriptionInfo subInfoRecord : slist) {
1335 if (subInfoRecord.getSubscriptionId() == subId) {
1336 isValid = true;
1337 break;
1338 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001339 }
Wink Saville08874612014-08-31 19:19:58 -07001340 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001341 if (!isValid) {
1342 return;
1343 }
Wink Saville08874612014-08-31 19:19:58 -07001344
Malcolm Chend965c8b2018-02-28 15:00:40 -08001345 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1346 intent.putExtra(SUBSCRIPTION_KEY, subId);
1347 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1348 mApp.startActivity(intent);
1349 } finally {
1350 Binder.restoreCallingIdentity(identity);
1351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001352 }
1353
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001354 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001355 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001356 }
1357
Wink Savilleb564aae2014-10-23 10:18:09 -07001358 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001359 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001360 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1361 }
1362
1363 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001365 }
1366
Wink Savilleb564aae2014-10-23 10:18:09 -07001367 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001368 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001369 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1370 }
1371
1372 /** {@hide} */
1373 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001379
1380 final long identity = Binder.clearCallingIdentity();
1381 try {
1382 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1383 checkSimPin.start();
1384 return checkSimPin.unlockSim(null, pin);
1385 } finally {
1386 Binder.restoreCallingIdentity(identity);
1387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 }
1389
Wink Saville9de0f752013-10-22 19:04:03 -07001390 /** {@hide} */
1391 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001392 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001393 }
1394
Wink Savilleb564aae2014-10-23 10:18:09 -07001395 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001397
1398 final long identity = Binder.clearCallingIdentity();
1399 try {
1400 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1401 checkSimPuk.start();
1402 return checkSimPuk.unlockSim(puk, pin);
1403 } finally {
1404 Binder.restoreCallingIdentity(identity);
1405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 }
1407
1408 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001409 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 * a synchronous one.
1411 */
1412 private static class UnlockSim extends Thread {
1413
1414 private final IccCard mSimCard;
1415
1416 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001417 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1418 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419
1420 // For replies from SimCard interface
1421 private Handler mHandler;
1422
1423 // For async handler to identify request type
1424 private static final int SUPPLY_PIN_COMPLETE = 100;
1425
1426 public UnlockSim(IccCard simCard) {
1427 mSimCard = simCard;
1428 }
1429
1430 @Override
1431 public void run() {
1432 Looper.prepare();
1433 synchronized (UnlockSim.this) {
1434 mHandler = new Handler() {
1435 @Override
1436 public void handleMessage(Message msg) {
1437 AsyncResult ar = (AsyncResult) msg.obj;
1438 switch (msg.what) {
1439 case SUPPLY_PIN_COMPLETE:
1440 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1441 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001442 mRetryCount = msg.arg1;
1443 if (ar.exception != null) {
1444 if (ar.exception instanceof CommandException &&
1445 ((CommandException)(ar.exception)).getCommandError()
1446 == CommandException.Error.PASSWORD_INCORRECT) {
1447 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1448 } else {
1449 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1450 }
1451 } else {
1452 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 mDone = true;
1455 UnlockSim.this.notifyAll();
1456 }
1457 break;
1458 }
1459 }
1460 };
1461 UnlockSim.this.notifyAll();
1462 }
1463 Looper.loop();
1464 }
1465
1466 /*
1467 * Use PIN or PUK to unlock SIM card
1468 *
1469 * If PUK is null, unlock SIM card with PIN
1470 *
1471 * If PUK is not null, unlock SIM card with PUK and set PIN code
1472 */
Wink Saville9de0f752013-10-22 19:04:03 -07001473 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
1475 while (mHandler == null) {
1476 try {
1477 wait();
1478 } catch (InterruptedException e) {
1479 Thread.currentThread().interrupt();
1480 }
1481 }
1482 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1483
1484 if (puk == null) {
1485 mSimCard.supplyPin(pin, callback);
1486 } else {
1487 mSimCard.supplyPuk(puk, pin, callback);
1488 }
1489
1490 while (!mDone) {
1491 try {
1492 Log.d(LOG_TAG, "wait for done");
1493 wait();
1494 } catch (InterruptedException e) {
1495 // Restore the interrupted status
1496 Thread.currentThread().interrupt();
1497 }
1498 }
1499 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001500 int[] resultArray = new int[2];
1501 resultArray[0] = mResult;
1502 resultArray[1] = mRetryCount;
1503 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 }
1505 }
1506
1507 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001509
1510 }
1511
Wink Savilleb564aae2014-10-23 10:18:09 -07001512 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 // No permission check needed here: this call is harmless, and it's
1514 // needed for the ServiceState.requestStateUpdate() call (which is
1515 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001516 final long identity = Binder.clearCallingIdentity();
1517 try {
1518 final Phone phone = getPhone(subId);
1519 if (phone != null) {
1520 phone.updateServiceLocation();
1521 }
1522 } finally {
1523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
1526
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001527 @Override
1528 public boolean isRadioOn(String callingPackage) {
1529 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001530 }
1531
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001532 @Override
1533 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001535 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001536 return false;
1537 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001538
1539 final long identity = Binder.clearCallingIdentity();
1540 try {
1541 return isRadioOnForSubscriber(subId);
1542 } finally {
1543 Binder.restoreCallingIdentity(identity);
1544 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001545 }
1546
1547 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001548 final long identity = Binder.clearCallingIdentity();
1549 try {
1550 final Phone phone = getPhone(subId);
1551 if (phone != null) {
1552 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1553 } else {
1554 return false;
1555 }
1556 } finally {
1557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
1560
1561 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001562 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
Wink Saville36469e72014-06-11 15:17:00 -07001564
Wink Savilleb564aae2014-10-23 10:18:09 -07001565 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001567
1568 final long identity = Binder.clearCallingIdentity();
1569 try {
1570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1573 }
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 }
Wink Saville36469e72014-06-11 15:17:00 -07001577 }
1578
1579 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001580 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001581 }
1582
Wink Savilleb564aae2014-10-23 10:18:09 -07001583 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001584 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001585
1586 final long identity = Binder.clearCallingIdentity();
1587 try {
1588 final Phone phone = getPhone(subId);
1589 if (phone == null) {
1590 return false;
1591 }
1592 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1593 toggleRadioOnOffForSubscriber(subId);
1594 }
1595 return true;
1596 } finally {
1597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
Wink Saville36469e72014-06-11 15:17:00 -07001600
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001601 public boolean needMobileRadioShutdown() {
1602 /*
1603 * If any of the Radios are available, it will need to be
1604 * shutdown. So return true if any Radio is available.
1605 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001606 final long identity = Binder.clearCallingIdentity();
1607 try {
1608 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1609 Phone phone = PhoneFactory.getPhone(i);
1610 if (phone != null && phone.isRadioAvailable()) return true;
1611 }
1612 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1613 return false;
1614 } finally {
1615 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001616 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001617 }
1618
Malcolm Chend965c8b2018-02-28 15:00:40 -08001619 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001620 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001621 enforceModifyPermission();
1622
1623 final long identity = Binder.clearCallingIdentity();
1624 try {
1625 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1626 logv("Shutting down Phone " + i);
1627 shutdownRadioUsingPhoneId(i);
1628 }
1629 } finally {
1630 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 }
1632 }
1633
1634 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001635 Phone phone = PhoneFactory.getPhone(phoneId);
1636 if (phone != null && phone.isRadioAvailable()) {
1637 phone.shutdownRadio();
1638 }
1639 }
1640
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001642 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001643
1644 final long identity = Binder.clearCallingIdentity();
1645 try {
1646 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1647 if (defaultPhone != null) {
1648 defaultPhone.setRadioPower(turnOn);
1649 return true;
1650 } else {
1651 loge("There's no default phone.");
1652 return false;
1653 }
1654 } finally {
1655 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001656 }
Wink Saville36469e72014-06-11 15:17:00 -07001657 }
1658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001661
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 final Phone phone = getPhone(subId);
1665 if (phone != null) {
1666 phone.setRadioPower(turnOn);
1667 return true;
1668 } else {
1669 return false;
1670 }
1671 } finally {
1672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 }
1675
Wink Saville36469e72014-06-11 15:17:00 -07001676 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 public boolean enableDataConnectivity() {
1679 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 int subId = mSubscriptionController.getDefaultDataSubId();
1684 final Phone phone = getPhone(subId);
1685 if (phone != null) {
1686 phone.setUserDataEnabled(true);
1687 return true;
1688 } else {
1689 return false;
1690 }
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
1695
Wink Saville36469e72014-06-11 15:17:00 -07001696 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 public boolean disableDataConnectivity() {
1699 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001700
1701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 int subId = mSubscriptionController.getDefaultDataSubId();
1704 final Phone phone = getPhone(subId);
1705 if (phone != null) {
1706 phone.setUserDataEnabled(false);
1707 return true;
1708 } else {
1709 return false;
1710 }
1711 } finally {
1712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
1715
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001717 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 final Phone phone = getPhone(subId);
1721 if (phone != null) {
1722 return phone.isDataAllowed();
1723 } else {
1724 return false;
1725 }
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 }
1730
1731 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001732 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001733 }
1734
pkanwarae03a6b2016-11-06 20:37:09 -08001735 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001736 enforceCallPermission();
1737
1738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1741 return;
1742 }
1743 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1744 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
1747 }
pkanwar32d516d2016-10-14 19:37:38 -07001748 };
1749
Wink Savilleb564aae2014-10-23 10:18:09 -07001750 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1756 return false;
1757 }
1758 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001765 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001768 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 Phone phone = PhoneFactory.getPhone(slotIndex);
1772 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1773 PhoneConstantConversions.convertCallState(phone.getState());
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
1776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Sanket Padawe356d7632015-06-22 14:03:32 -07001779 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001781 final long identity = Binder.clearCallingIdentity();
1782 try {
1783 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1784 if (phone != null) {
1785 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1786 } else {
1787 return PhoneConstantConversions.convertDataState(
1788 PhoneConstants.DataState.DISCONNECTED);
1789 }
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Sanket Padawe356d7632015-06-22 14:03:32 -07001795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1800 if (phone != null) {
1801 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1802 } else {
1803 return TelephonyManager.DATA_ACTIVITY_NONE;
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
1810 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001811 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001812 mPhone.getContext().getSystemService(AppOpsManager.class)
1813 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001814 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001815 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001816 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 }
1818
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001819 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 if (DBG_LOC) log("getCellLocation: is active user");
1823 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001824 int subId = mSubscriptionController.getDefaultDataSubId();
1825 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1826 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001827 return data;
1828 } finally {
1829 Binder.restoreCallingIdentity(identity);
1830 }
Svetoslav64fad262015-04-14 14:35:21 -07001831 }
1832
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001834 public String getNetworkCountryIsoForPhone(int phoneId) {
1835 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1836 // registered cell info, so return a NULL country instead.
1837 final long identity = Binder.clearCallingIdentity();
1838 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001839 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1840 // Get default phone in this case.
1841 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1842 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001843 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001844 // Todo: fix this when we can get the actual cellular network info when the device
1845 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001846 if (TelephonyManager.NETWORK_TYPE_IWLAN
1847 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1848 return "";
1849 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001850 Phone phone = PhoneFactory.getPhone(phoneId);
1851 if (phone != null) {
1852 ServiceStateTracker sst = phone.getServiceStateTracker();
1853 if (sst != null) {
1854 LocaleTracker lt = sst.getLocaleTracker();
1855 if (lt != null) {
1856 return lt.getCurrentCountry();
1857 }
1858 }
1859 }
1860 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001861 } finally {
1862 Binder.restoreCallingIdentity(identity);
1863 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001864 }
1865
1866 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001868 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001869 }
1870
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001872 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 mApp.enforceCallingOrSelfPermission(
1874 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001875
1876 final long identity = Binder.clearCallingIdentity();
1877 try {
1878 final Phone phone = getPhone(subId);
1879 if (phone != null) {
1880 phone.enableLocationUpdates();
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
1887 @Override
1888 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001889 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001893 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 mApp.enforceCallingOrSelfPermission(
1895 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
1901 phone.disableLocationUpdates();
1902 }
1903 } finally {
1904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 }
1907
Nathan Harold31d7ff32018-10-15 20:20:30 -07001908 /**
1909 * Returns the target SDK version number for a given package name.
1910 *
1911 * @return target SDK if the package is found or INT_MAX.
1912 */
1913 private int getTargetSdk(String packageName) {
1914 try {
1915 final ApplicationInfo ai =
1916 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1917 if (ai != null) return ai.targetSdkVersion;
1918 } catch (PackageManager.NameNotFoundException unexpected) {
1919 }
1920 return Integer.MAX_VALUE;
1921 }
1922
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 @Override
1924 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001925 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1926 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001927 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1928 throw new SecurityException(
1929 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1930 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001931
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1933 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1934 return null;
1935 }
Svetoslav64fad262015-04-14 14:35:21 -07001936
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001937 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938
Nathan Haroldf180aac2018-06-01 18:43:55 -07001939 List<CellInfo> info = getAllCellInfo(callingPackage);
1940 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941
Nathan Haroldf180aac2018-06-01 18:43:55 -07001942 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1943 for (CellInfo ci : info) {
1944 if (ci instanceof CellInfoGsm) {
1945 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1946 } else if (ci instanceof CellInfoWcdma) {
1947 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001950 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 }
1952
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001953 private List<CellInfo> getCachedCellInfo() {
1954 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1955 for (Phone phone : PhoneFactory.getPhones()) {
1956 List<CellInfo> info = phone.getAllCellInfo();
1957 if (info != null) cellInfos.addAll(info);
1958 }
1959 return cellInfos;
1960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961
1962 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001963 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001964 mPhone.getContext().getSystemService(AppOpsManager.class)
1965 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001966 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001967 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001968 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
1970
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001971 final int targetSdk = getTargetSdk(callingPackage);
1972 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1973 return getCachedCellInfo();
1974 }
1975
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001976 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001977 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001978 final long identity = Binder.clearCallingIdentity();
1979 try {
1980 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1981 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001982 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001983 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001984 if (info != null) cellInfos.addAll(info);
1985 }
1986 return cellInfos;
1987 } finally {
1988 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990 }
1991
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001992 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001993 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1994 requestCellInfoUpdateInternal(
1995 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
1996 }
1997
1998 @Override
1999 public void requestCellInfoUpdateWithWorkSource(
2000 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2001 enforceModifyPermission();
2002 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2003 }
2004
2005 private void requestCellInfoUpdateInternal(
2006 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2007 mPhone.getContext().getSystemService(AppOpsManager.class)
2008 .checkPackage(Binder.getCallingUid(), callingPackage);
2009 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2010 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
2011 return;
2012 }
2013
2014 final Phone phone = getPhone(subId);
2015 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2016
2017 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2018 }
2019
2020 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002022 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002024
2025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 mPhone.setCellInfoListRate(rateInMillis, workSource);
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
2030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Shishir Agrawala9f32182016-04-12 12:00:16 -07002033 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002034 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002035 Phone phone = PhoneFactory.getPhone(slotIndex);
2036 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002037 return null;
2038 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002039 int subId = phone.getSubId();
2040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2041 mApp, subId, callingPackage, "getImeiForSlot")) {
2042 return null;
2043 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002044
2045 final long identity = Binder.clearCallingIdentity();
2046 try {
2047 return phone.getImei();
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
2050 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002051 }
2052
2053 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002054 public String getTypeAllocationCodeForSlot(int slotIndex) {
2055 Phone phone = PhoneFactory.getPhone(slotIndex);
2056 String tac = null;
2057 if (phone != null) {
2058 String imei = phone.getImei();
2059 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2060 }
2061 return tac;
2062 }
2063
2064 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002065 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002066 Phone phone = PhoneFactory.getPhone(slotIndex);
2067 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002068 return null;
2069 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002070 int subId = phone.getSubId();
2071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2072 mApp, subId, callingPackage, "getMeidForSlot")) {
2073 return null;
2074 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 return phone.getMeid();
2079 } finally {
2080 Binder.restoreCallingIdentity(identity);
2081 }
Jack Yu2af8d712017-03-15 17:14:14 -07002082 }
2083
2084 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002085 public String getManufacturerCodeForSlot(int slotIndex) {
2086 Phone phone = PhoneFactory.getPhone(slotIndex);
2087 String manufacturerCode = null;
2088 if (phone != null) {
2089 String meid = phone.getMeid();
2090 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2091 }
2092 return manufacturerCode;
2093 }
2094
2095 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002096 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002097 Phone phone = PhoneFactory.getPhone(slotIndex);
2098 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002099 return null;
2100 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002101 int subId = phone.getSubId();
2102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2103 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2104 return null;
2105 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002106
2107 final long identity = Binder.clearCallingIdentity();
2108 try {
2109 return phone.getDeviceSvn();
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
2112 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002113 }
2114
fionaxu43304da2017-11-27 22:51:16 -08002115 @Override
2116 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 final Phone phone = getPhone(subId);
2120 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2121 } finally {
2122 Binder.restoreCallingIdentity(identity);
2123 }
fionaxu43304da2017-11-27 22:51:16 -08002124 }
2125
2126 @Override
2127 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002128 final long identity = Binder.clearCallingIdentity();
2129 try {
2130 final Phone phone = getPhone(subId);
2131 return phone == null ? null : phone.getCarrierName();
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
2134 }
fionaxu43304da2017-11-27 22:51:16 -08002135 }
2136
calvinpaneed9ae82018-11-01 19:43:06 +08002137 @Override
2138 public int getSubscriptionMNOCarrierId(int subId) {
2139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 final Phone phone = getPhone(subId);
2142 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
2145 }
2146 }
2147
chen xuc93cc282018-11-04 17:17:00 -08002148 @Override
2149 public int getSubscriptionPreciseCarrierId(int subId) {
2150 final long identity = Binder.clearCallingIdentity();
2151 try {
2152 final Phone phone = getPhone(subId);
2153 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2154 : phone.getPreciseCarrierId();
2155 } finally {
2156 Binder.restoreCallingIdentity(identity);
2157 }
2158 }
2159
2160 @Override
2161 public String getSubscriptionPreciseCarrierName(int subId) {
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 final Phone phone = getPhone(subId);
2165 return phone == null ? null : phone.getPreciseCarrierName();
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
2169 }
2170
chen xu02581692018-11-11 19:03:44 -08002171 @Override
2172 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) {
2173 final Phone phone = PhoneFactory.getPhone(slotIndex);
2174 if (phone == null) {
2175 return TelephonyManager.UNKNOWN_CARRIER_ID;
2176 }
2177 final long identity = Binder.clearCallingIdentity();
2178 try {
2179 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
2182 }
2183 }
2184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 //
2186 // Internal helper methods.
2187 //
2188
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002189 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2191 *
2192 * @throws SecurityException if the caller does not have the required permission
2193 */
2194 private void enforceModifyPermission() {
2195 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2196 }
2197
2198 /**
2199 * Make sure the caller has the CALL_PHONE permission.
2200 *
2201 * @throws SecurityException if the caller does not have the required permission
2202 */
2203 private void enforceCallPermission() {
2204 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2205 }
2206
Stuart Scott8eef64f2015-04-08 15:13:54 -07002207 private void enforceConnectivityInternalPermission() {
2208 mApp.enforceCallingOrSelfPermission(
2209 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2210 "ConnectivityService");
2211 }
2212
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 private String createTelUrl(String number) {
2214 if (TextUtils.isEmpty(number)) {
2215 return null;
2216 }
2217
Jake Hambye994d462014-02-03 13:10:13 -08002218 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
Ihab Awadf9e92732013-12-05 18:02:52 -08002221 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2223 }
2224
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002225 private static void logv(String msg) {
2226 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2227 }
2228
Ihab Awadf9e92732013-12-05 18:02:52 -08002229 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2231 }
2232
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002235 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002236 }
2237
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002239 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002240 final long identity = Binder.clearCallingIdentity();
2241 try {
2242 final Phone phone = PhoneFactory.getPhone(slotIndex);
2243 if (phone == null) {
2244 return PhoneConstants.PHONE_TYPE_NONE;
2245 } else {
2246 return phone.getPhoneType();
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
2253 /**
2254 * Returns the CDMA ERI icon index to display
2255 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002256 @Override
2257 public int getCdmaEriIconIndex(String callingPackage) {
2258 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002259 }
2260
Sanket Padawe356d7632015-06-22 14:03:32 -07002261 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002264 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002265 return -1;
2266 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002267
2268 final long identity = Binder.clearCallingIdentity();
2269 try {
2270 final Phone phone = getPhone(subId);
2271 if (phone != null) {
2272 return phone.getCdmaEriIconIndex();
2273 } else {
2274 return -1;
2275 }
2276 } finally {
2277 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
2281 /**
2282 * Returns the CDMA ERI icon mode,
2283 * 0 - ON
2284 * 1 - FLASHING
2285 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002286 @Override
2287 public int getCdmaEriIconMode(String callingPackage) {
2288 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002289 }
2290
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002292 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002294 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002295 return -1;
2296 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002297
2298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 final Phone phone = getPhone(subId);
2301 if (phone != null) {
2302 return phone.getCdmaEriIconMode();
2303 } else {
2304 return -1;
2305 }
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
2311 /**
2312 * Returns the CDMA ERI text,
2313 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 @Override
2315 public String getCdmaEriText(String callingPackage) {
2316 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002317 }
2318
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002320 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002323 return null;
2324 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002325
2326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 final Phone phone = getPhone(subId);
2329 if (phone != null) {
2330 return phone.getCdmaEriText();
2331 } else {
2332 return null;
2333 }
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 }
2338
2339 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002340 * Returns the CDMA MDN.
2341 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002343 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2345 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002346
2347 final long identity = Binder.clearCallingIdentity();
2348 try {
2349 final Phone phone = getPhone(subId);
2350 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2351 return phone.getLine1Number();
2352 } else {
2353 return null;
2354 }
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002357 }
2358 }
2359
2360 /**
2361 * Returns the CDMA MIN.
2362 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002363 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002364 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2366 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002367
2368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 final Phone phone = getPhone(subId);
2371 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2372 return phone.getCdmaMin();
2373 } else {
2374 return null;
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002378 }
2379 }
2380
Hall Liud892bec2018-11-30 14:51:45 -08002381 @Override
2382 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2383 INumberVerificationCallback callback, String callingPackage) {
2384 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2385 != PERMISSION_GRANTED) {
2386 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2387 }
2388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2389
2390 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2391 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2392 throw new SecurityException("Calling package must be configured in the device config");
2393 }
2394
2395 if (range == null) {
2396 throw new NullPointerException("Range must be non-null");
2397 }
2398
2399 timeoutMillis = Math.min(timeoutMillis,
2400 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2401
2402 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2403 }
2404
Junda Liuca05d5d2014-08-14 22:36:34 -07002405 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 * Returns true if CDMA provisioning needs to run.
2407 */
2408 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 return mPhone.needsOtaServiceProvisioning();
2412 } finally {
2413 Binder.restoreCallingIdentity(identity);
2414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 }
2416
2417 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002418 * Sets the voice mail number of a given subId.
2419 */
2420 @Override
2421 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002422 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002423
2424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2427 new Pair<String, String>(alphaTag, number), new Integer(subId));
2428 return success;
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
2431 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002432 }
2433
Ta-wei Yen87c49842016-05-13 21:19:52 -07002434 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002435 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2436 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2437 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2438 if (!TextUtils.equals(callingPackage, systemDialer)) {
2439 throw new SecurityException("caller must be system dialer");
2440 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002441
2442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2445 if (phoneAccountHandle == null) {
2446 return null;
2447 }
2448 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002451 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002452 }
2453
2454 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002455 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002458 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002459 return null;
2460 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002461
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002462 final long identity = Binder.clearCallingIdentity();
2463 try {
2464 return RemoteVvmTaskManager
2465 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
2468 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002469 }
2470
2471 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002472 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2473 VisualVoicemailSmsFilterSettings settings) {
2474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002475
2476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2479 mPhone.getContext(), callingPackage, subId, settings);
2480 } finally {
2481 Binder.restoreCallingIdentity(identity);
2482 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002483 }
2484
2485 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002486 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2492 mPhone.getContext(), callingPackage, subId);
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
2495 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002496 }
2497
2498 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002499 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2500 String callingPackage, int subId) {
2501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002502
2503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2506 mPhone.getContext(), callingPackage, subId);
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
2509 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002510 }
2511
2512 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002513 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002514 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002515
2516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2519 mPhone.getContext(), subId);
2520 } finally {
2521 Binder.restoreCallingIdentity(identity);
2522 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002523 }
2524
2525 @Override
2526 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2527 String number, int port, String text, PendingIntent sentIntent) {
2528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002529 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002530 enforceSendSmsPermission();
2531 // Make the calls as the phone process.
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2535 if (port == 0) {
2536 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2537 sentIntent, null, false);
2538 } else {
2539 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2540 smsManager.sendDataMessageWithSelfPermissions(number, null,
2541 (short) port, data, sentIntent, null);
2542 }
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002546 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002547 /**
fionaxu0152e512016-11-14 13:36:14 -08002548 * Sets the voice activation state of a given subId.
2549 */
2550 @Override
2551 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2553 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 final Phone phone = getPhone(subId);
2558 if (phone != null) {
2559 phone.setVoiceActivationState(activationState);
2560 } else {
2561 loge("setVoiceActivationState fails with invalid subId: " + subId);
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002565 }
2566 }
2567
2568 /**
2569 * Sets the data activation state of a given subId.
2570 */
2571 @Override
2572 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2574 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002575
2576 final long identity = Binder.clearCallingIdentity();
2577 try {
2578 final Phone phone = getPhone(subId);
2579 if (phone != null) {
2580 phone.setDataActivationState(activationState);
2581 } else {
2582 loge("setVoiceActivationState fails with invalid subId: " + subId);
2583 }
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002586 }
2587 }
2588
2589 /**
2590 * Returns the voice activation state of a given subId.
2591 */
2592 @Override
2593 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002594 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002595
fionaxu0152e512016-11-14 13:36:14 -08002596 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 if (phone != null) {
2600 return phone.getVoiceActivationState();
2601 } else {
2602 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002606 }
2607 }
2608
2609 /**
2610 * Returns the data activation state of a given subId.
2611 */
2612 @Override
2613 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002614 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002615
fionaxu0152e512016-11-14 13:36:14 -08002616 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 if (phone != null) {
2620 return phone.getDataActivationState();
2621 } else {
2622 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002626 }
2627 }
2628
2629 /**
Wink Saville36469e72014-06-11 15:17:00 -07002630 * Returns the unread count of voicemails for a subId
2631 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002633 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2635 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2636 return 0;
2637 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 final Phone phone = getPhone(subId);
2641 if (phone != null) {
2642 return phone.getVoiceMessageCount();
2643 } else {
2644 return 0;
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 }
2650
2651 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002652 * returns true, if the device is in a state where both voice and data
2653 * are supported simultaneously. This can change based on location or network condition.
2654 */
2655 @Override
2656 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002664 }
2665
2666 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002667 * Send the dialer code if called from the current default dialer or the caller has
2668 * carrier privilege.
2669 * @param inputCode The dialer code to send
2670 */
2671 @Override
2672 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2674 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2675 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002676 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2677 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002678 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 mPhone.sendDialerSpecialCode(inputCode);
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
fionaxu235cc5e2017-03-06 22:25:57 -08002686 }
2687
2688 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002689 * Returns the data network type.
2690 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 *
2692 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2693 */
2694 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002695 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 final Phone phone = getPhone(getDefaultSubscription());
2699 if (phone != null) {
2700 return phone.getServiceState().getDataNetworkType();
2701 } else {
2702 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002706 }
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
Pengquan Meng0c05b502018-09-06 09:59:22 -07002709 @Override
2710 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002711 if (!isActiveSubscription(subId)) {
2712 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2713 }
2714
Pengquan Meng0c05b502018-09-06 09:59:22 -07002715 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2716 }
2717
Brad Ebinger4c460712018-10-01 10:40:55 -07002718 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002719 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2720 throws RemoteException {
2721 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2723 final long token = Binder.clearCallingIdentity();
2724 try {
2725 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2726 .addRegistrationCallbackForSubscription(c, subId);
2727 } finally {
2728 Binder.restoreCallingIdentity(token);
2729 }
2730 }
2731
2732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002733 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2734 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2736 Binder.withCleanCallingIdentity(() ->
2737 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2738 .removeRegistrationCallbackForSubscription(c, subId));
2739 }
2740
2741 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002742 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2743 throws RemoteException {
2744 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2746 final long token = Binder.clearCallingIdentity();
2747 try {
2748 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2749 .addCapabilitiesCallbackForSubscription(c, subId);
2750 } finally {
2751 Binder.restoreCallingIdentity(token);
2752 }
2753 }
2754
2755 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002756 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2757 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2759 Binder.withCleanCallingIdentity(() ->
2760 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2761 .removeCapabilitiesCallbackForSubscription(c, subId));
2762 }
2763
2764 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002765 public boolean isCapable(int subId, int capability, int regTech) {
2766 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002767 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2768 final long token = Binder.clearCallingIdentity();
2769 try {
2770 return ImsManager.getInstance(mPhone.getContext(),
2771 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2772 } catch (ImsException e) {
2773 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2774 return false;
2775 } finally {
2776 Binder.restoreCallingIdentity(token);
2777 }
2778 }
2779
2780 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002781 public boolean isAvailable(int subId, int capability, int regTech) {
2782 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002783 final long token = Binder.clearCallingIdentity();
2784 try {
2785 Phone phone = getPhone(subId);
2786 if (phone == null) return false;
2787 return phone.isImsCapabilityAvailable(capability, regTech);
2788 } finally {
2789 Binder.restoreCallingIdentity(token);
2790 }
2791 }
2792
2793 @Override
2794 public boolean isAdvancedCallingSettingEnabled(int subId) {
2795 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2797 final long token = Binder.clearCallingIdentity();
2798 try {
2799 return ImsManager.getInstance(mPhone.getContext(),
2800 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2801 } finally {
2802 Binder.restoreCallingIdentity(token);
2803 }
2804 }
2805
2806 @Override
2807 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2809 "setAdvancedCallingSetting");
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2813 ImsManager.getInstance(mPhone.getContext(),
2814 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
2818 }
2819
2820 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002821 public boolean isVtSettingEnabled(int subId) {
2822 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2826 return ImsManager.getInstance(mPhone.getContext(),
2827 getSlotIndexOrException(subId)).isVtEnabledByUser();
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
2831 }
2832
2833 @Override
2834 public void setVtSetting(int subId, boolean isEnabled) {
2835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2836 "setVtSetting");
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2840 ImsManager.getInstance(mPhone.getContext(),
2841 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
2845 }
2846
2847 @Override
2848 public boolean isVoWiFiSettingEnabled(int subId) {
2849 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2853 return ImsManager.getInstance(mPhone.getContext(),
2854 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
2857 }
2858 }
2859
2860 @Override
2861 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2863 "setVoWiFiSetting");
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2867 ImsManager.getInstance(mPhone.getContext(),
2868 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
2872 }
2873
2874 @Override
2875 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2876 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2880 return ImsManager.getInstance(mPhone.getContext(),
2881 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
2885 }
2886
2887 @Override
2888 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2890 "setVoWiFiRoamingSetting");
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2894 ImsManager.getInstance(mPhone.getContext(),
2895 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
2899 }
2900
2901 @Override
2902 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2904 "setVoWiFiNonPersistent");
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2908 ImsManager.getInstance(mPhone.getContext(),
2909 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
2913 }
2914
2915 @Override
2916 public int getVoWiFiModeSetting(int subId) {
2917 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2921 return ImsManager.getInstance(mPhone.getContext(),
2922 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
2925 }
2926 }
2927
2928 @Override
2929 public void setVoWiFiModeSetting(int subId, int mode) {
2930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2931 "setVoWiFiModeSetting");
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2935 ImsManager.getInstance(mPhone.getContext(),
2936 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 }
2941
2942 @Override
2943 public int getVoWiFiRoamingModeSetting(int subId) {
2944 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2948 return ImsManager.getInstance(mPhone.getContext(),
2949 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
2952 }
2953 }
2954
2955 @Override
2956 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2958 "setVoWiFiRoamingModeSetting");
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2962 ImsManager.getInstance(mPhone.getContext(),
2963 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
2967 }
2968
2969 @Override
2970 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2972 "setRttCapabilityEnabled");
2973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2976 ImsManager.getInstance(mPhone.getContext(),
2977 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 @Override
2984 public boolean isTtyOverVolteEnabled(int subId) {
2985 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2989 return ImsManager.getInstance(mPhone.getContext(),
2990 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 }
2995
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002996 @Override
2997 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2998 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3002 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3003 .getConfigInterface().addConfigCallback(callback);
3004 } catch (ImsException e) {
3005 throw new IllegalArgumentException(e.getMessage());
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
3012 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3013 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3017 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3018 .getConfigInterface().removeConfigCallback(callback);
3019 } catch (ImsException e) {
3020 throw new IllegalArgumentException(e.getMessage());
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
3024 }
3025
3026 @Override
3027 public int getImsProvisioningInt(int subId, int key) {
3028 enforceReadPrivilegedPermission("getImsProvisioningInt");
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3032 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3033 .getConfigInterface().getConfigInt(key);
3034 } catch (ImsException e) {
3035 throw new IllegalArgumentException(e.getMessage());
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
3039 }
3040
3041 @Override
3042 public String getImsProvisioningString(int subId, int key) {
3043 enforceReadPrivilegedPermission("getImsProvisioningString");
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3047 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3048 .getConfigInterface().getConfigString(key);
3049 } catch (ImsException e) {
3050 throw new IllegalArgumentException(e.getMessage());
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
3057 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3059 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3063 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3064 .getConfigInterface().setConfig(key, value);
3065 } catch (ImsException e) {
3066 throw new IllegalArgumentException(e.getMessage());
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
3070 }
3071
3072 @Override
3073 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3075 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3079 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3080 .getConfigInterface().setConfig(key, value);
3081 } catch (ImsException e) {
3082 throw new IllegalArgumentException(e.getMessage());
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
3086 }
3087
Brad Ebinger4c460712018-10-01 10:40:55 -07003088 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3089 int slotId = SubscriptionManager.getSlotIndex(subId);
3090 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3091 throw new IllegalArgumentException("Invalid Subscription Id.");
3092 }
3093 return slotId;
3094 }
3095
Wink Saville36469e72014-06-11 15:17:00 -07003096 /**
3097 * Returns the network type for a subId
3098 */
3099 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003100 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003102 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003103 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3104 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003105
Malcolm Chend965c8b2018-02-28 15:00:40 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 final Phone phone = getPhone(subId);
3109 if (phone != null) {
3110 return phone.getServiceState().getDataNetworkType();
3111 } else {
3112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3113 }
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
3119 /**
3120 * Returns the data network type
3121 */
3122 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003123 public int getDataNetworkType(String callingPackage) {
3124 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003125 }
3126
3127 /**
3128 * Returns the data network type for a subId
3129 */
3130 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003131 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003133 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003134 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3135 }
3136
Malcolm Chend965c8b2018-02-28 15:00:40 -08003137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 final Phone phone = getPhone(subId);
3140 if (phone != null) {
3141 return phone.getServiceState().getDataNetworkType();
3142 } else {
3143 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3144 }
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149
3150 /**
Wink Saville36469e72014-06-11 15:17:00 -07003151 * Returns the Voice network type for a subId
3152 */
3153 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003154 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003156 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003157 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3158 }
3159
Malcolm Chend965c8b2018-02-28 15:00:40 -08003160 final long identity = Binder.clearCallingIdentity();
3161 try {
3162 final Phone phone = getPhone(subId);
3163 if (phone != null) {
3164 return phone.getServiceState().getVoiceNetworkType();
3165 } else {
3166 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3167 }
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 }
3172
3173 /**
3174 * @return true if a ICC card is present
3175 */
3176 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003177 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003178 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3179 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003180 }
3181
3182 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003183 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003184 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003186 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 final Phone phone = PhoneFactory.getPhone(slotIndex);
3190 if (phone != null) {
3191 return phone.getIccCard().hasIccCard();
3192 } else {
3193 return false;
3194 }
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 }
3199
3200 /**
3201 * Return if the current radio is LTE on CDMA. This
3202 * is a tri-state return value as for a period of time
3203 * the mode may be unknown.
3204 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003205 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003207 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003209 @Override
3210 public int getLteOnCdmaMode(String callingPackage) {
3211 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003212 }
3213
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003215 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003217 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003218 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3219 }
3220
Malcolm Chend965c8b2018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = getPhone(subId);
3224 if (phone == null) {
3225 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3226 } else {
3227 return phone.getLteOnCdmaMode();
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 }
Wink Saville36469e72014-06-11 15:17:00 -07003232 }
3233
3234 public void setPhone(Phone phone) {
3235 mPhone = phone;
3236 }
3237
3238 /**
3239 * {@hide}
3240 * Returns Default subId, 0 in the case of single standby.
3241 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003242 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003243 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003244 }
3245
Shishir Agrawala9f32182016-04-12 12:00:16 -07003246 private int getSlotForDefaultSubscription() {
3247 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3248 }
3249
Wink Savilleb564aae2014-10-23 10:18:09 -07003250 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003251 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003252 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003253
Pengquan Meng466e2482018-09-21 15:54:48 -07003254 private boolean isActiveSubscription(int subId) {
3255 return mSubscriptionController.isActiveSubId(subId);
3256 }
3257
Ihab Awadf2177b72013-11-25 13:33:23 -08003258 /**
3259 * @see android.telephony.TelephonyManager.WifiCallingChoices
3260 */
3261 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3265 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3266 getWhenToMakeWifiCallsDefaultPreference());
3267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003270 }
3271
3272 /**
3273 * @see android.telephony.TelephonyManager.WifiCallingChoices
3274 */
3275 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003276 final long identity = Binder.clearCallingIdentity();
3277 try {
3278 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3279 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3280 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003284 }
3285
Sailesh Nepald1e68152013-12-12 19:08:02 -08003286 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003287 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003288 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003289 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003290
Shishir Agrawal566b7612013-10-28 14:41:00 -07003291 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003292 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3293 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3295 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003296 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003297
Malcolm Chend965c8b2018-02-28 15:00:40 -08003298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 if (TextUtils.equals(ISDR_AID, aid)) {
3301 // Only allows LPA to open logical channel to ISD-R.
3302 ComponentInfo bestComponent =
3303 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3304 if (bestComponent == null
3305 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3306 loge("The calling package is not allowed to access ISD-R.");
3307 throw new SecurityException(
3308 "The calling package is not allowed to access ISD-R.");
3309 }
Derek Tan740e1672017-06-27 14:56:27 -07003310 }
Derek Tan740e1672017-06-27 14:56:27 -07003311
Malcolm Chend965c8b2018-02-28 15:00:40 -08003312 if (DBG) {
3313 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3314 }
3315 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3316 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3317 if (DBG) log("iccOpenLogicalChannel: " + response);
3318 return response;
3319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003322 }
3323
3324 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003325 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3327 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003328
Malcolm Chend965c8b2018-02-28 15:00:40 -08003329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3332 if (channel < 0) {
3333 return false;
3334 }
3335 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3336 if (DBG) log("iccCloseLogicalChannel: " + success);
3337 return success;
3338 } finally {
3339 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003340 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003341 }
3342
3343 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003344 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003345 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3347 mApp, subId, "iccTransmitApduLogicalChannel");
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) {
3352 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3353 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3354 + p3 + " data=" + data);
3355 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003356
Malcolm Chend965c8b2018-02-28 15:00:40 -08003357 if (channel < 0) {
3358 return "";
3359 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003360
Malcolm Chend965c8b2018-02-28 15:00:40 -08003361 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3362 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3363 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003364
Malcolm Chend965c8b2018-02-28 15:00:40 -08003365 // Append the returned status code to the end of the response payload.
3366 String s = Integer.toHexString(
3367 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3368 if (response.payload != null) {
3369 s = IccUtils.bytesToHexString(response.payload) + s;
3370 }
3371 return s;
3372 } finally {
3373 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003374 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003375 }
Jake Hambye994d462014-02-03 13:10:13 -08003376
Evan Charltonc66da362014-05-16 14:06:40 -07003377 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003378 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3379 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3381 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003383
Malcolm Chend965c8b2018-02-28 15:00:40 -08003384 final long identity = Binder.clearCallingIdentity();
3385 try {
3386 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3387 && TextUtils.equals(ISDR_AID, data)) {
3388 // Only allows LPA to select ISD-R.
3389 ComponentInfo bestComponent =
3390 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3391 if (bestComponent == null
3392 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3393 loge("The calling package is not allowed to select ISD-R.");
3394 throw new SecurityException(
3395 "The calling package is not allowed to select ISD-R.");
3396 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003397 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003398
Malcolm Chend965c8b2018-02-28 15:00:40 -08003399 if (DBG) {
3400 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3401 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3402 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003403
Malcolm Chend965c8b2018-02-28 15:00:40 -08003404 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3405 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3406 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003407
Malcolm Chend965c8b2018-02-28 15:00:40 -08003408 // Append the returned status code to the end of the response payload.
3409 String s = Integer.toHexString(
3410 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3411 if (response.payload != null) {
3412 s = IccUtils.bytesToHexString(response.payload) + s;
3413 }
3414 return s;
3415 } finally {
3416 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003417 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003418 }
3419
3420 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003421 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003422 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3424 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003425
Malcolm Chend965c8b2018-02-28 15:00:40 -08003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 if (DBG) {
3429 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3430 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3431 }
3432
3433 IccIoResult response =
3434 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3435 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3436 subId);
3437
3438 if (DBG) {
3439 log("Exchange SIM_IO [R]" + response);
3440 }
3441
3442 byte[] result = null;
3443 int length = 2;
3444 if (response.payload != null) {
3445 length = 2 + response.payload.length;
3446 result = new byte[length];
3447 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3448 } else {
3449 result = new byte[length];
3450 }
3451
3452 result[length - 1] = (byte) response.sw2;
3453 result[length - 2] = (byte) response.sw1;
3454 return result;
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003457 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003458 }
3459
Nathan Haroldb3014052017-01-25 15:57:32 -08003460 /**
3461 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3462 * on a particular subscription
3463 */
sqianb6e41952018-03-12 14:54:01 -07003464 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3466 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3467 return null;
3468 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 if (appType != TelephonyManager.APPTYPE_USIM
3473 && appType != TelephonyManager.APPTYPE_SIM) {
3474 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3475 return null;
3476 }
3477 Object response = sendRequest(
3478 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3479 if (response instanceof String[]) {
3480 return (String[]) response;
3481 }
3482 // Response is an Exception of some kind,
3483 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003484 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003485 } finally {
3486 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003487 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003488 }
3489
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003490 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003491 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3493 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003494
Malcolm Chend965c8b2018-02-28 15:00:40 -08003495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3498 if (response.payload == null) {
3499 return "";
3500 }
Evan Charltonc66da362014-05-16 14:06:40 -07003501
Malcolm Chend965c8b2018-02-28 15:00:40 -08003502 // Append the returned status code to the end of the response payload.
3503 String s = Integer.toHexString(
3504 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3505 s = IccUtils.bytesToHexString(response.payload) + s;
3506 return s;
3507 } finally {
3508 Binder.restoreCallingIdentity(identity);
3509 }
Evan Charltonc66da362014-05-16 14:06:40 -07003510 }
3511
Jake Hambye994d462014-02-03 13:10:13 -08003512 /**
3513 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3514 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3515 *
3516 * @param itemID the ID of the item to read
3517 * @return the NV item as a String, or null on error.
3518 */
3519 @Override
3520 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3523 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003524
3525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003528 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003529 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3530 return value;
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
Jake Hambye994d462014-02-03 13:10:13 -08003534 }
3535
3536 /**
3537 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3538 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3539 *
3540 * @param itemID the ID of the item to read
3541 * @param itemValue the value to write, as a String
3542 * @return true on success; false on any failure
3543 */
3544 @Override
3545 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003546 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3548 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3553 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003554 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003555 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3556 return success;
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
3559 }
Jake Hambye994d462014-02-03 13:10:13 -08003560 }
3561
3562 /**
3563 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3564 * Used for device configuration by some CDMA operators.
3565 *
3566 * @param preferredRoamingList byte array containing the new PRL
3567 * @return true on success; false on any failure
3568 */
3569 @Override
3570 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3572 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3577 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3578 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3579 return success;
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
Jake Hambye994d462014-02-03 13:10:13 -08003583 }
3584
3585 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003586 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003587 * Used for device configuration by some CDMA operators.
3588 *
chen xu1cc0abe2018-10-26 17:39:23 -07003589 * @param slotIndex - device slot.
3590 *
Jake Hambye994d462014-02-03 13:10:13 -08003591 * @return true on success; false on any failure
3592 */
3593 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003594 public boolean resetModemConfig(int slotIndex) {
3595 Phone phone = PhoneFactory.getPhone(slotIndex);
3596 if (phone != null) {
3597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3598 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003599
chen xu1cc0abe2018-10-26 17:39:23 -07003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3603 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3604 return success;
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003608 }
chen xu1cc0abe2018-10-26 17:39:23 -07003609 return false;
3610 }
3611
3612 /**
3613 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3614 *
3615 * @param slotIndex - device slot.
3616 *
3617 * @return true on success; false on any failure
3618 */
3619 @Override
3620 public boolean rebootModem(int slotIndex) {
3621 Phone phone = PhoneFactory.getPhone(slotIndex);
3622 if (phone != null) {
3623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3624 mApp, phone.getSubId(), "rebootModem");
3625
3626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3629 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3630 return success;
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
3633 }
3634 }
3635 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003636 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003637
Svet Ganovb320e182015-04-16 12:30:10 -07003638 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003641 return new String[0];
3642 }
3643
Malcolm Chend965c8b2018-02-28 15:00:40 -08003644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 return mPhone.getPcscfAddress(apnType);
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
3649 }
Wink Saville36469e72014-06-11 15:17:00 -07003650 }
3651
Brad Ebinger51f743a2017-01-23 13:50:20 -08003652 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003653 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3654 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003655 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003656 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003657 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003658
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 PhoneFactory.getImsResolver().enableIms(slotId);
3662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003665 }
3666
3667 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003668 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3669 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003670 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003671 public void disableIms(int slotId) {
3672 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 PhoneFactory.getImsResolver().disableIms(slotId);
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003680 }
3681
3682 /**
3683 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3684 * feature or {@link null} if the service is not available. If the feature is available, the
3685 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3686 */
3687 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003688 IImsServiceFeatureCallback callback) {
3689 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003690
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003697 }
3698
3699 /**
3700 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3701 * feature during emergency calling or {@link null} if the service is not available. If the
3702 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3703 * listener for feature updates.
3704 */
3705 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3706 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003707
3708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003714 }
3715
Brad Ebinger5f64b052017-12-14 14:26:15 -08003716 /**
3717 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3718 * specified.
3719 */
3720 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3721 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003722
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003729 }
3730
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003731 /**
3732 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3733 * specified.
3734 */
3735 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3736 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003737
3738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003744 }
3745
Brad Ebinger884c07b2018-02-15 16:17:40 -08003746 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003747 * Sets the ImsService Package Name that Telephony will bind to.
3748 *
3749 * @param slotId the slot ID that the ImsService should bind for.
3750 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3751 * ImsService is the device default ImsService.
3752 * @param packageName The package name of the application that contains the ImsService to bind
3753 * to.
3754 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3755 * @hide
3756 */
3757 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003758 int[] subIds = SubscriptionManager.getSubId(slotId);
3759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3760 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3761 "setImsService");
3762
Malcolm Chend965c8b2018-02-28 15:00:40 -08003763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3766 isCarrierImsService, packageName);
3767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003770 }
3771
3772 /**
3773 * Return the ImsService configuration.
3774 *
3775 * @param slotId The slot that the ImsService is associated with.
3776 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3777 * the device default.
3778 * @return the package name of the ImsService configuration.
3779 */
3780 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003781 int[] subIds = SubscriptionManager.getSubId(slotId);
3782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3783 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3784 "getImsService");
3785
Malcolm Chend965c8b2018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3789 isCarrierImsService);
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003793 }
3794
Wink Saville36469e72014-06-11 15:17:00 -07003795 public void setImsRegistrationState(boolean registered) {
3796 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 mPhone.setImsRegistrationState(registered);
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
Wink Saville36469e72014-06-11 15:17:00 -07003804 }
3805
3806 /**
Stuart Scott54788802015-03-30 13:18:01 -07003807 * Set the network selection mode to automatic.
3808 *
3809 */
3810 @Override
3811 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3813 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003814
Pengquan Meng466e2482018-09-21 15:54:48 -07003815 if (!isActiveSubscription(subId)) {
3816 return;
3817 }
3818
Malcolm Chend965c8b2018-02-28 15:00:40 -08003819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3822 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3823 } finally {
3824 Binder.restoreCallingIdentity(identity);
3825 }
Stuart Scott54788802015-03-30 13:18:01 -07003826 }
3827
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003828 /**
3829 * Ask the radio to connect to the input network and change selection mode to manual.
3830 *
3831 * @param subId the id of the subscription.
3832 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3833 * the operator to attach to.
3834 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3835 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3836 * normal network selection next time.
3837 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003838 */
3839 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003840 public boolean setNetworkSelectionModeManual(
3841 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3843 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003844
3845 if (!isActiveSubscription(subId)) {
3846 return false;
3847 }
3848
Malcolm Chend965c8b2018-02-28 15:00:40 -08003849 final long identity = Binder.clearCallingIdentity();
3850 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003851 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003852 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003853 if (DBG) {
3854 log("setNetworkSelectionModeManual: subId: " + subId
3855 + " operator: " + operatorInfo);
3856 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003857 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
3860 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003861 }
3862
3863 /**
3864 * Scans for available networks.
3865 */
3866 @Override
3867 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3869 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003870
Pengquan Meng0c05b502018-09-06 09:59:22 -07003871 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003872 try {
3873 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003874 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003875 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003879 }
3880
3881 /**
yinxub1bed742017-04-17 11:45:04 -07003882 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003883 *
yinxub1bed742017-04-17 11:45:04 -07003884 * @param subId id of the subscription
3885 * @param request contains the radio access networks with bands/channels to scan
3886 * @param messenger callback messenger for scan results or errors
3887 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003888 * @return the id of the requested scan which can be used to stop the scan.
3889 */
3890 @Override
3891 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3892 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3894 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003895
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 return mNetworkScanRequestTracker.startNetworkScan(
3899 request, messenger, binder, getPhone(subId));
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
yinxu504e1392017-04-12 16:03:22 -07003903 }
3904
3905 /**
3906 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003907 *
3908 * @param subId id of the subscription
3909 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003910 */
3911 @Override
3912 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3914 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003915
3916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
3921 }
yinxu504e1392017-04-12 16:03:22 -07003922 }
3923
3924 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003925 * Get the calculated preferred network type.
3926 * Used for debugging incorrect network type.
3927 *
3928 * @return the preferred network type, defined in RILConstants.java.
3929 */
3930 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003931 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003933 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003934 return RILConstants.PREFERRED_NETWORK_MODE;
3935 }
3936
Malcolm Chend965c8b2018-02-28 15:00:40 -08003937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 // FIXME: need to get SubId from somewhere.
3940 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
Junda Liu84d15a22014-07-02 11:21:04 -07003944 }
3945
3946 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003947 * Get the preferred network type.
3948 * Used for device configuration by some CDMA operators.
3949 *
3950 * @return the preferred network type, defined in RILConstants.java.
3951 */
3952 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003953 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3955 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003956
3957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 if (DBG) log("getPreferredNetworkType");
3960 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3961 int networkType = (result != null ? result[0] : -1);
3962 if (DBG) log("getPreferredNetworkType: " + networkType);
3963 return networkType;
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003967 }
3968
3969 /**
3970 * Set the preferred network type.
3971 * Used for device configuration by some CDMA operators.
3972 *
3973 * @param networkType the preferred network type, defined in RILConstants.java.
3974 * @return true on success; false on any failure.
3975 */
3976 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003977 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3979 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3984 Boolean success = (Boolean) sendRequest(
3985 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3986 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3987 if (success) {
3988 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3989 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3990 }
3991 return success;
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003994 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003995 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003996
3997 /**
Junda Liu475951f2014-11-07 16:45:03 -08003998 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003999 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004000 * tethering.
4001 *
4002 * @return 0: Not required. 1: required. 2: Not set.
4003 * @hide
4004 */
4005 @Override
4006 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004007 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004008
4009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
4012 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004013 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08004014 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
4015 dunRequired = 1;
4016 }
4017 return dunRequired;
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004020 }
Junda Liu475951f2014-11-07 16:45:03 -08004021 }
4022
4023 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004024 * Set mobile data enabled
4025 * Used by the user through settings etc to turn on/off mobile data
4026 *
4027 * @param enable {@code true} turn turn data on, else {@code false}
4028 */
4029 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004030 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4032 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 int phoneId = mSubscriptionController.getPhoneId(subId);
4037 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4038 Phone phone = PhoneFactory.getPhone(phoneId);
4039 if (phone != null) {
4040 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4041 phone.setUserDataEnabled(enable);
4042 } else {
4043 loge("setUserDataEnabled: no phone for subId=" + subId);
4044 }
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004047 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004048 }
4049
4050 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004051 * Get the user enabled state of Mobile Data.
4052 *
4053 * TODO: remove and use isUserDataEnabled.
4054 * This can't be removed now because some vendor codes
4055 * calls through ITelephony directly while they should
4056 * use TelephonyManager.
4057 *
4058 * @return true on enabled
4059 */
4060 @Override
4061 public boolean getDataEnabled(int subId) {
4062 return isUserDataEnabled(subId);
4063 }
4064
4065 /**
4066 * Get whether mobile data is enabled per user setting.
4067 *
4068 * There are other factors deciding whether mobile data is actually enabled, but they are
4069 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004070 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004071 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004072 *
4073 * @return {@code true} if data is enabled else {@code false}
4074 */
4075 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004076 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004077 try {
4078 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4079 null);
4080 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4082 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004083 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004084
4085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 int phoneId = mSubscriptionController.getPhoneId(subId);
4088 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4089 Phone phone = PhoneFactory.getPhone(phoneId);
4090 if (phone != null) {
4091 boolean retVal = phone.isUserDataEnabled();
4092 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4093 return retVal;
4094 } else {
4095 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4096 return false;
4097 }
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004100 }
4101 }
4102
4103 /**
4104 * Get whether mobile data is enabled.
4105 *
4106 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4107 * whether mobile data is actually enabled.
4108 *
4109 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4110 *
4111 * @return {@code true} if data is enabled else {@code false}
4112 */
4113 @Override
4114 public boolean isDataEnabled(int subId) {
4115 try {
4116 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4117 null);
4118 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4120 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004121 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 int phoneId = mSubscriptionController.getPhoneId(subId);
4126 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4127 Phone phone = PhoneFactory.getPhone(phoneId);
4128 if (phone != null) {
4129 boolean retVal = phone.isDataEnabled();
4130 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4131 return retVal;
4132 } else {
4133 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4134 return false;
4135 }
4136 } finally {
4137 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004138 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004139 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004140
4141 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004142 public int getCarrierPrivilegeStatus(int subId) {
4143 final Phone phone = getPhone(subId);
4144 if (phone == null) {
4145 loge("getCarrierPrivilegeStatus: Invalid subId");
4146 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4147 }
4148 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004149 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004150 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4152 }
4153 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004154 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004155 }
Junda Liu29340342014-07-10 15:23:27 -07004156
4157 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004158 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4159 final Phone phone = getPhone(subId);
4160 if (phone == null) {
4161 loge("getCarrierPrivilegeStatus: Invalid subId");
4162 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4163 }
4164 UiccProfile profile =
4165 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4166 if (profile == null) {
4167 loge("getCarrierPrivilegeStatus: No UICC");
4168 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4169 }
4170 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4171 }
4172
4173 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004174 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004175 if (TextUtils.isEmpty(pkgName))
4176 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004177 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004178 if (card == null) {
4179 loge("checkCarrierPrivilegesForPackage: No UICC");
4180 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4181 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004182 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4183 }
4184
4185 @Override
4186 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004187 if (TextUtils.isEmpty(pkgName))
4188 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004189 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4190 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4191 UiccCard card = UiccController.getInstance().getUiccCard(i);
4192 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004193 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004194 continue;
4195 }
4196
4197 result = card.getCarrierPrivilegeStatus(
4198 mPhone.getContext().getPackageManager(), pkgName);
4199 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4200 break;
4201 }
4202 }
4203
4204 return result;
Junda Liu29340342014-07-10 15:23:27 -07004205 }
Derek Tan89e89d42014-07-08 17:00:10 -07004206
4207 @Override
Junda Liue64de782015-04-16 17:19:16 -07004208 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4209 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4210 loge("phoneId " + phoneId + " is not valid.");
4211 return null;
4212 }
4213 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004214 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004215 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004216 return null ;
4217 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004218 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004219 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004220 }
4221
Amith Yamasani6e118872016-02-19 12:53:51 -08004222 @Override
4223 public List<String> getPackagesWithCarrierPrivileges() {
4224 PackageManager pm = mPhone.getContext().getPackageManager();
4225 List<String> privilegedPackages = new ArrayList<>();
4226 List<PackageInfo> packages = null;
4227 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4228 UiccCard card = UiccController.getInstance().getUiccCard(i);
4229 if (card == null) {
4230 // No UICC in that slot.
4231 continue;
4232 }
4233 if (card.hasCarrierPrivilegeRules()) {
4234 if (packages == null) {
4235 // Only check packages in user 0 for now
4236 packages = pm.getInstalledPackagesAsUser(
4237 PackageManager.MATCH_DISABLED_COMPONENTS
4238 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4239 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4240 }
4241 for (int p = packages.size() - 1; p >= 0; p--) {
4242 PackageInfo pkgInfo = packages.get(p);
4243 if (pkgInfo != null && pkgInfo.packageName != null
4244 && card.getCarrierPrivilegeStatus(pkgInfo)
4245 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4246 privilegedPackages.add(pkgInfo.packageName);
4247 }
4248 }
4249 }
4250 }
4251 return privilegedPackages;
4252 }
4253
Wink Savilleb564aae2014-10-23 10:18:09 -07004254 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004255 final Phone phone = getPhone(subId);
4256 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004257 if (card == null) {
4258 loge("getIccId: No UICC");
4259 return null;
4260 }
4261 String iccId = card.getIccId();
4262 if (TextUtils.isEmpty(iccId)) {
4263 loge("getIccId: ICC ID is null or empty.");
4264 return null;
4265 }
4266 return iccId;
4267 }
4268
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004269 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004270 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4271 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004272 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4273 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004274
Malcolm Chend965c8b2018-02-28 15:00:40 -08004275 final long identity = Binder.clearCallingIdentity();
4276 try {
4277 final String iccId = getIccId(subId);
4278 final Phone phone = getPhone(subId);
4279 if (phone == null) {
4280 return false;
4281 }
4282 final String subscriberId = phone.getSubscriberId();
4283
4284 if (DBG_MERGE) {
4285 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4286 + subscriberId + " to " + number);
4287 }
4288
4289 if (TextUtils.isEmpty(iccId)) {
4290 return false;
4291 }
4292
4293 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4294
4295 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4296 if (alphaTag == null) {
4297 editor.remove(alphaTagPrefKey);
4298 } else {
4299 editor.putString(alphaTagPrefKey, alphaTag);
4300 }
4301
4302 // Record both the line number and IMSI for this ICCID, since we need to
4303 // track all merged IMSIs based on line number
4304 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4305 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4306 if (number == null) {
4307 editor.remove(numberPrefKey);
4308 editor.remove(subscriberPrefKey);
4309 } else {
4310 editor.putString(numberPrefKey, number);
4311 editor.putString(subscriberPrefKey, subscriberId);
4312 }
4313
4314 editor.commit();
4315 return true;
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004318 }
Derek Tan7226c842014-07-02 17:42:23 -07004319 }
4320
4321 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004322 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004323 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004325 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004326 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004327 return null;
4328 }
Derek Tan97ebb422014-09-05 16:55:38 -07004329
Malcolm Chend965c8b2018-02-28 15:00:40 -08004330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 String iccId = getIccId(subId);
4333 if (iccId != null) {
4334 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4335 if (DBG_MERGE) {
4336 log("getLine1NumberForDisplay returning "
4337 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4338 }
4339 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004340 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004341 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4342 return null;
4343 } finally {
4344 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004345 }
Derek Tan7226c842014-07-02 17:42:23 -07004346 }
4347
4348 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004349 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004351 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004352 return null;
4353 }
Derek Tan97ebb422014-09-05 16:55:38 -07004354
Malcolm Chend965c8b2018-02-28 15:00:40 -08004355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 String iccId = getIccId(subId);
4358 if (iccId != null) {
4359 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4360 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4361 }
4362 return null;
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004365 }
Derek Tan7226c842014-07-02 17:42:23 -07004366 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004367
4368 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004369 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004370 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4371 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004373 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4374 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004375 return null;
4376 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004377
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004378 final long identity = Binder.clearCallingIdentity();
4379 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004380 final Context context = mPhone.getContext();
4381 final TelephonyManager tele = TelephonyManager.from(context);
4382 final SubscriptionManager sub = SubscriptionManager.from(context);
4383
4384 // Figure out what subscribers are currently active
4385 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4386 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4387 // the process, where TelephonyManager was instantiated.
4388 // Otherwise AppOps check will fail.
4389
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004390 final int[] subIds = sub.getActiveSubscriptionIdList();
4391 for (int subId : subIds) {
4392 activeSubscriberIds.add(tele.getSubscriberId(subId));
4393 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004394
4395 // First pass, find a number override for an active subscriber
4396 String mergeNumber = null;
4397 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4398 for (String key : prefs.keySet()) {
4399 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4400 final String subscriberId = (String) prefs.get(key);
4401 if (activeSubscriberIds.contains(subscriberId)) {
4402 final String iccId = key.substring(
4403 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4404 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4405 mergeNumber = (String) prefs.get(numberKey);
4406 if (DBG_MERGE) {
4407 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4408 + " for active subscriber " + subscriberId);
4409 }
4410 if (!TextUtils.isEmpty(mergeNumber)) {
4411 break;
4412 }
4413 }
4414 }
4415 }
4416
4417 // Shortcut when no active merged subscribers
4418 if (TextUtils.isEmpty(mergeNumber)) {
4419 return null;
4420 }
4421
4422 // Second pass, find all subscribers under that line override
4423 final ArraySet<String> result = new ArraySet<>();
4424 for (String key : prefs.keySet()) {
4425 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4426 final String number = (String) prefs.get(key);
4427 if (mergeNumber.equals(number)) {
4428 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4429 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4430 final String subscriberId = (String) prefs.get(subscriberKey);
4431 if (!TextUtils.isEmpty(subscriberId)) {
4432 result.add(subscriberId);
4433 }
4434 }
4435 }
4436 }
4437
4438 final String[] resultArray = result.toArray(new String[result.size()]);
4439 Arrays.sort(resultArray);
4440 if (DBG_MERGE) {
4441 Slog.d(LOG_TAG,
4442 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4443 }
4444 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004445 } finally {
4446 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004447 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004448 }
4449
4450 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004451 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004452 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4453 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004454
4455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 final Phone phone = getPhone(subId);
4458 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004462 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004463
4464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004465 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004466 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4467 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004468 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004469
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 final Phone phone = getPhone(subId);
4473 if (phone == null) {
4474 return false;
4475 }
4476 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4477 cdmaNonRoamingList);
4478 } finally {
4479 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004480 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004481 }
4482
4483 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004484 @Deprecated
4485 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4486 enforceModifyPermission();
4487
4488 int returnValue = 0;
4489 try {
vagdevie435a3e2018-08-15 16:01:53 -07004490 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004491 if(result.exception == null) {
4492 if (result.result != null) {
4493 byte[] responseData = (byte[])(result.result);
4494 if(responseData.length > oemResp.length) {
4495 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4496 responseData.length + "bytes. Buffer Size is " +
4497 oemResp.length + "bytes.");
4498 }
4499 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4500 returnValue = responseData.length;
4501 }
4502 } else {
4503 CommandException ex = (CommandException) result.exception;
4504 returnValue = ex.getCommandError().ordinal();
4505 if(returnValue > 0) returnValue *= -1;
4506 }
4507 } catch (RuntimeException e) {
4508 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4509 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4510 if(returnValue > 0) returnValue *= -1;
4511 }
4512
4513 return returnValue;
4514 }
4515
4516 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004517 public void setRadioCapability(RadioAccessFamily[] rafs) {
4518 try {
4519 ProxyController.getInstance().setRadioCapability(rafs);
4520 } catch (RuntimeException e) {
4521 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4522 }
4523 }
4524
4525 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004526 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004527 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004528 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004529 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004530 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004531 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004532 final long identity = Binder.clearCallingIdentity();
4533 try {
chen xufeeed752018-10-26 14:17:57 -07004534 TelephonyPermissions
4535 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4536 mApp, phone.getSubId(), "getRadioAccessFamily");
4537 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
chen xufeeed752018-10-26 14:17:57 -07004541 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004542 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004543
4544 @Override
4545 public void enableVideoCalling(boolean enable) {
4546 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004547
4548 final long identity = Binder.clearCallingIdentity();
4549 try {
4550 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4551 } finally {
4552 Binder.restoreCallingIdentity(identity);
4553 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004554 }
4555
4556 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004557 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4559 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4560 return false;
4561 }
Svet Ganovb320e182015-04-16 12:30:10 -07004562
Malcolm Chend965c8b2018-02-28 15:00:40 -08004563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 // Check the user preference and the system-level IMS setting. Even if the user has
4566 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4567 // In the long run, we may instead need to check if there exists a connection service
4568 // which can support video calling.
4569 ImsManager imsManager =
4570 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4571 return imsManager.isVtEnabledByPlatform()
4572 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4573 && imsManager.isVtEnabledByUser();
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004577 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004578
Andrew Leea1239f22015-03-02 17:44:07 -08004579 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004580 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4582 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4583 return false;
4584 }
4585
4586 final long identity = Binder.clearCallingIdentity();
4587 try {
4588 CarrierConfigManager configManager =
4589 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4590 return configManager.getConfigForSubId(mPhone.getSubId())
4591 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4592 } finally {
4593 Binder.restoreCallingIdentity(identity);
4594 }
Andrew Leea1239f22015-03-02 17:44:07 -08004595 }
4596
4597 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004598 public boolean isWorldPhone(int subId, String callingPackage) {
4599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4600 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4601 return false;
4602 }
4603
4604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 CarrierConfigManager configManager =
4607 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4608 return configManager.getConfigForSubId(mPhone.getSubId())
4609 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4610 } finally {
4611 Binder.restoreCallingIdentity(identity);
4612 }
Andrew Leea1239f22015-03-02 17:44:07 -08004613 }
4614
Andrew Lee9431b832015-03-09 18:46:45 -07004615 @Override
4616 public boolean isTtyModeSupported() {
4617 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004618 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004619 }
4620
4621 @Override
4622 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
Andrew Lee9431b832015-03-09 18:46:45 -07004629 }
4630
Hall Liuf6668912018-10-31 17:05:23 -07004631 /**
4632 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4633 * support for the feature and device firmware support.
4634 *
4635 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4636 */
4637 @Override
4638 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004639 final long identity = Binder.clearCallingIdentity();
4640 try {
4641 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4642 mPhone.getSubId()).getBoolean(
4643 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4644 boolean isDeviceSupported =
4645 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4646 return isCarrierSupported && isDeviceSupported;
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
4649 }
Hall Liu98187582018-01-22 19:15:32 -08004650 }
4651
Hall Liuf6668912018-10-31 17:05:23 -07004652 /**
4653 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4654 * both also support RTT.
4655 */
4656 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004657 final long identity = Binder.clearCallingIdentity();
4658 try {
Hall Liuf6668912018-10-31 17:05:23 -07004659 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004660 mPhone.getContext().getContentResolver(),
4661 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004665 }
4666
Sanket Padawe7310cc72015-01-14 09:53:20 -08004667 /**
4668 * Returns the unique device ID of phone, for example, the IMEI for
4669 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4670 *
4671 * <p>Requires Permission:
4672 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4673 */
4674 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004675 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004676 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004677 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004678 return null;
4679 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004680 int subId = phone.getSubId();
4681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4682 mApp, subId, callingPackage, "getDeviceId")) {
4683 return null;
4684 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
4688 return phone.getDeviceId();
4689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004692 }
4693
Ping Sunc67b7c22016-03-02 19:16:45 +08004694 /**
4695 * {@hide}
4696 * Returns the IMS Registration Status on a particular subid
4697 *
4698 * @param subId
4699 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004700 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004701 Phone phone = getPhone(subId);
4702 if (phone != null) {
4703 return phone.isImsRegistered();
4704 } else {
4705 return false;
4706 }
4707 }
4708
Santos Cordon7a1885b2015-02-03 11:15:19 -08004709 @Override
4710 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004711 final long identity = Binder.clearCallingIdentity();
4712 try {
4713 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
4716 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004717 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004718
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004719 /**
4720 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004721 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004722 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 Phone phone = getPhone(subId);
4726 if (phone != null) {
4727 return phone.isWifiCallingEnabled();
4728 } else {
4729 return false;
4730 }
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004733 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004734 }
4735
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004736 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004737 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004738 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004739 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 Phone phone = getPhone(subId);
4743 if (phone != null) {
4744 return phone.isVideoEnabled();
4745 } else {
4746 return false;
4747 }
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004750 }
4751 }
4752
4753 /**
4754 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4755 * defined in {@link ImsRegistrationImplBase}.
4756 */
4757 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004758 final long identity = Binder.clearCallingIdentity();
4759 try {
4760 Phone phone = getPhone(subId);
4761 if (phone != null) {
4762 return phone.getImsRegistrationTech();
4763 } else {
4764 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4765 }
4766 } finally {
4767 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004768 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004769 }
4770
Stuart Scott8eef64f2015-04-08 15:13:54 -07004771 @Override
4772 public void factoryReset(int subId) {
4773 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004774 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4775 return;
4776 }
4777
Svet Ganovcc087f82015-05-12 20:35:54 -07004778 final long identity = Binder.clearCallingIdentity();
4779 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004780 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4781 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004782 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004783 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004784 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4785 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004786 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004787 }
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004790 }
4791 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004792
4793 @Override
4794 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 // We query all subscriptions instead of just the active ones, because
4798 // this might be called early on in the provisioning flow when the
4799 // subscriptions potentially aren't active yet.
4800 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4801 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004802 return null;
4803 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004804
Malcolm Chend965c8b2018-02-28 15:00:40 -08004805 // This function may be called very early, say, from the setup wizard, at
4806 // which point we won't have a default subscription set. If that's the case
4807 // we just choose the first, which will be valid in "most cases".
4808 final int defaultSubId = getDefaultSubscription();
4809 SubscriptionInfo info = null;
4810 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4811 info = slist.get(0);
4812 } else {
4813 for (SubscriptionInfo item : slist) {
4814 if (item.getSubscriptionId() == defaultSubId) {
4815 info = item;
4816 break;
4817 }
4818 }
4819
4820 if (info == null) {
4821 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004822 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004823 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004824
Malcolm Chend965c8b2018-02-28 15:00:40 -08004825 // Try and fetch the locale from the carrier properties or from the SIM language
4826 // preferences (EF-PL and EF-LI)...
4827 final int mcc = info.getMcc();
4828 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4829 String simLanguage = null;
4830 if (defaultPhone != null) {
4831 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4832 if (localeFromDefaultSim != null) {
4833 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4834 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4835 return localeFromDefaultSim.toLanguageTag();
4836 } else {
4837 simLanguage = localeFromDefaultSim.getLanguage();
4838 }
4839 }
4840 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004841
Malcolm Chend965c8b2018-02-28 15:00:40 -08004842 // The SIM language preferences only store a language (e.g. fr = French), not an
4843 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4844 // the SIM and carrier preferences does not include a country we add the country
4845 // determined from the SIM MCC to provide an exact locale.
4846 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4847 simLanguage);
4848 if (mccLocale != null) {
4849 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4850 return mccLocale.toLanguageTag();
4851 }
4852
4853 if (DBG) log("No locale found - returning null");
4854 return null;
4855 } finally {
4856 Binder.restoreCallingIdentity(identity);
4857 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004858 }
4859
4860 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004861 return mSubscriptionController.getAllSubInfoList(
4862 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004863 }
4864
Malcolm Chend965c8b2018-02-28 15:00:40 -08004865 /**
4866 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4867 */
4868 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4869 return mSubscriptionController.getActiveSubscriptionInfoList(
4870 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004871 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004872
Chenjie Yu1ba97252018-01-11 18:16:20 -08004873 private final ModemActivityInfo mLastModemActivityInfo =
4874 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4875
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004876 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004877 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4878 * representing the state of the modem.
4879 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004880 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4881 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004882 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004883 */
4884 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004885 public void requestModemActivityInfo(ResultReceiver result) {
4886 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004888
4889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 ModemActivityInfo ret = null;
4892 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004893 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4894 CMD_GET_MODEM_ACTIVITY_INFO,
4895 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004896 if (isModemActivityInfoValid(info)) {
4897 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4898 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4899 mergedTxTimeMs[i] =
4900 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4901 }
4902 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4903 mLastModemActivityInfo.setSleepTimeMillis(
4904 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4905 mLastModemActivityInfo.setIdleTimeMillis(
4906 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4907 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4908 mLastModemActivityInfo.setRxTimeMillis(
4909 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4910 mLastModemActivityInfo.setEnergyUsed(
4911 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004912 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004913 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4914 mLastModemActivityInfo.getSleepTimeMillis(),
4915 mLastModemActivityInfo.getIdleTimeMillis(),
4916 mLastModemActivityInfo.getTxTimeMillis(),
4917 mLastModemActivityInfo.getRxTimeMillis(),
4918 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004919 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004920 Bundle bundle = new Bundle();
4921 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4922 result.send(0, bundle);
4923 } finally {
4924 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004925 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004926 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004927
Siddharth Rayf5d29552018-06-17 15:02:38 -07004928 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4929 // less than total activity duration.
4930 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4931 if (info == null) {
4932 return false;
4933 }
4934 int activityDurationMs =
4935 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4936 int totalTxTimeMs = 0;
4937 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4938 totalTxTimeMs += info.getTxTimeMillis()[i];
4939 }
4940 return (info.isValid()
4941 && (info.getSleepTimeMillis() <= activityDurationMs)
4942 && (info.getIdleTimeMillis() <= activityDurationMs)
4943 && (info.getRxTimeMillis() <= activityDurationMs)
4944 && (totalTxTimeMs <= activityDurationMs));
4945 }
4946
Jack Yu85bd38a2015-11-09 11:34:32 -08004947 /**
4948 * {@hide}
4949 * Returns the service state information on specified subscription.
4950 */
4951 @Override
4952 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004954 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004955 return null;
4956 }
4957
Malcolm Chend965c8b2018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 final Phone phone = getPhone(subId);
4961 if (phone == null) {
4962 return null;
4963 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004964
Malcolm Chend965c8b2018-02-28 15:00:40 -08004965 return phone.getServiceState();
4966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004969 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004970
4971 /**
4972 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4973 *
4974 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4975 * voicemail ringtone.
4976 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4977 * PhoneAccount.
4978 */
4979 @Override
4980 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004981 final long identity = Binder.clearCallingIdentity();
4982 try {
4983 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4984 if (phone == null) {
4985 phone = mPhone;
4986 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004987
Malcolm Chend965c8b2018-02-28 15:00:40 -08004988 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004992 }
4993
4994 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004995 * Sets the per-account voicemail ringtone.
4996 *
4997 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4998 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4999 *
5000 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5001 * voicemail ringtone.
5002 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5003 * PhoneAccount.
5004 */
5005 @Override
5006 public void setVoicemailRingtoneUri(String callingPackage,
5007 PhoneAccountHandle phoneAccountHandle, Uri uri) {
5008 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5009 if (!TextUtils.equals(callingPackage,
5010 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5012 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5013 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005014 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005015
5016 final long identity = Binder.clearCallingIdentity();
5017 try {
5018 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5019 if (phone == null) {
5020 phone = mPhone;
5021 }
5022 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5023 } finally {
5024 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005025 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005026 }
5027
5028 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005029 * Returns whether vibration is set for voicemail notification in Phone settings.
5030 *
5031 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5032 * voicemail vibration setting.
5033 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5034 */
5035 @Override
5036 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5040 if (phone == null) {
5041 phone = mPhone;
5042 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005043
Malcolm Chend965c8b2018-02-28 15:00:40 -08005044 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005048 }
5049
Youhan Wange64578a2016-05-02 15:32:42 -07005050 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005051 * Sets the per-account voicemail vibration.
5052 *
5053 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5054 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5055 *
5056 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5057 * voicemail vibration setting.
5058 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5059 * specific PhoneAccount.
5060 */
5061 @Override
5062 public void setVoicemailVibrationEnabled(String callingPackage,
5063 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5065 if (!TextUtils.equals(callingPackage,
5066 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5068 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5069 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005070 }
5071
Malcolm Chend965c8b2018-02-28 15:00:40 -08005072 final long identity = Binder.clearCallingIdentity();
5073 try {
5074 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5075 if (phone == null) {
5076 phone = mPhone;
5077 }
5078 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005081 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005082 }
5083
5084 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005085 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5086 *
5087 * @throws SecurityException if the caller does not have the required permission
5088 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005089 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005090 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005091 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005092 }
5093
5094 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005095 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5096 * permission.
5097 *
5098 * @throws SecurityException if the caller does not have the required permission
5099 */
5100 private void enforceSendSmsPermission() {
5101 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5102 }
5103
5104 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005105 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005106 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005107 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005108 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005109 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 ComponentName componentName =
5113 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5114 if (componentName == null) {
5115 throw new SecurityException(
5116 "Caller not current active visual voicemail package[null]");
5117 }
5118 String vvmPackage = componentName.getPackageName();
5119 if (!callingPackage.equals(vvmPackage)) {
5120 throw new SecurityException("Caller not current active visual voicemail package["
5121 + vvmPackage + "]");
5122 }
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005125 }
5126 }
5127
5128 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005129 * Return the application ID for the app type.
5130 *
5131 * @param subId the subscription ID that this request applies to.
5132 * @param appType the uicc app type.
5133 * @return Application ID for specificied app type, or null if no uicc.
5134 */
5135 @Override
5136 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005137 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005138 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005139
5140 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005141 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005142 if (phone == null) {
5143 return null;
5144 }
5145 String aid = null;
5146 try {
5147 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5148 .getApplicationByType(appType).getAid();
5149 } catch (Exception e) {
5150 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5151 }
5152 return aid;
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005155 }
Youhan Wange64578a2016-05-02 15:32:42 -07005156 }
5157
Youhan Wang4001d252016-05-11 10:29:41 -07005158 /**
5159 * Return the Electronic Serial Number.
5160 *
5161 * @param subId the subscription ID that this request applies to.
5162 * @return ESN or null if error.
5163 */
5164 @Override
5165 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005166 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005167 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005168
5169 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005170 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171 if (phone == null) {
5172 return null;
5173 }
5174 String esn = null;
5175 try {
5176 esn = phone.getEsn();
5177 } catch (Exception e) {
5178 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5179 }
5180 return esn;
5181 } finally {
5182 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005183 }
Youhan Wang4001d252016-05-11 10:29:41 -07005184 }
5185
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005186 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005187 * Return the Preferred Roaming List Version.
5188 *
5189 * @param subId the subscription ID that this request applies to.
5190 * @return PRLVersion or null if error.
5191 */
5192 @Override
5193 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005194 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005195 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005196
5197 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005198 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005199 if (phone == null) {
5200 return null;
5201 }
5202 String cdmaPrlVersion = null;
5203 try {
5204 cdmaPrlVersion = phone.getCdmaPrlVersion();
5205 } catch (Exception e) {
5206 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5207 }
5208 return cdmaPrlVersion;
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005211 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005212 }
5213
5214 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005215 * Get snapshot of Telephony histograms
5216 * @return List of Telephony histograms
5217 * @hide
5218 */
5219 @Override
5220 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5222 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005223
5224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 return RIL.getTelephonyRILTimingHistograms();
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005230 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005231
5232 /**
5233 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005234 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005235 * Require system privileges. In the future we may add this to carrier APIs.
5236 *
5237 * @return The number of carriers set successfully, should match length of carriers
5238 */
5239 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005240 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005241 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005242 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005243
Meng Wang9b7c4e92017-02-17 11:41:27 -08005244 if (carriers == null) {
5245 throw new NullPointerException("carriers cannot be null");
5246 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005247
Malcolm Chend965c8b2018-02-28 15:00:40 -08005248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005251 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5252 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005253 return retVal[0];
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005257 }
5258
5259 /**
5260 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005261 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005262 * Require system privileges. In the future we may add this to carrier APIs.
5263 *
5264 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5265 * means all carriers are allowed.
5266 */
5267 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005268 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005269 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005271
5272 final long identity = Binder.clearCallingIdentity();
5273 try {
5274 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005275 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5276 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005280 }
5281
fionaxu59545b42016-05-25 15:53:37 -07005282 /**
5283 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5284 * @param subId the subscription ID that this action applies to.
5285 * @param enabled control enable or disable metered apns.
5286 * {@hide}
5287 */
5288 @Override
5289 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5290 enforceModifyPermission();
5291 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005292
5293 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005294 if (phone == null) {
5295 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5296 return;
5297 }
5298 try {
5299 phone.carrierActionSetMeteredApnsEnabled(enabled);
5300 } catch (Exception e) {
5301 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005302 } finally {
5303 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005304 }
5305 }
5306
5307 /**
5308 * Action set from carrier signalling broadcast receivers to enable/disable radio
5309 * @param subId the subscription ID that this action applies to.
5310 * @param enabled control enable or disable radio.
5311 * {@hide}
5312 */
5313 @Override
5314 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5315 enforceModifyPermission();
5316 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005317
5318 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005319 if (phone == null) {
5320 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5321 return;
5322 }
5323 try {
5324 phone.carrierActionSetRadioEnabled(enabled);
5325 } catch (Exception e) {
5326 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005327 } finally {
5328 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005329 }
5330 }
5331
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005332 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005333 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5334 * network status based on which carrier apps could apply actions accordingly,
5335 * enable/disable default url handler for example.
5336 *
5337 * @param subId the subscription ID that this action applies to.
5338 * @param report control start/stop reporting the default network status.
5339 * {@hide}
5340 */
5341 @Override
5342 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5343 enforceModifyPermission();
5344 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005345
5346 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005347 if (phone == null) {
5348 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5349 return;
5350 }
5351 try {
5352 phone.carrierActionReportDefaultNetworkStatus(report);
5353 } catch (Exception e) {
5354 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005355 } finally {
5356 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005357 }
5358 }
5359
5360 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005361 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5362 * bug report is being generated.
5363 */
5364 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005365 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005366 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Hall Liud892bec2018-11-30 14:51:45 -08005367 != PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005368 writer.println("Permission Denial: can't dump Phone from pid="
5369 + Binder.getCallingPid()
5370 + ", uid=" + Binder.getCallingUid()
5371 + "without permission "
5372 + android.Manifest.permission.DUMP);
5373 return;
5374 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005375 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005376 }
Jack Yueb89b242016-06-22 13:27:47 -07005377
Brad Ebingerdac2f002018-04-03 15:17:52 -07005378 @Override
5379 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5380 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5381 throws RemoteException {
5382 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5383 }
5384
Jack Yueb89b242016-06-22 13:27:47 -07005385 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005386 * Get aggregated video call data usage since boot.
5387 *
5388 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5389 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005390 * {@hide}
5391 */
5392 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005393 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005394 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5395 null);
5396
Malcolm Chend965c8b2018-02-28 15:00:40 -08005397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 // NetworkStatsService keeps tracking the active network interface and identity. It
5400 // records the delta with the corresponding network identity.
5401 // We just return the total video call data usage snapshot since boot.
5402 Phone phone = getPhone(subId);
5403 if (phone != null) {
5404 return phone.getVtDataUsage(perUidStats);
5405 }
5406 return null;
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005409 }
Jack Yueb89b242016-06-22 13:27:47 -07005410 }
Jack Yu75ab2952016-07-08 14:29:33 -07005411
5412 /**
5413 * Policy control of data connection. Usually used when data limit is passed.
5414 * @param enabled True if enabling the data, otherwise disabling.
5415 * @param subId Subscription index
5416 * {@hide}
5417 */
5418 @Override
5419 public void setPolicyDataEnabled(boolean enabled, int subId) {
5420 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 Phone phone = getPhone(subId);
5425 if (phone != null) {
5426 phone.setPolicyDataEnabled(enabled);
5427 }
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005430 }
5431 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005432
5433 /**
5434 * Get Client request stats
5435 * @return List of Client Request Stats
5436 * @hide
5437 */
5438 @Override
5439 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005441 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005442 return null;
5443 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005444 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005445
Malcolm Chend965c8b2018-02-28 15:00:40 -08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
5448 if (phone != null) {
5449 return phone.getClientRequestStats();
5450 }
5451
5452 return null;
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
5455 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005456 }
5457
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005458 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005459 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005460 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005461 }
Jack Yueb4124c2017-02-16 15:32:43 -08005462
5463 /**
Grace Chen70990072017-03-24 17:21:30 -07005464 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005465 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005466 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005467 * @param state State of SIM (power down, power up, pass through)
5468 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5469 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5470 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005471 *
5472 **/
5473 @Override
Grace Chen70990072017-03-24 17:21:30 -07005474 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005475 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005476 Phone phone = PhoneFactory.getPhone(slotIndex);
5477
vagdevie435a3e2018-08-15 16:01:53 -07005478 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5479
Malcolm Chend965c8b2018-02-28 15:00:40 -08005480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005483 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005484 }
5485 } finally {
5486 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005487 }
5488 }
Shuo Qiandd210312017-04-12 22:11:33 +00005489
Tyler Gunn65d45c22017-06-05 11:22:26 -07005490 private boolean isUssdApiAllowed(int subId) {
5491 CarrierConfigManager configManager =
5492 (CarrierConfigManager) mPhone.getContext().getSystemService(
5493 Context.CARRIER_CONFIG_SERVICE);
5494 if (configManager == null) {
5495 return false;
5496 }
5497 PersistableBundle pb = configManager.getConfigForSubId(subId);
5498 if (pb == null) {
5499 return false;
5500 }
5501 return pb.getBoolean(
5502 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5503 }
5504
Shuo Qiandd210312017-04-12 22:11:33 +00005505 /**
5506 * Check if phone is in emergency callback mode
5507 * @return true if phone is in emergency callback mode
5508 * @param subId sub id
5509 */
goneil9c5f4872017-12-05 14:07:56 -08005510 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005511 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005512 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005513 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005514
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 if (phone != null) {
5518 return phone.isInEcm();
5519 } else {
5520 return false;
5521 }
5522 } finally {
5523 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005524 }
5525 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005526
5527 /**
5528 * Get the current signal strength information for the given subscription.
5529 * Because this information is not updated when the device is in a low power state
5530 * it should not be relied-upon to be current.
5531 * @param subId Subscription index
5532 * @return the most recent cached signal strength info from the modem
5533 */
5534 @Override
5535 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 Phone p = getPhone(subId);
5539 if (p == null) {
5540 return null;
5541 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005542
Malcolm Chend965c8b2018-02-28 15:00:40 -08005543 return p.getSignalStrength();
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005547 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005548
Pengquan Meng9140aec2018-08-22 14:49:57 -07005549 /**
chen xu907e5a22018-10-11 13:21:04 -07005550 * Get the current modem radio state for the given slot.
5551 * @param slotIndex slot index.
5552 * @param callingPackage the name of the package making the call.
5553 * @return the current radio power state from the modem
5554 */
5555 @Override
5556 public int getRadioPowerState(int slotIndex, String callingPackage) {
5557 Phone phone = PhoneFactory.getPhone(slotIndex);
5558 if (phone != null) {
5559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5560 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5561 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5562 }
5563
5564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 return phone.getRadioPowerState();
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
5570 }
5571 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5572 }
5573
5574 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005575 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5576 *
5577 * <p>Requires one of the following permissions:
5578 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5579 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5580 * privileges.
5581 *
5582 * @param subId subscription id
5583 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5584 * {@code false}.
5585 */
5586 @Override
5587 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005588 boolean isEnabled = false;
5589 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005590 try {
5591 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005592 null /* message */);
5593 Phone phone = getPhone(subId);
5594 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005595 } catch (Exception e) {
5596 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5597 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005600 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005601 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005602 }
5603
5604
5605 /**
5606 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5607 *
5608 * <p> Requires permission:
5609 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5610 * privileges.
5611 *
5612 * @param subId subscription id
5613 * @param isEnabled {@code true} means enable, {@code false} means disable.
5614 */
5615 @Override
5616 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5620 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005621
Pengquan Meng0c05b502018-09-06 09:59:22 -07005622 Phone phone = getPhone(subId);
5623 if (phone != null) {
5624 phone.setDataRoamingEnabled(isEnabled);
5625 }
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005628 }
5629 }
5630
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005631 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005632 public boolean isManualNetworkSelectionAllowed(int subId) {
5633 boolean isAllowed = true;
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5637 mApp, subId, "isManualNetworkSelectionAllowed");
5638 Phone phone = getPhone(subId);
5639 if (phone != null) {
5640 isAllowed = phone.isCspPlmnEnabled();
5641 }
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
5645 return isAllowed;
5646 }
5647
5648 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005649 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005650 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005651
Malcolm Chend965c8b2018-02-28 15:00:40 -08005652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5655 if (slots == null) {
5656 Rlog.i(LOG_TAG, "slots is null.");
5657 return null;
5658 }
5659
5660 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5661 for (int i = 0; i < slots.length; i++) {
5662 UiccSlot slot = slots[i];
5663 if (slot == null) {
5664 continue;
5665 }
5666
5667 String cardId;
5668 UiccCard card = slot.getUiccCard();
5669 if (card != null) {
5670 cardId = card.getCardId();
5671 } else {
5672 cardId = slot.getIccId();
5673 }
5674
5675 int cardState = 0;
5676 switch (slot.getCardState()) {
5677 case CARDSTATE_ABSENT:
5678 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5679 break;
5680 case CARDSTATE_PRESENT:
5681 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5682 break;
5683 case CARDSTATE_ERROR:
5684 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5685 break;
5686 case CARDSTATE_RESTRICTED:
5687 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5688 break;
5689 default:
5690 break;
5691
5692 }
5693
5694 infos[i] = new UiccSlotInfo(
5695 slot.isActive(),
5696 slot.isEuicc(),
5697 cardId,
5698 cardState,
5699 slot.getPhoneId(),
5700 slot.isExtendedApduSupported());
5701 }
5702 return infos;
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005705 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005706 }
5707
5708 @Override
5709 public boolean switchSlots(int[] physicalSlots) {
5710 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005711
5712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005718 }
Jack Yu4c988042018-02-27 15:30:01 -08005719
5720 @Override
5721 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5722 enforceModifyPermission();
5723 final Phone phone = getPhone(subId);
5724 if (phone == null) {
5725 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5726 return;
5727 }
5728
Malcolm Chend965c8b2018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 phone.setRadioIndicationUpdateMode(filters, mode);
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
Jack Yu4c988042018-02-27 15:30:01 -08005735 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005736
5737 /**
goneil47ffb6e2018-04-06 15:40:58 -07005738 * A test API to reload the UICC profile.
5739 *
5740 * <p>Requires that the calling app has permission
5741 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5742 * @hide
5743 */
5744 @Override
5745 public void refreshUiccProfile(int subId) {
5746 enforceModifyPermission();
5747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
5750 Phone phone = getPhone(subId);
5751 if (phone == null) {
5752 return;
5753 }
5754 UiccCard uiccCard = phone.getUiccCard();
5755 if (uiccCard == null) {
5756 return;
5757 }
5758 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5759 if (uiccProfile == null) {
5760 return;
5761 }
5762 uiccProfile.refresh();
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
5766 }
5767
5768 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005769 * Returns false if the mobile data is disabled by default, otherwise return true.
5770 */
5771 private boolean getDefaultDataEnabled() {
5772 return "true".equalsIgnoreCase(
5773 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5774 }
5775
5776 /**
5777 * Returns true if the data roaming is enabled by default, i.e the system property
5778 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5779 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5780 */
5781 private boolean getDefaultDataRoamingEnabled(int subId) {
5782 final CarrierConfigManager configMgr = (CarrierConfigManager)
5783 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5784 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5785 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5786 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5787 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5788 return isDataRoamingEnabled;
5789 }
5790
5791 /**
5792 * Returns the default network type for the given {@code subId}, if the default network type is
5793 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5794 */
5795 private int getDefaultNetworkType(int subId) {
5796 return Integer.parseInt(
5797 TelephonyManager.getTelephonyProperty(
5798 mSubscriptionController.getPhoneId(subId),
5799 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5800 String.valueOf(Phone.PREFERRED_NT_MODE)));
5801 }
fionaxua13278b2018-03-21 00:08:13 -07005802
5803 @Override
5804 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5805 gid1, String gid2, String plmn, String spn) {
5806 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 final Phone phone = getPhone(subId);
5811 if (phone == null) {
5812 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5813 return;
5814 }
5815 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005818 }
fionaxua13278b2018-03-21 00:08:13 -07005819 }
5820
5821 @Override
5822 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005823 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005824
5825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 final Phone phone = getPhone(subId);
5828 if (phone == null) {
5829 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5830 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5831 }
5832 return phone.getCarrierIdListVersion();
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005835 }
fionaxua13278b2018-03-21 00:08:13 -07005836 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005837
5838 @Override
5839 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5841 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5842 return -1;
5843 }
5844
5845 final long identity = Binder.clearCallingIdentity();
5846 try {
5847 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5848 } finally {
5849 Binder.restoreCallingIdentity(identity);
5850 }
5851 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005852
5853 @Override
5854 public int getCdmaRoamingMode(int subId) {
5855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5856 mApp, subId, "getCdmaRoamingMode");
5857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
5864 }
5865
5866 @Override
5867 public boolean setCdmaRoamingMode(int subId, int mode) {
5868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5869 mApp, subId, "setCdmaRoamingMode");
5870
5871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
5877 }
5878
5879 @Override
5880 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5882 mApp, subId, "setCdmaSubscriptionMode");
5883
5884 final long identity = Binder.clearCallingIdentity();
5885 try {
5886 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
5890 }
chen xu7ee67862018-10-30 22:27:10 -07005891
sqian2fff4a32018-11-05 14:18:37 -08005892 private void ensureUserRunning(int userId) {
5893 if (!mUserManager.isUserRunning(userId)) {
5894 throw new IllegalStateException("User " + userId + " does not exist or not running");
5895 }
5896 }
5897
5898 /**
5899 * Returns a list of SMS apps on a given user.
5900 *
5901 * Only the shell user (UID 2000 or 0) can call it.
5902 * Target user must be running.
5903 */
5904 @Override
5905 public String[] getSmsApps(int userId) {
5906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5907 ensureUserRunning(userId);
5908
5909 final Collection<SmsApplicationData> apps =
5910 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5911
5912 String[] ret = new String[apps.size()];
5913 int i = 0;
5914 for (SmsApplicationData app : apps) {
5915 ret[i++] = app.mPackageName;
5916 }
5917 return ret;
5918 }
5919
5920 /**
5921 * Returns the default SMS app package name on a given user.
5922 *
5923 * Only the shell user (UID 2000 or 0) can call it.
5924 * Target user must be running.
5925 */
5926 @Override
5927 public String getDefaultSmsApp(int userId) {
5928 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5929 ensureUserRunning(userId);
5930
5931 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5932 /* updateIfNeeded= */ true, userId);
5933 return cn == null ? null : cn.getPackageName();
5934 }
5935
5936 /**
5937 * Set a package as the default SMS app on a given user.
5938 *
5939 * Only the shell user (UID 2000 or 0) can call it.
5940 * Target user must be running.
5941 */
5942 @Override
5943 public void setDefaultSmsApp(int userId, String packageName) {
5944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5945 ensureUserRunning(userId);
5946
5947 boolean found = false;
5948 for (String pkg : getSmsApps(userId)) {
5949 if (TextUtils.equals(packageName, pkg)) {
5950 found = true;
5951 break;
5952 }
5953 }
5954 if (!found) {
5955 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5956 }
5957
5958 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5959 }
5960
chen xu7ee67862018-10-30 22:27:10 -07005961 @Override
sqian04b86072018-11-07 14:02:21 -08005962 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5963 String callingPackage) {
5964 // TODO connect with internal content
5965 return null;
5966 }
5967
5968 @Override
5969 public boolean isCurrentEmergencyNumber(String number) {
5970 // TODO connect with internal content
5971 return false;
5972 }
5973
5974 @Override
chen xu7ee67862018-10-30 22:27:10 -07005975 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5976 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5977 Phone phone = getPhone(subId);
5978 if (phone == null) {
5979 return null;
5980 }
5981 final long identity = Binder.clearCallingIdentity();
5982 try {
5983 UiccProfile profile = UiccController.getInstance()
5984 .getUiccProfileForPhone(phone.getPhoneId());
5985 if (profile != null) {
5986 return profile.getCertsFromCarrierPrivilegeAccessRules();
5987 }
5988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
5991 return null;
5992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005993}