blob: a8f72bc1e974023b6430a27f07680f001de28247 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070089import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080090import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070091import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080092import android.telephony.ims.aidl.IImsMmTelFeature;
93import android.telephony.ims.aidl.IImsRcsFeature;
94import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070095import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080096import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800102
Brad Ebinger4c460712018-10-01 10:40:55 -0700103import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700104import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800105import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700107import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700108import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800109import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800113import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700116import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100117import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700118import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700121import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800122import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700123import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700124import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700125import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700126import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700127import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800129import com.android.internal.telephony.SmsApplication;
130import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800131import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800132import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700133import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.IccIoResult;
135import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800136import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700137import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800138import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000141import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700142import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800143import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700144import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800145import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700146import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700147import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700149import java.io.FileDescriptor;
150import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800154import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800155import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100156import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800157import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158
159/**
160 * Implementation of the ITelephony interface.
161 */
Santos Cordon117fee72014-05-16 17:56:12 -0700162public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 private static final String LOG_TAG = "PhoneInterfaceManager";
164 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
165 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800166 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167
168 // Message codes used with mMainThreadHandler
169 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700170 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
171 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700172 private static final int CMD_OPEN_CHANNEL = 9;
173 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
174 private static final int CMD_CLOSE_CHANNEL = 11;
175 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800176 private static final int CMD_NV_READ_ITEM = 13;
177 private static final int EVENT_NV_READ_ITEM_DONE = 14;
178 private static final int CMD_NV_WRITE_ITEM = 15;
179 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
180 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
181 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700182 private static final int CMD_RESET_MODEM_CONFIG = 19;
183 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800184 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
185 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
186 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
187 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800188 private static final int CMD_SEND_ENVELOPE = 25;
189 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000190 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
191 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700192 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
193 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
194 private static final int CMD_EXCHANGE_SIM_IO = 31;
195 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800196 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
197 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700198 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
199 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700200 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
201 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700202 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
203 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
204 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
205 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700206 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
207 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
208 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
209 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700210 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800211 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
212 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000213 private static final int CMD_SWITCH_SLOTS = 50;
214 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700215 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
216 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
217 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
218 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
219 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
220 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
221 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
222 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700223 private static final int CMD_GET_ALL_CELL_INFO = 60;
224 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
225 private static final int CMD_GET_CELL_LOCATION = 62;
226 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700227 private static final int CMD_MODEM_REBOOT = 64;
228 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700229 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
230 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800232 // Parameters of select command.
233 private static final int SELECT_COMMAND = 0xA4;
234 private static final int SELECT_P1 = 0x04;
235 private static final int SELECT_P2 = 0;
236 private static final int SELECT_P3 = 0x10;
237
Pengquan Meng85728fb2018-03-12 16:31:21 -0700238 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
239 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
240 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
241
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 /** The singleton instance. */
243 private static PhoneInterfaceManager sInstance;
244
Wink Saville3ab207e2014-11-20 13:07:20 -0800245 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800246 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700247 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800248 private AppOpsManager mAppOps;
249 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800250 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800251 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700252 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
Derek Tan97ebb422014-09-05 16:55:38 -0700254 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
255 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800256 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700257
Derek Tan740e1672017-06-27 14:56:27 -0700258 // The AID of ISD-R.
259 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
260
yinxub1bed742017-04-17 11:45:04 -0700261 private NetworkScanRequestTracker mNetworkScanRequestTracker;
262
David Kelly5e06a7f2018-03-12 14:10:59 +0000263 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
264 private static final int MANUFACTURER_CODE_LENGTH = 8;
265
Derek Tan89e89d42014-07-08 17:00:10 -0700266 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700267 * A request object to use for transmitting data to an ICC.
268 */
269 private static final class IccAPDUArgument {
270 public int channel, cla, command, p1, p2, p3;
271 public String data;
272
273 public IccAPDUArgument(int channel, int cla, int command,
274 int p1, int p2, int p3, String data) {
275 this.channel = channel;
276 this.cla = cla;
277 this.command = command;
278 this.p1 = p1;
279 this.p2 = p2;
280 this.p3 = p3;
281 this.data = data;
282 }
283 }
284
285 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700286 * A request object to use for transmitting data to an ICC.
287 */
288 private static final class ManualNetworkSelectionArgument {
289 public OperatorInfo operatorInfo;
290 public boolean persistSelection;
291
292 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
293 this.operatorInfo = operatorInfo;
294 this.persistSelection = persistSelection;
295 }
296 }
297
298 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
300 * request after sending. The main thread will notify the request when it is complete.
301 */
302 private static final class MainThreadRequest {
303 /** The argument to use for the request */
304 public Object argument;
305 /** The result of the request that is run on the main thread */
306 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800307 // The subscriber id that this request applies to. Defaults to
308 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
309 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
Nathan Harold92bed182018-10-12 18:16:49 -0700311 // In cases where subId is unavailable, the caller needs to specify the phone.
312 public Phone phone;
313
vagdevie435a3e2018-08-15 16:01:53 -0700314 public WorkSource workSource;
315
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 public MainThreadRequest(Object argument) {
317 this.argument = argument;
318 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800319
Nathan Harold92bed182018-10-12 18:16:49 -0700320 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
321 this.argument = argument;
322 if (phone != null) {
323 this.phone = phone;
324 }
325 this.workSource = workSource;
326 }
327
vagdevie435a3e2018-08-15 16:01:53 -0700328 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800329 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800330 if (subId != null) {
331 this.subId = subId;
332 }
vagdevie435a3e2018-08-15 16:01:53 -0700333 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 }
336
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800337 private static final class IncomingThirdPartyCallArgs {
338 public final ComponentName component;
339 public final String callId;
340 public final String callerDisplayName;
341
342 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
343 String callerDisplayName) {
344 this.component = component;
345 this.callId = callId;
346 this.callerDisplayName = callerDisplayName;
347 }
348 }
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 /**
351 * A handler that processes messages on the main thread in the phone process. Since many
352 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
353 * inbound binder threads to the main thread in the phone process. The Binder thread
354 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
355 * on, which will be notified when the operation completes and will contain the result of the
356 * request.
357 *
358 * <p>If a MainThreadRequest object is provided in the msg.obj field,
359 * note that request.result must be set to something non-null for the calling thread to
360 * unblock.
361 */
362 private final class MainThreadHandler extends Handler {
363 @Override
364 public void handleMessage(Message msg) {
365 MainThreadRequest request;
366 Message onCompleted;
367 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800368 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700369 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800370 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
372 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700373 case CMD_HANDLE_USSD_REQUEST: {
374 request = (MainThreadRequest) msg.obj;
375 final Phone phone = getPhoneFromRequest(request);
376 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
377 String ussdRequest = ussdObject.first;
378 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700379
Pengquan Meng0c05b502018-09-06 09:59:22 -0700380 if (!isUssdApiAllowed(request.subId)) {
381 // Carrier does not support use of this API, return failure.
382 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
383 UssdResponse response = new UssdResponse(ussdRequest, null);
384 Bundle returnData = new Bundle();
385 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
386 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700387
Pengquan Meng0c05b502018-09-06 09:59:22 -0700388 request.result = true;
389 notifyRequester(request);
390 return;
391 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700392
Pengquan Meng0c05b502018-09-06 09:59:22 -0700393 try {
394 request.result = phone != null
395 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
396 } catch (CallStateException cse) {
397 request.result = false;
398 }
399 // Wake up the requesting thread
400 notifyRequester(request);
401 break;
pkanwar32d516d2016-10-14 19:37:38 -0700402 }
403
Yorke Lee716f67e2015-06-17 15:39:16 -0700404 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700406 final Phone phone = getPhoneFromRequest(request);
407 request.result = phone != null ?
408 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
409 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700411 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800418 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 if (uiccCard == null) {
420 loge("iccTransmitApduLogicalChannel: No UICC");
421 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700422 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700423 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
425 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 iccArgument.channel, iccArgument.cla, iccArgument.command,
428 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 break;
432
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 ar = (AsyncResult) msg.obj;
435 request = (MainThreadRequest) ar.userObj;
436 if (ar.exception == null && ar.result != null) {
437 request.result = ar.result;
438 } else {
439 request.result = new IccIoResult(0x6F, 0, (byte[])null);
440 if (ar.result == null) {
441 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800442 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800444 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 } else {
446 loge("iccTransmitApduLogicalChannel: Unknown exception");
447 }
448 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700449 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 break;
451
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
453 request = (MainThreadRequest) msg.obj;
454 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800455 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 if (uiccCard == null) {
457 loge("iccTransmitApduBasicChannel: No UICC");
458 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700459 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 } else {
461 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
462 request);
463 uiccCard.iccTransmitApduBasicChannel(
464 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
465 iccArgument.p3, iccArgument.data, onCompleted);
466 }
467 break;
468
469 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
470 ar = (AsyncResult) msg.obj;
471 request = (MainThreadRequest) ar.userObj;
472 if (ar.exception == null && ar.result != null) {
473 request.result = ar.result;
474 } else {
475 request.result = new IccIoResult(0x6F, 0, (byte[])null);
476 if (ar.result == null) {
477 loge("iccTransmitApduBasicChannel: Empty response");
478 } else if (ar.exception instanceof CommandException) {
479 loge("iccTransmitApduBasicChannel: CommandException: " +
480 ar.exception);
481 } else {
482 loge("iccTransmitApduBasicChannel: Unknown exception");
483 }
484 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700485 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 break;
487
488 case CMD_EXCHANGE_SIM_IO:
489 request = (MainThreadRequest) msg.obj;
490 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800491 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 if (uiccCard == null) {
493 loge("iccExchangeSimIO: No UICC");
494 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 } else {
497 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
498 request);
499 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
500 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
501 iccArgument.data, onCompleted);
502 }
503 break;
504
505 case EVENT_EXCHANGE_SIM_IO_DONE:
506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6f, 0, (byte[])null);
512 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700513 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 break;
515
Derek Tan4d5e5c12014-02-04 11:54:58 -0800516 case CMD_SEND_ENVELOPE:
517 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700519 if (uiccCard == null) {
520 loge("sendEnvelopeWithStatus: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 } else {
524 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
525 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
526 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800527 break;
528
529 case EVENT_SEND_ENVELOPE_DONE:
530 ar = (AsyncResult) msg.obj;
531 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700532 if (ar.exception == null && ar.result != null) {
533 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800534 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 if (ar.result == null) {
537 loge("sendEnvelopeWithStatus: Empty response");
538 } else if (ar.exception instanceof CommandException) {
539 loge("sendEnvelopeWithStatus: CommandException: " +
540 ar.exception);
541 } else {
542 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
543 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700545 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 break;
547
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 case CMD_OPEN_CHANNEL:
549 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800550 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800551 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 if (uiccCard == null) {
553 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800554 request.result = new IccOpenLogicalChannelResponse(-1,
555 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
558 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800559 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
560 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 break;
563
564 case EVENT_OPEN_CHANNEL_DONE:
565 ar = (AsyncResult) msg.obj;
566 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 int[] result = (int[]) ar.result;
570 int channelId = result[0];
571 byte[] selectResponse = null;
572 if (result.length > 1) {
573 selectResponse = new byte[result.length - 1];
574 for (int i = 1; i < result.length; ++i) {
575 selectResponse[i - 1] = (byte) result[i];
576 }
577 }
578 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700579 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 if (ar.result == null) {
582 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 if (ar.exception != null) {
585 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
586 }
587
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700588 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700589 if (ar.exception instanceof CommandException) {
590 CommandException.Error error =
591 ((CommandException) (ar.exception)).getCommandError();
592 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700594 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 }
597 }
598 openChannelResp = new IccOpenLogicalChannelResponse(
599 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700601 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 break;
604
605 case CMD_CLOSE_CHANNEL:
606 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800607 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 if (uiccCard == null) {
609 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900610 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700611 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 } else {
613 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
614 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
615 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 break;
617
618 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800619 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
620 break;
621
622 case CMD_NV_READ_ITEM:
623 request = (MainThreadRequest) msg.obj;
624 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800625 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
626 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800627 break;
628
629 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 ar = (AsyncResult) msg.obj;
631 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800632 if (ar.exception == null && ar.result != null) {
633 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800635 request.result = "";
636 if (ar.result == null) {
637 loge("nvReadItem: Empty response");
638 } else if (ar.exception instanceof CommandException) {
639 loge("nvReadItem: CommandException: " +
640 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800642 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
644 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
Jake Hambye994d462014-02-03 13:10:13 -0800648 case CMD_NV_WRITE_ITEM:
649 request = (MainThreadRequest) msg.obj;
650 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
651 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800652 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700653 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800654 break;
655
656 case EVENT_NV_WRITE_ITEM_DONE:
657 handleNullReturnEvent(msg, "nvWriteItem");
658 break;
659
660 case CMD_NV_WRITE_CDMA_PRL:
661 request = (MainThreadRequest) msg.obj;
662 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800663 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800664 break;
665
666 case EVENT_NV_WRITE_CDMA_PRL_DONE:
667 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
668 break;
669
chen xu1cc0abe2018-10-26 17:39:23 -0700670 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800671 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700672 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800673 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
chen xu1cc0abe2018-10-26 17:39:23 -0700676 case EVENT_RESET_MODEM_CONFIG_DONE:
677 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800678 break;
679
Jake Hamby7c27be32014-03-03 13:25:59 -0800680 case CMD_GET_PREFERRED_NETWORK_TYPE:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700683 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800684 break;
685
686 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
687 ar = (AsyncResult) msg.obj;
688 request = (MainThreadRequest) ar.userObj;
689 if (ar.exception == null && ar.result != null) {
690 request.result = ar.result; // Integer
691 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800692 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800693 if (ar.result == null) {
694 loge("getPreferredNetworkType: Empty response");
695 } else if (ar.exception instanceof CommandException) {
696 loge("getPreferredNetworkType: CommandException: " +
697 ar.exception);
698 } else {
699 loge("getPreferredNetworkType: Unknown exception");
700 }
701 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700702 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 break;
704
705 case CMD_SET_PREFERRED_NETWORK_TYPE:
706 request = (MainThreadRequest) msg.obj;
707 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
708 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700709 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 break;
711
712 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
713 handleNullReturnEvent(msg, "setPreferredNetworkType");
714 break;
715
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000716 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
717 request = (MainThreadRequest)msg.obj;
718 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800719 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000720 break;
721
722 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
723 ar = (AsyncResult)msg.obj;
724 request = (MainThreadRequest)ar.userObj;
725 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700726 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000727 break;
728
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800729 case CMD_SET_VOICEMAIL_NUMBER:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
732 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800733 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
734 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800735 break;
736
737 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
738 handleNullReturnEvent(msg, "setVoicemailNumber");
739 break;
740
Stuart Scott54788802015-03-30 13:18:01 -0700741 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
744 request);
745 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
746 break;
747
748 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
749 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
750 break;
751
Shishir Agrawal302c8692015-06-19 13:49:39 -0700752 case CMD_PERFORM_NETWORK_SCAN:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
755 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
756 break;
757
758 case EVENT_PERFORM_NETWORK_SCAN_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 CellNetworkScanResult cellScanResult;
762 if (ar.exception == null && ar.result != null) {
763 cellScanResult = new CellNetworkScanResult(
764 CellNetworkScanResult.STATUS_SUCCESS,
765 (List<OperatorInfo>) ar.result);
766 } else {
767 if (ar.result == null) {
768 loge("getCellNetworkScanResults: Empty response");
769 }
770 if (ar.exception != null) {
771 loge("getCellNetworkScanResults: Exception: " + ar.exception);
772 }
773 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
774 if (ar.exception instanceof CommandException) {
775 CommandException.Error error =
776 ((CommandException) (ar.exception)).getCommandError();
777 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
778 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
779 } else if (error == CommandException.Error.GENERIC_FAILURE) {
780 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
781 }
782 }
783 cellScanResult = new CellNetworkScanResult(errorCode, null);
784 }
785 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700786 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700787 break;
788
789 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
790 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700791 ManualNetworkSelectionArgument selArg =
792 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700793 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
794 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700795 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
796 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 break;
798
799 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700800 ar = (AsyncResult) msg.obj;
801 request = (MainThreadRequest) ar.userObj;
802 if (ar.exception == null) {
803 request.result = true;
804 } else {
805 request.result = false;
806 loge("setNetworkSelectionModeManual " + ar.exception);
807 }
808 notifyRequester(request);
809 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700812 case CMD_GET_MODEM_ACTIVITY_INFO:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800815 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700816 break;
817
818 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
819 ar = (AsyncResult) msg.obj;
820 request = (MainThreadRequest) ar.userObj;
821 if (ar.exception == null && ar.result != null) {
822 request.result = ar.result;
823 } else {
824 if (ar.result == null) {
825 loge("queryModemActivityInfo: Empty response");
826 } else if (ar.exception instanceof CommandException) {
827 loge("queryModemActivityInfo: CommandException: " +
828 ar.exception);
829 } else {
830 loge("queryModemActivityInfo: Unknown exception");
831 }
832 }
Amit Mahajand4766222016-01-28 15:28:28 -0800833 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
834 if (request.result == null) {
835 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
836 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700837 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700838 break;
839
Meng Wang1a7c35a2016-05-05 20:56:15 -0700840 case CMD_SET_ALLOWED_CARRIERS:
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800843 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700845 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700846 break;
847
848 case EVENT_SET_ALLOWED_CARRIERS_DONE:
849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null && ar.result != null) {
852 request.result = ar.result;
853 } else {
854 if (ar.result == null) {
855 loge("setAllowedCarriers: Empty response");
856 } else if (ar.exception instanceof CommandException) {
857 loge("setAllowedCarriers: CommandException: " +
858 ar.exception);
859 } else {
860 loge("setAllowedCarriers: Unknown exception");
861 }
862 }
863 // Result cannot be null. Return -1 on error.
864 if (request.result == null) {
865 request.result = new int[]{-1};
866 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700867 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700868 break;
869
870 case CMD_GET_ALLOWED_CARRIERS:
871 request = (MainThreadRequest) msg.obj;
872 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800873 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700874 break;
875
876 case EVENT_GET_ALLOWED_CARRIERS_DONE:
877 ar = (AsyncResult) msg.obj;
878 request = (MainThreadRequest) ar.userObj;
879 if (ar.exception == null && ar.result != null) {
880 request.result = ar.result;
881 } else {
882 if (ar.result == null) {
883 loge("getAllowedCarriers: Empty response");
884 } else if (ar.exception instanceof CommandException) {
885 loge("getAllowedCarriers: CommandException: " +
886 ar.exception);
887 } else {
888 loge("getAllowedCarriers: Unknown exception");
889 }
890 }
891 // Result cannot be null. Return empty list of CarrierIdentifier.
892 if (request.result == null) {
893 request.result = new ArrayList<CarrierIdentifier>(0);
894 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700895 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 break;
897
Nathan Haroldb3014052017-01-25 15:57:32 -0800898 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null && ar.result != null) {
902 request.result = ar.result;
903 } else {
904 request.result = new IllegalArgumentException(
905 "Failed to retrieve Forbidden Plmns");
906 if (ar.result == null) {
907 loge("getForbiddenPlmns: Empty response");
908 } else {
909 loge("getForbiddenPlmns: Unknown exception");
910 }
911 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700912 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800913 break;
914
915 case CMD_GET_FORBIDDEN_PLMNS:
916 request = (MainThreadRequest) msg.obj;
917 uiccCard = getUiccCardFromRequest(request);
918 if (uiccCard == null) {
919 loge("getForbiddenPlmns() UiccCard is null");
920 request.result = new IllegalArgumentException(
921 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700922 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800923 break;
924 }
925 Integer appType = (Integer) request.argument;
926 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
927 if (uiccApp == null) {
928 loge("getForbiddenPlmns() no app with specified type -- "
929 + appType);
930 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700931 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800932 break;
933 } else {
934 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
935 + " specified type -- " + appType);
936 }
937 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
938 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
939 onCompleted);
940 break;
941
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000942 case CMD_SWITCH_SLOTS:
943 request = (MainThreadRequest) msg.obj;
944 int[] physicalSlots = (int[]) request.argument;
945 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
946 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
947 break;
948
949 case EVENT_SWITCH_SLOTS_DONE:
950 ar = (AsyncResult) msg.obj;
951 request = (MainThreadRequest) ar.userObj;
952 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700953 notifyRequester(request);
954 break;
955 case CMD_GET_NETWORK_SELECTION_MODE:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
958 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
959 break;
960
961 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 if (ar.exception != null) {
965 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
966 } else {
967 int mode = ((int[]) ar.result)[0];
968 if (mode == 0) {
969 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
970 } else {
971 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
972 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000973 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700974 notifyRequester(request);
975 break;
976 case CMD_GET_CDMA_ROAMING_MODE:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
979 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
980 break;
981 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception != null) {
985 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
986 } else {
987 request.result = ((int[]) ar.result)[0];
988 }
989 notifyRequester(request);
990 break;
991 case CMD_SET_CDMA_ROAMING_MODE:
992 request = (MainThreadRequest) msg.obj;
993 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
994 int mode = (int) request.argument;
995 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
996 break;
997 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 request.result = ar.exception == null;
1001 notifyRequester(request);
1002 break;
1003 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1006 int subscriptionMode = (int) request.argument;
1007 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1008 break;
1009 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
1012 request.result = ar.exception == null;
1013 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001014 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001015 case CMD_GET_ALL_CELL_INFO:
1016 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001017 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001018 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 case EVENT_GET_ALL_CELL_INFO_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001023 // If a timeout occurs, the response will be null
1024 request.result = (ar.exception == null && ar.result != null)
1025 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001026 synchronized (request) {
1027 request.notifyAll();
1028 }
1029 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001030 case CMD_REQUEST_CELL_INFO_UPDATE:
1031 request = (MainThreadRequest) msg.obj;
1032 request.phone.requestCellInfoUpdate(request.workSource,
1033 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1034 break;
1035 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
1038 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1039 try {
1040 if (ar.exception != null) {
1041 // something went wrong... the response is null
1042 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1043 cb.onCellInfo(null);
1044 } else if (ar.result == null) {
1045 // timeout occurred, so force the result to non-null "empty"
1046 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1047 cb.onCellInfo(new ArrayList<CellInfo>());
1048 } else {
1049 // use the result as returned
1050 cb.onCellInfo((List<CellInfo>) ar.result);
1051 }
1052 } catch (RemoteException re) {
1053 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1054 }
1055 break;
1056 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 request = (MainThreadRequest) msg.obj;
1058 WorkSource ws = (WorkSource) request.argument;
1059 Phone phone = getPhoneFromRequest(request);
1060 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1061 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 if (ar.exception == null) {
1066 request.result = ar.result;
1067 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1070 ? new CdmaCellLocation() : new GsmCellLocation();
1071 }
1072
1073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001077 case CMD_MODEM_REBOOT:
1078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001080 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001081 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001082 case EVENT_CMD_MODEM_REBOOT_DONE:
1083 handleNullReturnEvent(msg, "rebootModem");
1084 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 default:
1086 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1087 break;
1088 }
1089 }
Jake Hambye994d462014-02-03 13:10:13 -08001090
Pengquan Meng0c05b502018-09-06 09:59:22 -07001091 private void notifyRequester(MainThreadRequest request) {
1092 synchronized (request) {
1093 request.notifyAll();
1094 }
1095 }
1096
Jake Hambye994d462014-02-03 13:10:13 -08001097 private void handleNullReturnEvent(Message msg, String command) {
1098 AsyncResult ar = (AsyncResult) msg.obj;
1099 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1100 if (ar.exception == null) {
1101 request.result = true;
1102 } else {
1103 request.result = false;
1104 if (ar.exception instanceof CommandException) {
1105 loge(command + ": CommandException: " + ar.exception);
1106 } else {
1107 loge(command + ": Unknown exception");
1108 }
1109 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001110 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001112 }
1113
1114 /**
1115 * Posts the specified command to be executed on the main thread,
1116 * waits for the request to complete, and returns the result.
1117 * @see #sendRequestAsync
1118 */
1119 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001120 return sendRequest(
1121 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001122 }
1123
1124 /**
1125 * Posts the specified command to be executed on the main thread,
1126 * waits for the request to complete, and returns the result.
1127 * @see #sendRequestAsync
1128 */
1129 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1130 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001131 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001132 }
1133
1134 /**
1135 * Posts the specified command to be executed on the main thread,
1136 * waits for the request to complete, and returns the result.
1137 * @see #sendRequestAsync
1138 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001139 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001140 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001141 }
1142
1143 /**
1144 * Posts the specified command to be executed on the main thread,
1145 * waits for the request to complete, and returns the result.
1146 * @see #sendRequestAsync
1147 */
Nathan Harold92bed182018-10-12 18:16:49 -07001148 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1149 return sendRequest(command, argument, subId, null, workSource);
1150 }
1151
1152 /**
1153 * Posts the specified command to be executed on the main thread,
1154 * waits for the request to complete, and returns the result.
1155 * @see #sendRequestAsync
1156 */
1157 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1158 return sendRequest(
1159 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1160 }
1161
1162 /**
1163 * Posts the specified command to be executed on the main thread,
1164 * waits for the request to complete, and returns the result.
1165 * @see #sendRequestAsync
1166 */
1167 private Object sendRequest(
1168 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1170 throw new RuntimeException("This method will deadlock if called from the main thread.");
1171 }
1172
Nathan Harold92bed182018-10-12 18:16:49 -07001173 MainThreadRequest request = null;
1174 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1175 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1176 } else if (phone != null) {
1177 request = new MainThreadRequest(argument, phone, workSource);
1178 } else {
1179 request = new MainThreadRequest(argument, subId, workSource);
1180 }
1181
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182 Message msg = mMainThreadHandler.obtainMessage(command, request);
1183 msg.sendToTarget();
1184
1185 // Wait for the request to complete
1186 synchronized (request) {
1187 while (request.result == null) {
1188 try {
1189 request.wait();
1190 } catch (InterruptedException e) {
1191 // Do nothing, go back and wait until the request is complete
1192 }
1193 }
1194 }
1195 return request.result;
1196 }
1197
1198 /**
1199 * Asynchronous ("fire and forget") version of sendRequest():
1200 * Posts the specified command to be executed on the main thread, and
1201 * returns immediately.
1202 * @see #sendRequest
1203 */
1204 private void sendRequestAsync(int command) {
1205 mMainThreadHandler.sendEmptyMessage(command);
1206 }
1207
1208 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001209 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001210 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001211 */
1212 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001213 sendRequestAsync(command, argument, null, null);
1214 }
1215
1216 /**
1217 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1218 * @see {@link #sendRequest(int,Object)}
1219 */
1220 private void sendRequestAsync(
1221 int command, Object argument, Phone phone, WorkSource workSource) {
1222 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001223 Message msg = mMainThreadHandler.obtainMessage(command, request);
1224 msg.sendToTarget();
1225 }
1226
1227 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 * Initialize the singleton PhoneInterfaceManager instance.
1229 * This is only done once, at startup, from PhoneApp.onCreate().
1230 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001231 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 synchronized (PhoneInterfaceManager.class) {
1233 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001234 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 } else {
1236 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1237 }
1238 return sInstance;
1239 }
1240 }
1241
1242 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001243 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001246 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1248 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001249 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001250 mTelephonySharedPreferences =
1251 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001252 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001253 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 publish();
1256 }
1257
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001258 private Phone getDefaultPhone() {
1259 Phone thePhone = getPhone(getDefaultSubscription());
1260 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1261 }
1262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 private void publish() {
1264 if (DBG) log("publish: " + this);
1265
1266 ServiceManager.addService("phone", this);
1267 }
1268
Stuart Scott584921c2015-01-15 17:10:34 -08001269 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001270 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001271 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001272 }
1273
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001274 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1275 Phone phone = getPhoneFromRequest(request);
1276 return phone == null ? null :
1277 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1278 }
1279
Wink Saville36469e72014-06-11 15:17:00 -07001280 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001281 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001282 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284
1285 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001286 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001287 }
1288
Wink Savilleb564aae2014-10-23 10:18:09 -07001289 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 if (DBG) log("dial: " + number);
1291 // No permission check needed here: This is just a wrapper around the
1292 // ACTION_DIAL intent, which is available to any app since it puts up
1293 // the UI before it does anything.
1294
Malcolm Chend965c8b2018-02-28 15:00:40 -08001295 final long identity = Binder.clearCallingIdentity();
1296 try {
1297 String url = createTelUrl(number);
1298 if (url == null) {
1299 return;
1300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301
Malcolm Chend965c8b2018-02-28 15:00:40 -08001302 // PENDING: should we just silently fail if phone is offhook or ringing?
1303 PhoneConstants.State state = mCM.getState(subId);
1304 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1305 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1306 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1307 mApp.startActivity(intent);
1308 }
1309 } finally {
1310 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 }
1312 }
1313
1314 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001315 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001316 }
1317
Wink Savilleb564aae2014-10-23 10:18:09 -07001318 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 if (DBG) log("call: " + number);
1320
1321 // This is just a wrapper around the ACTION_CALL intent, but we still
1322 // need to do a permission check since we're calling startActivity()
1323 // from the context of the phone app.
1324 enforceCallPermission();
1325
1326 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1327 != AppOpsManager.MODE_ALLOWED) {
1328 return;
1329 }
1330
Malcolm Chend965c8b2018-02-28 15:00:40 -08001331 final long identity = Binder.clearCallingIdentity();
1332 try {
1333 String url = createTelUrl(number);
1334 if (url == null) {
1335 return;
1336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337
Malcolm Chend965c8b2018-02-28 15:00:40 -08001338 boolean isValid = false;
1339 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1340 if (slist != null) {
1341 for (SubscriptionInfo subInfoRecord : slist) {
1342 if (subInfoRecord.getSubscriptionId() == subId) {
1343 isValid = true;
1344 break;
1345 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001346 }
Wink Saville08874612014-08-31 19:19:58 -07001347 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001348 if (!isValid) {
1349 return;
1350 }
Wink Saville08874612014-08-31 19:19:58 -07001351
Malcolm Chend965c8b2018-02-28 15:00:40 -08001352 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1353 intent.putExtra(SUBSCRIPTION_KEY, subId);
1354 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1355 mApp.startActivity(intent);
1356 } finally {
1357 Binder.restoreCallingIdentity(identity);
1358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 }
1360
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001362 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001363 }
1364
Wink Savilleb564aae2014-10-23 10:18:09 -07001365 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001366 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001367 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1368 }
1369
1370 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001376 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1377 }
1378
1379 /** {@hide} */
1380 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001381 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001382 }
1383
Wink Savilleb564aae2014-10-23 10:18:09 -07001384 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001386
1387 final long identity = Binder.clearCallingIdentity();
1388 try {
1389 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1390 checkSimPin.start();
1391 return checkSimPin.unlockSim(null, pin);
1392 } finally {
1393 Binder.restoreCallingIdentity(identity);
1394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 }
1396
Wink Saville9de0f752013-10-22 19:04:03 -07001397 /** {@hide} */
1398 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001400 }
1401
Wink Savilleb564aae2014-10-23 10:18:09 -07001402 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001404
1405 final long identity = Binder.clearCallingIdentity();
1406 try {
1407 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1408 checkSimPuk.start();
1409 return checkSimPuk.unlockSim(puk, pin);
1410 } finally {
1411 Binder.restoreCallingIdentity(identity);
1412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 }
1414
1415 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001416 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 * a synchronous one.
1418 */
1419 private static class UnlockSim extends Thread {
1420
1421 private final IccCard mSimCard;
1422
1423 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001424 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1425 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426
1427 // For replies from SimCard interface
1428 private Handler mHandler;
1429
1430 // For async handler to identify request type
1431 private static final int SUPPLY_PIN_COMPLETE = 100;
1432
1433 public UnlockSim(IccCard simCard) {
1434 mSimCard = simCard;
1435 }
1436
1437 @Override
1438 public void run() {
1439 Looper.prepare();
1440 synchronized (UnlockSim.this) {
1441 mHandler = new Handler() {
1442 @Override
1443 public void handleMessage(Message msg) {
1444 AsyncResult ar = (AsyncResult) msg.obj;
1445 switch (msg.what) {
1446 case SUPPLY_PIN_COMPLETE:
1447 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1448 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001449 mRetryCount = msg.arg1;
1450 if (ar.exception != null) {
1451 if (ar.exception instanceof CommandException &&
1452 ((CommandException)(ar.exception)).getCommandError()
1453 == CommandException.Error.PASSWORD_INCORRECT) {
1454 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1455 } else {
1456 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1457 }
1458 } else {
1459 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 mDone = true;
1462 UnlockSim.this.notifyAll();
1463 }
1464 break;
1465 }
1466 }
1467 };
1468 UnlockSim.this.notifyAll();
1469 }
1470 Looper.loop();
1471 }
1472
1473 /*
1474 * Use PIN or PUK to unlock SIM card
1475 *
1476 * If PUK is null, unlock SIM card with PIN
1477 *
1478 * If PUK is not null, unlock SIM card with PUK and set PIN code
1479 */
Wink Saville9de0f752013-10-22 19:04:03 -07001480 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481
1482 while (mHandler == null) {
1483 try {
1484 wait();
1485 } catch (InterruptedException e) {
1486 Thread.currentThread().interrupt();
1487 }
1488 }
1489 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1490
1491 if (puk == null) {
1492 mSimCard.supplyPin(pin, callback);
1493 } else {
1494 mSimCard.supplyPuk(puk, pin, callback);
1495 }
1496
1497 while (!mDone) {
1498 try {
1499 Log.d(LOG_TAG, "wait for done");
1500 wait();
1501 } catch (InterruptedException e) {
1502 // Restore the interrupted status
1503 Thread.currentThread().interrupt();
1504 }
1505 }
1506 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001507 int[] resultArray = new int[2];
1508 resultArray[0] = mResult;
1509 resultArray[1] = mRetryCount;
1510 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
1512 }
1513
1514 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001516
1517 }
1518
Wink Savilleb564aae2014-10-23 10:18:09 -07001519 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 // No permission check needed here: this call is harmless, and it's
1521 // needed for the ServiceState.requestStateUpdate() call (which is
1522 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001523 final long identity = Binder.clearCallingIdentity();
1524 try {
1525 final Phone phone = getPhone(subId);
1526 if (phone != null) {
1527 phone.updateServiceLocation();
1528 }
1529 } finally {
1530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001534 @Override
1535 public boolean isRadioOn(String callingPackage) {
1536 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001539 @Override
1540 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001542 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001543 return false;
1544 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 return isRadioOnForSubscriber(subId);
1549 } finally {
1550 Binder.restoreCallingIdentity(identity);
1551 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001552 }
1553
1554 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001555 final long identity = Binder.clearCallingIdentity();
1556 try {
1557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
1559 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1560 } else {
1561 return false;
1562 }
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
1568 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001569 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
Wink Saville36469e72014-06-11 15:17:00 -07001571
Wink Savilleb564aae2014-10-23 10:18:09 -07001572 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
1579 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1580 }
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001583 }
Wink Saville36469e72014-06-11 15:17:00 -07001584 }
1585
1586 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001587 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001588 }
1589
Wink Savilleb564aae2014-10-23 10:18:09 -07001590 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001591 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001592
1593 final long identity = Binder.clearCallingIdentity();
1594 try {
1595 final Phone phone = getPhone(subId);
1596 if (phone == null) {
1597 return false;
1598 }
1599 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1600 toggleRadioOnOffForSubscriber(subId);
1601 }
1602 return true;
1603 } finally {
1604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 }
Wink Saville36469e72014-06-11 15:17:00 -07001607
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001608 public boolean needMobileRadioShutdown() {
1609 /*
1610 * If any of the Radios are available, it will need to be
1611 * shutdown. So return true if any Radio is available.
1612 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001613 final long identity = Binder.clearCallingIdentity();
1614 try {
1615 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1616 Phone phone = PhoneFactory.getPhone(i);
1617 if (phone != null && phone.isRadioAvailable()) return true;
1618 }
1619 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1620 return false;
1621 } finally {
1622 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001623 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001624 }
1625
Malcolm Chend965c8b2018-02-28 15:00:40 -08001626 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001628 enforceModifyPermission();
1629
1630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1633 logv("Shutting down Phone " + i);
1634 shutdownRadioUsingPhoneId(i);
1635 }
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001638 }
1639 }
1640
1641 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001642 Phone phone = PhoneFactory.getPhone(phoneId);
1643 if (phone != null && phone.isRadioAvailable()) {
1644 phone.shutdownRadio();
1645 }
1646 }
1647
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001649 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001650
1651 final long identity = Binder.clearCallingIdentity();
1652 try {
1653 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1654 if (defaultPhone != null) {
1655 defaultPhone.setRadioPower(turnOn);
1656 return true;
1657 } else {
1658 loge("There's no default phone.");
1659 return false;
1660 }
1661 } finally {
1662 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001663 }
Wink Saville36469e72014-06-11 15:17:00 -07001664 }
1665
Wink Savilleb564aae2014-10-23 10:18:09 -07001666 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001668
1669 final long identity = Binder.clearCallingIdentity();
1670 try {
1671 final Phone phone = getPhone(subId);
1672 if (phone != null) {
1673 phone.setRadioPower(turnOn);
1674 return true;
1675 } else {
1676 return false;
1677 }
1678 } finally {
1679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682
Wink Saville36469e72014-06-11 15:17:00 -07001683 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 public boolean enableDataConnectivity() {
1686 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001687
1688 final long identity = Binder.clearCallingIdentity();
1689 try {
1690 int subId = mSubscriptionController.getDefaultDataSubId();
1691 final Phone phone = getPhone(subId);
1692 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001693 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001694 return true;
1695 } else {
1696 return false;
1697 }
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 }
1702
Wink Saville36469e72014-06-11 15:17:00 -07001703 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 public boolean disableDataConnectivity() {
1706 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001707
1708 final long identity = Binder.clearCallingIdentity();
1709 try {
1710 int subId = mSubscriptionController.getDefaultDataSubId();
1711 final Phone phone = getPhone(subId);
1712 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001713 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714 return true;
1715 } else {
1716 return false;
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 }
1722
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001724 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 final Phone phone = getPhone(subId);
1728 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001729 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001730 } else {
1731 return false;
1732 }
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 }
1737
1738 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001739 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001740 }
1741
pkanwarae03a6b2016-11-06 20:37:09 -08001742 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001743 enforceCallPermission();
1744
1745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1748 return;
1749 }
1750 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1751 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
1754 }
pkanwar32d516d2016-10-14 19:37:38 -07001755 };
1756
Wink Savilleb564aae2014-10-23 10:18:09 -07001757 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001759
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1763 return false;
1764 }
1765 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001772 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001773 }
1774
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001775 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 Phone phone = PhoneFactory.getPhone(slotIndex);
1779 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1780 PhoneConstantConversions.convertCallState(phone.getState());
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
1783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 }
1785
Sanket Padawe356d7632015-06-22 14:03:32 -07001786 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1791 if (phone != null) {
1792 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1793 } else {
1794 return PhoneConstantConversions.convertDataState(
1795 PhoneConstants.DataState.DISCONNECTED);
1796 }
1797 } finally {
1798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 }
1801
Sanket Padawe356d7632015-06-22 14:03:32 -07001802 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001804 final long identity = Binder.clearCallingIdentity();
1805 try {
1806 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1807 if (phone != null) {
1808 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1809 } else {
1810 return TelephonyManager.DATA_ACTIVITY_NONE;
1811 }
1812 } finally {
1813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
1817 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001818 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001819 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001820 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001821 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1822 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001823 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 if (DBG_LOC) log("getCellLocation: is active user");
1830 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001831 int subId = mSubscriptionController.getDefaultDataSubId();
1832 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1833 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001834 return data;
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
1837 }
Svetoslav64fad262015-04-14 14:35:21 -07001838 }
1839
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001841 public String getNetworkCountryIsoForPhone(int phoneId) {
1842 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1843 // registered cell info, so return a NULL country instead.
1844 final long identity = Binder.clearCallingIdentity();
1845 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001846 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1847 // Get default phone in this case.
1848 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1849 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001850 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001851 // Todo: fix this when we can get the actual cellular network info when the device
1852 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001853 if (TelephonyManager.NETWORK_TYPE_IWLAN
1854 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1855 return "";
1856 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001857 Phone phone = PhoneFactory.getPhone(phoneId);
1858 if (phone != null) {
1859 ServiceStateTracker sst = phone.getServiceStateTracker();
1860 if (sst != null) {
1861 LocaleTracker lt = sst.getLocaleTracker();
1862 if (lt != null) {
1863 return lt.getCurrentCountry();
1864 }
1865 }
1866 }
1867 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001868 } finally {
1869 Binder.restoreCallingIdentity(identity);
1870 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001871 }
1872
1873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001875 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001876 }
1877
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001879 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 mApp.enforceCallingOrSelfPermission(
1881 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001882
1883 final long identity = Binder.clearCallingIdentity();
1884 try {
1885 final Phone phone = getPhone(subId);
1886 if (phone != null) {
1887 phone.enableLocationUpdates();
1888 }
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
1894 @Override
1895 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001896 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001897 }
1898
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001900 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 mApp.enforceCallingOrSelfPermission(
1902 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001903
1904 final long identity = Binder.clearCallingIdentity();
1905 try {
1906 final Phone phone = getPhone(subId);
1907 if (phone != null) {
1908 phone.disableLocationUpdates();
1909 }
1910 } finally {
1911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
Nathan Harold31d7ff32018-10-15 20:20:30 -07001915 /**
1916 * Returns the target SDK version number for a given package name.
1917 *
1918 * @return target SDK if the package is found or INT_MAX.
1919 */
1920 private int getTargetSdk(String packageName) {
1921 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001922 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1923 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001924 if (ai != null) return ai.targetSdkVersion;
1925 } catch (PackageManager.NameNotFoundException unexpected) {
1926 }
1927 return Integer.MAX_VALUE;
1928 }
1929
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 @Override
1931 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001932 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1933 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001934 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1935 throw new SecurityException(
1936 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1937 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001938
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1940 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1941 return null;
1942 }
Svetoslav64fad262015-04-14 14:35:21 -07001943
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001944 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945
Nathan Haroldf180aac2018-06-01 18:43:55 -07001946 List<CellInfo> info = getAllCellInfo(callingPackage);
1947 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948
Nathan Haroldf180aac2018-06-01 18:43:55 -07001949 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1950 for (CellInfo ci : info) {
1951 if (ci instanceof CellInfoGsm) {
1952 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1953 } else if (ci instanceof CellInfoWcdma) {
1954 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001957 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 }
1959
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001960 private List<CellInfo> getCachedCellInfo() {
1961 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1962 for (Phone phone : PhoneFactory.getPhones()) {
1963 List<CellInfo> info = phone.getAllCellInfo();
1964 if (info != null) cellInfos.addAll(info);
1965 }
1966 return cellInfos;
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968
1969 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001970 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001971 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001972 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001973 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001974 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001975 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
1977
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001978 final int targetSdk = getTargetSdk(callingPackage);
1979 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1980 return getCachedCellInfo();
1981 }
1982
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001983 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1988 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001989 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001990 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001991 if (info != null) cellInfos.addAll(info);
1992 }
1993 return cellInfos;
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997 }
1998
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001999 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002000 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2001 requestCellInfoUpdateInternal(
2002 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2003 }
2004
2005 @Override
2006 public void requestCellInfoUpdateWithWorkSource(
2007 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2008 enforceModifyPermission();
2009 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2010 }
2011
2012 private void requestCellInfoUpdateInternal(
2013 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002014 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002015 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002016 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2017 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002018 return;
2019 }
2020
2021 final Phone phone = getPhone(subId);
2022 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2023
2024 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2025 }
2026
2027 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002029 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002031
2032 final long identity = Binder.clearCallingIdentity();
2033 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002034 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002035 } finally {
2036 Binder.restoreCallingIdentity(identity);
2037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 }
2039
Shishir Agrawala9f32182016-04-12 12:00:16 -07002040 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002041 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002042 Phone phone = PhoneFactory.getPhone(slotIndex);
2043 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002044 return null;
2045 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002046 int subId = phone.getSubId();
2047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2048 mApp, subId, callingPackage, "getImeiForSlot")) {
2049 return null;
2050 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002051
2052 final long identity = Binder.clearCallingIdentity();
2053 try {
2054 return phone.getImei();
2055 } finally {
2056 Binder.restoreCallingIdentity(identity);
2057 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002058 }
2059
2060 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002061 public String getTypeAllocationCodeForSlot(int slotIndex) {
2062 Phone phone = PhoneFactory.getPhone(slotIndex);
2063 String tac = null;
2064 if (phone != null) {
2065 String imei = phone.getImei();
2066 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2067 }
2068 return tac;
2069 }
2070
2071 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002072 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002073 Phone phone = PhoneFactory.getPhone(slotIndex);
2074 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002075 return null;
2076 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002077
Jeff Davidson913390f2018-02-23 17:11:49 -08002078 int subId = phone.getSubId();
2079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2080 mApp, subId, callingPackage, "getMeidForSlot")) {
2081 return null;
2082 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002083
2084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 return phone.getMeid();
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
2089 }
Jack Yu2af8d712017-03-15 17:14:14 -07002090 }
2091
2092 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002093 public String getManufacturerCodeForSlot(int slotIndex) {
2094 Phone phone = PhoneFactory.getPhone(slotIndex);
2095 String manufacturerCode = null;
2096 if (phone != null) {
2097 String meid = phone.getMeid();
2098 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2099 }
2100 return manufacturerCode;
2101 }
2102
2103 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002104 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002105 Phone phone = PhoneFactory.getPhone(slotIndex);
2106 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002107 return null;
2108 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002109 int subId = phone.getSubId();
2110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2111 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2112 return null;
2113 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002114
2115 final long identity = Binder.clearCallingIdentity();
2116 try {
2117 return phone.getDeviceSvn();
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002121 }
2122
fionaxu43304da2017-11-27 22:51:16 -08002123 @Override
2124 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
2131 }
fionaxu43304da2017-11-27 22:51:16 -08002132 }
2133
2134 @Override
2135 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 final Phone phone = getPhone(subId);
2139 return phone == null ? null : phone.getCarrierName();
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
fionaxu43304da2017-11-27 22:51:16 -08002143 }
2144
calvinpaneed9ae82018-11-01 19:43:06 +08002145 @Override
chen xuc93cc282018-11-04 17:17:00 -08002146 public int getSubscriptionPreciseCarrierId(int subId) {
2147 final long identity = Binder.clearCallingIdentity();
2148 try {
2149 final Phone phone = getPhone(subId);
2150 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2151 : phone.getPreciseCarrierId();
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
2155 }
2156
2157 @Override
2158 public String getSubscriptionPreciseCarrierName(int subId) {
2159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 final Phone phone = getPhone(subId);
2162 return phone == null ? null : phone.getPreciseCarrierName();
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
2165 }
2166 }
2167
chen xu02581692018-11-11 19:03:44 -08002168 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002169 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2170 if (!isSubscriptionMccMnc) {
2171 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2172 }
chen xu02581692018-11-11 19:03:44 -08002173 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() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002208 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002209 "ConnectivityService");
2210 }
2211
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 private String createTelUrl(String number) {
2213 if (TextUtils.isEmpty(number)) {
2214 return null;
2215 }
2216
Jake Hambye994d462014-02-03 13:10:13 -08002217 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219
Ihab Awadf9e92732013-12-05 18:02:52 -08002220 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2222 }
2223
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002224 private static void logv(String msg) {
2225 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2226 }
2227
Ihab Awadf9e92732013-12-05 18:02:52 -08002228 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2230 }
2231
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002232 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002234 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002235 }
2236
Sanket Padawe356d7632015-06-22 14:03:32 -07002237 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002238 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 final Phone phone = PhoneFactory.getPhone(slotIndex);
2242 if (phone == null) {
2243 return PhoneConstants.PHONE_TYPE_NONE;
2244 } else {
2245 return phone.getPhoneType();
2246 }
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
2252 /**
2253 * Returns the CDMA ERI icon index to display
2254 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002255 @Override
2256 public int getCdmaEriIconIndex(String callingPackage) {
2257 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002258 }
2259
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002261 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002263 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002264 return -1;
2265 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002266
2267 final long identity = Binder.clearCallingIdentity();
2268 try {
2269 final Phone phone = getPhone(subId);
2270 if (phone != null) {
2271 return phone.getCdmaEriIconIndex();
2272 } else {
2273 return -1;
2274 }
2275 } finally {
2276 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 }
2279
2280 /**
2281 * Returns the CDMA ERI icon mode,
2282 * 0 - ON
2283 * 1 - FLASHING
2284 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002285 @Override
2286 public int getCdmaEriIconMode(String callingPackage) {
2287 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002288 }
2289
Sanket Padawe356d7632015-06-22 14:03:32 -07002290 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002294 return -1;
2295 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002296
2297 final long identity = Binder.clearCallingIdentity();
2298 try {
2299 final Phone phone = getPhone(subId);
2300 if (phone != null) {
2301 return phone.getCdmaEriIconMode();
2302 } else {
2303 return -1;
2304 }
2305 } finally {
2306 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
2310 /**
2311 * Returns the CDMA ERI text,
2312 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002313 @Override
2314 public String getCdmaEriText(String callingPackage) {
2315 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002319 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002321 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 return null;
2323 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 final Phone phone = getPhone(subId);
2328 if (phone != null) {
2329 return phone.getCdmaEriText();
2330 } else {
2331 return null;
2332 }
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 }
2337
2338 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002339 * Returns the CDMA MDN.
2340 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002342 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2344 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002345
2346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002349 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002350 return phone.getLine1Number();
2351 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002352 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002353 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 {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002411 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002412 } 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);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002437 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002438 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 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002448 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002449 } 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 {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002464 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002465 } finally {
2466 Binder.restoreCallingIdentity(identity);
2467 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002468 }
2469
2470 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002471 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2472 VisualVoicemailSmsFilterSettings settings) {
2473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474
2475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002478 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002479 } finally {
2480 Binder.restoreCallingIdentity(identity);
2481 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002482 }
2483
2484 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002485 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002491 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002495 }
2496
2497 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002498 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2499 String callingPackage, int subId) {
2500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002501
2502 final long identity = Binder.clearCallingIdentity();
2503 try {
2504 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002505 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002506 } finally {
2507 Binder.restoreCallingIdentity(identity);
2508 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002509 }
2510
2511 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002512 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002513 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002514
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002518 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002519 } finally {
2520 Binder.restoreCallingIdentity(identity);
2521 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002522 }
2523
2524 @Override
2525 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2526 String number, int port, String text, PendingIntent sentIntent) {
2527 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002528 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002529 enforceSendSmsPermission();
2530 // Make the calls as the phone process.
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2534 if (port == 0) {
2535 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2536 sentIntent, null, false);
2537 } else {
2538 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2539 smsManager.sendDataMessageWithSelfPermissions(number, null,
2540 (short) port, data, sentIntent, null);
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002545 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002546 /**
fionaxu0152e512016-11-14 13:36:14 -08002547 * Sets the voice activation state of a given subId.
2548 */
2549 @Override
2550 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2552 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002553
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 final Phone phone = getPhone(subId);
2557 if (phone != null) {
2558 phone.setVoiceActivationState(activationState);
2559 } else {
2560 loge("setVoiceActivationState fails with invalid subId: " + subId);
2561 }
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002564 }
2565 }
2566
2567 /**
2568 * Sets the data activation state of a given subId.
2569 */
2570 @Override
2571 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2573 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null) {
2579 phone.setDataActivationState(activationState);
2580 } else {
2581 loge("setVoiceActivationState fails with invalid subId: " + subId);
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002585 }
2586 }
2587
2588 /**
2589 * Returns the voice activation state of a given subId.
2590 */
2591 @Override
2592 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002593 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002594
fionaxu0152e512016-11-14 13:36:14 -08002595 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 if (phone != null) {
2599 return phone.getVoiceActivationState();
2600 } else {
2601 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002605 }
2606 }
2607
2608 /**
2609 * Returns the data activation state of a given subId.
2610 */
2611 @Override
2612 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002613 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002614
fionaxu0152e512016-11-14 13:36:14 -08002615 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 if (phone != null) {
2619 return phone.getDataActivationState();
2620 } else {
2621 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2622 }
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002625 }
2626 }
2627
2628 /**
Wink Saville36469e72014-06-11 15:17:00 -07002629 * Returns the unread count of voicemails for a subId
2630 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002631 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002632 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2634 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2635 return 0;
2636 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 if (phone != null) {
2641 return phone.getVoiceMessageCount();
2642 } else {
2643 return 0;
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 }
2649
2650 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002651 * returns true, if the device is in a state where both voice and data
2652 * are supported simultaneously. This can change based on location or network condition.
2653 */
2654 @Override
2655 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(subId);
2659 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002663 }
2664
2665 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002666 * Send the dialer code if called from the current default dialer or the caller has
2667 * carrier privilege.
2668 * @param inputCode The dialer code to send
2669 */
2670 @Override
2671 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002672 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002674 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2675 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002676 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002677 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2678 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002679 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002683 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002684 } finally {
2685 Binder.restoreCallingIdentity(identity);
2686 }
fionaxu235cc5e2017-03-06 22:25:57 -08002687 }
2688
2689 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002690 * Returns the data network type.
2691 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 *
2693 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2694 */
2695 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002696 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(getDefaultSubscription());
2700 if (phone != null) {
2701 return phone.getServiceState().getDataNetworkType();
2702 } else {
2703 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002707 }
Wink Saville36469e72014-06-11 15:17:00 -07002708 }
2709
Pengquan Meng0c05b502018-09-06 09:59:22 -07002710 @Override
2711 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002712 if (!isActiveSubscription(subId)) {
2713 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2714 }
2715
Pengquan Meng0c05b502018-09-06 09:59:22 -07002716 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2717 }
2718
Brad Ebinger4c460712018-10-01 10:40:55 -07002719 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002720 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2721 throws RemoteException {
2722 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2724 final long token = Binder.clearCallingIdentity();
2725 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002726 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002727 .addRegistrationCallbackForSubscription(c, subId);
2728 } finally {
2729 Binder.restoreCallingIdentity(token);
2730 }
2731 }
2732
2733 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002734 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2735 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2737 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002738 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002739 .removeRegistrationCallbackForSubscription(c, subId));
2740 }
2741
2742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002743 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2744 throws RemoteException {
2745 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002746 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2747 final long token = Binder.clearCallingIdentity();
2748 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002749 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002750 .addCapabilitiesCallbackForSubscription(c, subId);
2751 } finally {
2752 Binder.restoreCallingIdentity(token);
2753 }
2754 }
2755
2756 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002757 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2758 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2760 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002761 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002762 .removeCapabilitiesCallbackForSubscription(c, subId));
2763 }
2764
2765 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002766 public boolean isCapable(int subId, int capability, int regTech) {
2767 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2769 final long token = Binder.clearCallingIdentity();
2770 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002771 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002772 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2773 } catch (ImsException e) {
2774 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2775 return false;
2776 } finally {
2777 Binder.restoreCallingIdentity(token);
2778 }
2779 }
2780
2781 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002782 public boolean isAvailable(int subId, int capability, int regTech) {
2783 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002784 final long token = Binder.clearCallingIdentity();
2785 try {
2786 Phone phone = getPhone(subId);
2787 if (phone == null) return false;
2788 return phone.isImsCapabilityAvailable(capability, regTech);
2789 } finally {
2790 Binder.restoreCallingIdentity(token);
2791 }
2792 }
2793
2794 @Override
2795 public boolean isAdvancedCallingSettingEnabled(int subId) {
2796 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2797 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2798 final long token = Binder.clearCallingIdentity();
2799 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002800 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002801 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2802 } finally {
2803 Binder.restoreCallingIdentity(token);
2804 }
2805 }
2806
2807 @Override
2808 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2810 "setAdvancedCallingSetting");
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002814 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002815 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
2819 }
2820
2821 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002822 public boolean isVtSettingEnabled(int subId) {
2823 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002827 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002828 getSlotIndexOrException(subId)).isVtEnabledByUser();
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
2831 }
2832 }
2833
2834 @Override
2835 public void setVtSetting(int subId, boolean isEnabled) {
2836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2837 "setVtSetting");
2838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002841 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002842 } 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.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002853 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002854 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.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002867 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002868 } finally {
2869 Binder.restoreCallingIdentity(identity);
2870 }
2871 }
2872
2873 @Override
2874 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2875 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002879 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002880 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
2883 }
2884 }
2885
2886 @Override
2887 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2889 "setVoWiFiRoamingSetting");
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002893 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002894 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
2897 }
2898 }
2899
2900 @Override
2901 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2903 "setVoWiFiNonPersistent");
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002907 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002908 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
2912 }
2913
2914 @Override
2915 public int getVoWiFiModeSetting(int subId) {
2916 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002920 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002921 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
2924 }
2925 }
2926
2927 @Override
2928 public void setVoWiFiModeSetting(int subId, int mode) {
2929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2930 "setVoWiFiModeSetting");
2931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002934 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002935 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
2939 }
2940
2941 @Override
2942 public int getVoWiFiRoamingModeSetting(int subId) {
2943 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002947 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002948 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
2951 }
2952 }
2953
2954 @Override
2955 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2957 "setVoWiFiRoamingModeSetting");
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002961 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002962 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
2966 }
2967
2968 @Override
2969 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2971 "setRttCapabilityEnabled");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002975 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002976 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2977 } finally {
2978 Binder.restoreCallingIdentity(identity);
2979 }
2980 }
2981
2982 @Override
2983 public boolean isTtyOverVolteEnabled(int subId) {
2984 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002988 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002989 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
2993 }
2994
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002995 @Override
2996 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2997 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003001 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003002 .getConfigInterface().addConfigCallback(callback);
3003 } catch (ImsException e) {
3004 throw new IllegalArgumentException(e.getMessage());
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
3011 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3012 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003016 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003017 .getConfigInterface().removeConfigCallback(callback);
3018 } catch (ImsException e) {
3019 throw new IllegalArgumentException(e.getMessage());
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
3023 }
3024
3025 @Override
3026 public int getImsProvisioningInt(int subId, int key) {
3027 enforceReadPrivilegedPermission("getImsProvisioningInt");
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003031 return ImsManager.getInstance(mApp,
3032 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003033 } catch (ImsException e) {
3034 throw new IllegalArgumentException(e.getMessage());
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
3038 }
3039
3040 @Override
3041 public String getImsProvisioningString(int subId, int key) {
3042 enforceReadPrivilegedPermission("getImsProvisioningString");
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003046 return ImsManager.getInstance(mApp,
3047 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003048 } catch (ImsException e) {
3049 throw new IllegalArgumentException(e.getMessage());
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
3053 }
3054
3055 @Override
3056 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3058 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003062 return ImsManager.getInstance(mApp,
3063 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003064 } catch (ImsException e) {
3065 throw new IllegalArgumentException(e.getMessage());
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
3069 }
3070
3071 @Override
3072 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3074 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003078 return ImsManager.getInstance(mApp,
3079 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003080 } catch (ImsException e) {
3081 throw new IllegalArgumentException(e.getMessage());
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
3085 }
3086
Brad Ebinger4c460712018-10-01 10:40:55 -07003087 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3088 int slotId = SubscriptionManager.getSlotIndex(subId);
3089 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3090 throw new IllegalArgumentException("Invalid Subscription Id.");
3091 }
3092 return slotId;
3093 }
3094
Wink Saville36469e72014-06-11 15:17:00 -07003095 /**
3096 * Returns the network type for a subId
3097 */
3098 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003099 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003101 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003102 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3103 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003104
Malcolm Chend965c8b2018-02-28 15:00:40 -08003105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 final Phone phone = getPhone(subId);
3108 if (phone != null) {
3109 return phone.getServiceState().getDataNetworkType();
3110 } else {
3111 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3112 }
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 }
3117
3118 /**
3119 * Returns the data network type
3120 */
3121 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003122 public int getDataNetworkType(String callingPackage) {
3123 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003124 }
3125
3126 /**
3127 * Returns the data network type for a subId
3128 */
3129 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003130 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003132 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003133 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3134 }
3135
Malcolm Chend965c8b2018-02-28 15:00:40 -08003136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 final Phone phone = getPhone(subId);
3139 if (phone != null) {
3140 return phone.getServiceState().getDataNetworkType();
3141 } else {
3142 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3143 }
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147 }
3148
3149 /**
Wink Saville36469e72014-06-11 15:17:00 -07003150 * Returns the Voice network type for a subId
3151 */
3152 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003153 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003154 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003155 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003156 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3157 }
3158
Malcolm Chend965c8b2018-02-28 15:00:40 -08003159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 final Phone phone = getPhone(subId);
3162 if (phone != null) {
3163 return phone.getServiceState().getVoiceNetworkType();
3164 } else {
3165 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3166 }
3167 } finally {
3168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 }
3171
3172 /**
3173 * @return true if a ICC card is present
3174 */
3175 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003176 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003177 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3178 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003179 }
3180
3181 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003182 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003183 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003184 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003185 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 final Phone phone = PhoneFactory.getPhone(slotIndex);
3189 if (phone != null) {
3190 return phone.getIccCard().hasIccCard();
3191 } else {
3192 return false;
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
3199 /**
3200 * Return if the current radio is LTE on CDMA. This
3201 * is a tri-state return value as for a period of time
3202 * the mode may be unknown.
3203 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003204 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003206 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003208 @Override
3209 public int getLteOnCdmaMode(String callingPackage) {
3210 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003211 }
3212
Sanket Padawe356d7632015-06-22 14:03:32 -07003213 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003214 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003216 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003217 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3218 }
3219
Malcolm Chend965c8b2018-02-28 15:00:40 -08003220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 final Phone phone = getPhone(subId);
3223 if (phone == null) {
3224 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3225 } else {
3226 return phone.getLteOnCdmaMode();
3227 }
3228 } finally {
3229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003230 }
Wink Saville36469e72014-06-11 15:17:00 -07003231 }
3232
Wink Saville36469e72014-06-11 15:17:00 -07003233 /**
3234 * {@hide}
3235 * Returns Default subId, 0 in the case of single standby.
3236 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003237 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003238 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003239 }
3240
Shishir Agrawala9f32182016-04-12 12:00:16 -07003241 private int getSlotForDefaultSubscription() {
3242 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3243 }
3244
Wink Savilleb564aae2014-10-23 10:18:09 -07003245 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003246 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003247 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003248
Pengquan Meng466e2482018-09-21 15:54:48 -07003249 private boolean isActiveSubscription(int subId) {
3250 return mSubscriptionController.isActiveSubId(subId);
3251 }
3252
Ihab Awadf2177b72013-11-25 13:33:23 -08003253 /**
3254 * @see android.telephony.TelephonyManager.WifiCallingChoices
3255 */
3256 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003257 final long identity = Binder.clearCallingIdentity();
3258 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003259 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003260 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3261 getWhenToMakeWifiCallsDefaultPreference());
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
3264 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003265 }
3266
3267 /**
3268 * @see android.telephony.TelephonyManager.WifiCallingChoices
3269 */
3270 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003274 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003275 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003279 }
3280
Sailesh Nepald1e68152013-12-12 19:08:02 -08003281 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003282 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003283 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003284 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003285
Shishir Agrawal566b7612013-10-28 14:41:00 -07003286 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003287 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3288 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3290 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003291 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003292
Malcolm Chend965c8b2018-02-28 15:00:40 -08003293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 if (TextUtils.equals(ISDR_AID, aid)) {
3296 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003297 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3298 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003299 if (bestComponent == null
3300 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3301 loge("The calling package is not allowed to access ISD-R.");
3302 throw new SecurityException(
3303 "The calling package is not allowed to access ISD-R.");
3304 }
Derek Tan740e1672017-06-27 14:56:27 -07003305 }
Derek Tan740e1672017-06-27 14:56:27 -07003306
Malcolm Chend965c8b2018-02-28 15:00:40 -08003307 if (DBG) {
3308 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3309 }
3310 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3311 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3312 if (DBG) log("iccOpenLogicalChannel: " + response);
3313 return response;
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003317 }
3318
3319 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003320 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3322 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003323
Malcolm Chend965c8b2018-02-28 15:00:40 -08003324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3327 if (channel < 0) {
3328 return false;
3329 }
3330 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3331 if (DBG) log("iccCloseLogicalChannel: " + success);
3332 return success;
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003335 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003336 }
3337
3338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003339 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003340 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3342 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003343
Malcolm Chend965c8b2018-02-28 15:00:40 -08003344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 if (DBG) {
3347 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3348 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3349 + p3 + " data=" + data);
3350 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003351
Malcolm Chend965c8b2018-02-28 15:00:40 -08003352 if (channel < 0) {
3353 return "";
3354 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003355
Malcolm Chend965c8b2018-02-28 15:00:40 -08003356 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3357 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3358 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003359
Malcolm Chend965c8b2018-02-28 15:00:40 -08003360 // Append the returned status code to the end of the response payload.
3361 String s = Integer.toHexString(
3362 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3363 if (response.payload != null) {
3364 s = IccUtils.bytesToHexString(response.payload) + s;
3365 }
3366 return s;
3367 } finally {
3368 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003369 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003370 }
Jake Hambye994d462014-02-03 13:10:13 -08003371
Evan Charltonc66da362014-05-16 14:06:40 -07003372 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003373 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3374 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3376 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003377 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003378
Malcolm Chend965c8b2018-02-28 15:00:40 -08003379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3382 && TextUtils.equals(ISDR_AID, data)) {
3383 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003384 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3385 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003386 if (bestComponent == null
3387 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3388 loge("The calling package is not allowed to select ISD-R.");
3389 throw new SecurityException(
3390 "The calling package is not allowed to select ISD-R.");
3391 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003392 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003393
Malcolm Chend965c8b2018-02-28 15:00:40 -08003394 if (DBG) {
3395 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3396 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3397 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003398
Malcolm Chend965c8b2018-02-28 15:00:40 -08003399 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3400 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3401 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003402
Malcolm Chend965c8b2018-02-28 15:00:40 -08003403 // Append the returned status code to the end of the response payload.
3404 String s = Integer.toHexString(
3405 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3406 if (response.payload != null) {
3407 s = IccUtils.bytesToHexString(response.payload) + s;
3408 }
3409 return s;
3410 } finally {
3411 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003412 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003413 }
3414
3415 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003416 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003417 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3419 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003420
Malcolm Chend965c8b2018-02-28 15:00:40 -08003421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 if (DBG) {
3424 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3425 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3426 }
3427
3428 IccIoResult response =
3429 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3430 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3431 subId);
3432
3433 if (DBG) {
3434 log("Exchange SIM_IO [R]" + response);
3435 }
3436
3437 byte[] result = null;
3438 int length = 2;
3439 if (response.payload != null) {
3440 length = 2 + response.payload.length;
3441 result = new byte[length];
3442 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3443 } else {
3444 result = new byte[length];
3445 }
3446
3447 result[length - 1] = (byte) response.sw2;
3448 result[length - 2] = (byte) response.sw1;
3449 return result;
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003452 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003453 }
3454
Nathan Haroldb3014052017-01-25 15:57:32 -08003455 /**
3456 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3457 * on a particular subscription
3458 */
sqianb6e41952018-03-12 14:54:01 -07003459 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3461 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3462 return null;
3463 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003464
3465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 if (appType != TelephonyManager.APPTYPE_USIM
3468 && appType != TelephonyManager.APPTYPE_SIM) {
3469 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3470 return null;
3471 }
3472 Object response = sendRequest(
3473 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3474 if (response instanceof String[]) {
3475 return (String[]) response;
3476 }
3477 // Response is an Exception of some kind,
3478 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003479 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003480 } finally {
3481 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003482 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003483 }
3484
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003485 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003486 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3488 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003489
Malcolm Chend965c8b2018-02-28 15:00:40 -08003490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3493 if (response.payload == null) {
3494 return "";
3495 }
Evan Charltonc66da362014-05-16 14:06:40 -07003496
Malcolm Chend965c8b2018-02-28 15:00:40 -08003497 // Append the returned status code to the end of the response payload.
3498 String s = Integer.toHexString(
3499 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3500 s = IccUtils.bytesToHexString(response.payload) + s;
3501 return s;
3502 } finally {
3503 Binder.restoreCallingIdentity(identity);
3504 }
Evan Charltonc66da362014-05-16 14:06:40 -07003505 }
3506
Jake Hambye994d462014-02-03 13:10:13 -08003507 /**
3508 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3509 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3510 *
3511 * @param itemID the ID of the item to read
3512 * @return the NV item as a String, or null on error.
3513 */
3514 @Override
3515 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003516 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3518 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003519
3520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003523 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003524 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3525 return value;
3526 } finally {
3527 Binder.restoreCallingIdentity(identity);
3528 }
Jake Hambye994d462014-02-03 13:10:13 -08003529 }
3530
3531 /**
3532 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3533 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3534 *
3535 * @param itemID the ID of the item to read
3536 * @param itemValue the value to write, as a String
3537 * @return true on success; false on any failure
3538 */
3539 @Override
3540 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003541 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3543 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3548 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003549 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003550 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3551 return success;
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
Jake Hambye994d462014-02-03 13:10:13 -08003555 }
3556
3557 /**
3558 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3559 * Used for device configuration by some CDMA operators.
3560 *
3561 * @param preferredRoamingList byte array containing the new PRL
3562 * @return true on success; false on any failure
3563 */
3564 @Override
3565 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3567 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003568
3569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3572 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3573 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3574 return success;
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
Jake Hambye994d462014-02-03 13:10:13 -08003578 }
3579
3580 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003581 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003582 * Used for device configuration by some CDMA operators.
3583 *
chen xu1cc0abe2018-10-26 17:39:23 -07003584 * @param slotIndex - device slot.
3585 *
Jake Hambye994d462014-02-03 13:10:13 -08003586 * @return true on success; false on any failure
3587 */
3588 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003589 public boolean resetModemConfig(int slotIndex) {
3590 Phone phone = PhoneFactory.getPhone(slotIndex);
3591 if (phone != null) {
3592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3593 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003594
chen xu1cc0abe2018-10-26 17:39:23 -07003595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3598 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3599 return success;
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003603 }
chen xu1cc0abe2018-10-26 17:39:23 -07003604 return false;
3605 }
3606
3607 /**
3608 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3609 *
3610 * @param slotIndex - device slot.
3611 *
3612 * @return true on success; false on any failure
3613 */
3614 @Override
3615 public boolean rebootModem(int slotIndex) {
3616 Phone phone = PhoneFactory.getPhone(slotIndex);
3617 if (phone != null) {
3618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3619 mApp, phone.getSubId(), "rebootModem");
3620
3621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3624 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3625 return success;
3626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
3629 }
3630 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003631 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003632
Svet Ganovb320e182015-04-16 12:30:10 -07003633 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003634 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003636 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003637 return new String[0];
3638 }
3639
Malcolm Chend965c8b2018-02-28 15:00:40 -08003640 final long identity = Binder.clearCallingIdentity();
3641 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003642 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
Wink Saville36469e72014-06-11 15:17:00 -07003646 }
3647
Brad Ebinger51f743a2017-01-23 13:50:20 -08003648 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003649 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3650 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003651 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003652 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003653 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 PhoneFactory.getImsResolver().enableIms(slotId);
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003661 }
3662
3663 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003664 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3665 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003666 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003667 public void disableIms(int slotId) {
3668 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 PhoneFactory.getImsResolver().disableIms(slotId);
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003676 }
3677
3678 /**
3679 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3680 * feature or {@link null} if the service is not available. If the feature is available, the
3681 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3682 */
3683 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003684 IImsServiceFeatureCallback callback) {
3685 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003693 }
3694
3695 /**
3696 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3697 * feature during emergency calling or {@link null} if the service is not available. If the
3698 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3699 * listener for feature updates.
3700 */
3701 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3702 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003703
3704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003710 }
3711
Brad Ebinger5f64b052017-12-14 14:26:15 -08003712 /**
3713 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3714 * specified.
3715 */
3716 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3717 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003718
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3722 } finally {
3723 Binder.restoreCallingIdentity(identity);
3724 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003725 }
3726
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003727 /**
3728 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3729 * specified.
3730 */
3731 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3732 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003733
3734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003740 }
3741
Brad Ebinger884c07b2018-02-15 16:17:40 -08003742 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003743 * Sets the ImsService Package Name that Telephony will bind to.
3744 *
3745 * @param slotId the slot ID that the ImsService should bind for.
3746 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3747 * ImsService is the device default ImsService.
3748 * @param packageName The package name of the application that contains the ImsService to bind
3749 * to.
3750 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3751 * @hide
3752 */
3753 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003754 int[] subIds = SubscriptionManager.getSubId(slotId);
3755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3756 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3757 "setImsService");
3758
Malcolm Chend965c8b2018-02-28 15:00:40 -08003759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3762 isCarrierImsService, packageName);
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003766 }
3767
3768 /**
3769 * Return the ImsService configuration.
3770 *
3771 * @param slotId The slot that the ImsService is associated with.
3772 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3773 * the device default.
3774 * @return the package name of the ImsService configuration.
3775 */
3776 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003777 int[] subIds = SubscriptionManager.getSubId(slotId);
3778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3779 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3780 "getImsService");
3781
Malcolm Chend965c8b2018-02-28 15:00:40 -08003782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3785 isCarrierImsService);
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003789 }
3790
Wink Saville36469e72014-06-11 15:17:00 -07003791 public void setImsRegistrationState(boolean registered) {
3792 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003793
3794 final long identity = Binder.clearCallingIdentity();
3795 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003796 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
Wink Saville36469e72014-06-11 15:17:00 -07003800 }
3801
3802 /**
Stuart Scott54788802015-03-30 13:18:01 -07003803 * Set the network selection mode to automatic.
3804 *
3805 */
3806 @Override
3807 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3809 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003810
Pengquan Meng466e2482018-09-21 15:54:48 -07003811 if (!isActiveSubscription(subId)) {
3812 return;
3813 }
3814
Malcolm Chend965c8b2018-02-28 15:00:40 -08003815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3818 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3819 } finally {
3820 Binder.restoreCallingIdentity(identity);
3821 }
Stuart Scott54788802015-03-30 13:18:01 -07003822 }
3823
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003824 /**
3825 * Ask the radio to connect to the input network and change selection mode to manual.
3826 *
3827 * @param subId the id of the subscription.
3828 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3829 * the operator to attach to.
3830 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3831 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3832 * normal network selection next time.
3833 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003834 */
3835 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003836 public boolean setNetworkSelectionModeManual(
3837 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3839 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003840
3841 if (!isActiveSubscription(subId)) {
3842 return false;
3843 }
3844
Malcolm Chend965c8b2018-02-28 15:00:40 -08003845 final long identity = Binder.clearCallingIdentity();
3846 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003847 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003848 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003849 if (DBG) {
3850 log("setNetworkSelectionModeManual: subId: " + subId
3851 + " operator: " + operatorInfo);
3852 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003857 }
3858
3859 /**
3860 * Scans for available networks.
3861 */
3862 @Override
3863 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3865 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003866
Pengquan Meng0c05b502018-09-06 09:59:22 -07003867 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003868 try {
3869 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003870 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003871 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003875 }
3876
3877 /**
yinxub1bed742017-04-17 11:45:04 -07003878 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003879 *
yinxub1bed742017-04-17 11:45:04 -07003880 * @param subId id of the subscription
3881 * @param request contains the radio access networks with bands/channels to scan
3882 * @param messenger callback messenger for scan results or errors
3883 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003884 * @return the id of the requested scan which can be used to stop the scan.
3885 */
3886 @Override
3887 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3888 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3890 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003891
3892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 return mNetworkScanRequestTracker.startNetworkScan(
3895 request, messenger, binder, getPhone(subId));
3896 } finally {
3897 Binder.restoreCallingIdentity(identity);
3898 }
yinxu504e1392017-04-12 16:03:22 -07003899 }
3900
3901 /**
3902 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003903 *
3904 * @param subId id of the subscription
3905 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003906 */
3907 @Override
3908 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3910 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003911
3912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3915 } finally {
3916 Binder.restoreCallingIdentity(identity);
3917 }
yinxu504e1392017-04-12 16:03:22 -07003918 }
3919
3920 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003921 * Get the calculated preferred network type.
3922 * Used for debugging incorrect network type.
3923 *
3924 * @return the preferred network type, defined in RILConstants.java.
3925 */
3926 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003927 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003928 final Phone defaultPhone = getDefaultPhone();
3929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3930 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003931 return RILConstants.PREFERRED_NETWORK_MODE;
3932 }
3933
Malcolm Chend965c8b2018-02-28 15:00:40 -08003934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003937 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
Junda Liu84d15a22014-07-02 11:21:04 -07003941 }
3942
3943 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003944 * Get the preferred network type.
3945 * Used for device configuration by some CDMA operators.
3946 *
3947 * @return the preferred network type, defined in RILConstants.java.
3948 */
3949 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003950 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3952 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003953
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 if (DBG) log("getPreferredNetworkType");
3957 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3958 int networkType = (result != null ? result[0] : -1);
3959 if (DBG) log("getPreferredNetworkType: " + networkType);
3960 return networkType;
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003964 }
3965
3966 /**
3967 * Set the preferred network type.
3968 * Used for device configuration by some CDMA operators.
3969 *
3970 * @param networkType the preferred network type, defined in RILConstants.java.
3971 * @return true on success; false on any failure.
3972 */
3973 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003974 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3976 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003977
3978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3981 Boolean success = (Boolean) sendRequest(
3982 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3983 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3984 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003985 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003986 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3987 }
3988 return success;
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003991 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003992 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003993
3994 /**
Junda Liu475951f2014-11-07 16:45:03 -08003995 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003996 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003997 * tethering.
3998 *
3999 * @return 0: Not required. 1: required. 2: Not set.
4000 * @hide
4001 */
4002 @Override
4003 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004004 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004005
4006 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004007 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004008 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004009 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004010 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004011 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004012 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004013 dunRequired = 1;
4014 }
4015 return dunRequired;
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004018 }
Junda Liu475951f2014-11-07 16:45:03 -08004019 }
4020
4021 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004022 * Set mobile data enabled
4023 * Used by the user through settings etc to turn on/off mobile data
4024 *
4025 * @param enable {@code true} turn turn data on, else {@code false}
4026 */
4027 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004028 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4030 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 int phoneId = mSubscriptionController.getPhoneId(subId);
4035 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4036 Phone phone = PhoneFactory.getPhone(phoneId);
4037 if (phone != null) {
4038 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004039 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004040 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004041 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004042 }
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004045 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004046 }
4047
4048 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004049 * Get the user enabled state of Mobile Data.
4050 *
4051 * TODO: remove and use isUserDataEnabled.
4052 * This can't be removed now because some vendor codes
4053 * calls through ITelephony directly while they should
4054 * use TelephonyManager.
4055 *
4056 * @return true on enabled
4057 */
4058 @Override
4059 public boolean getDataEnabled(int subId) {
4060 return isUserDataEnabled(subId);
4061 }
4062
4063 /**
4064 * Get whether mobile data is enabled per user setting.
4065 *
4066 * There are other factors deciding whether mobile data is actually enabled, but they are
4067 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004068 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004069 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004070 *
4071 * @return {@code true} if data is enabled else {@code false}
4072 */
4073 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004074 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004075 try {
4076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4077 null);
4078 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004081 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004082
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 int phoneId = mSubscriptionController.getPhoneId(subId);
4086 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4087 Phone phone = PhoneFactory.getPhone(phoneId);
4088 if (phone != null) {
4089 boolean retVal = phone.isUserDataEnabled();
4090 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4091 return retVal;
4092 } else {
4093 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4094 return false;
4095 }
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004098 }
4099 }
4100
4101 /**
4102 * Get whether mobile data is enabled.
4103 *
4104 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4105 * whether mobile data is actually enabled.
4106 *
4107 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4108 *
4109 * @return {@code true} if data is enabled else {@code false}
4110 */
4111 @Override
4112 public boolean isDataEnabled(int subId) {
4113 try {
4114 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4115 null);
4116 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4118 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004119 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004120
4121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 int phoneId = mSubscriptionController.getPhoneId(subId);
4124 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4125 Phone phone = PhoneFactory.getPhone(phoneId);
4126 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004127 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004128 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4129 return retVal;
4130 } else {
4131 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4132 return false;
4133 }
4134 } finally {
4135 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004136 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004137 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004138
4139 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004140 public int getCarrierPrivilegeStatus(int subId) {
4141 final Phone phone = getPhone(subId);
4142 if (phone == null) {
4143 loge("getCarrierPrivilegeStatus: Invalid subId");
4144 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4145 }
4146 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004147 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004148 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4150 }
4151 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004152 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004153 }
Junda Liu29340342014-07-10 15:23:27 -07004154
4155 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4157 final Phone phone = getPhone(subId);
4158 if (phone == null) {
4159 loge("getCarrierPrivilegeStatus: Invalid subId");
4160 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4161 }
4162 UiccProfile profile =
4163 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4164 if (profile == null) {
4165 loge("getCarrierPrivilegeStatus: No UICC");
4166 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4167 }
4168 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4169 }
4170
4171 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004172 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004173 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004174 if (TextUtils.isEmpty(pkgName))
4175 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004176 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004177 if (card == null) {
4178 loge("checkCarrierPrivilegesForPackage: No UICC");
4179 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4180 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004181 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4182 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004183 }
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
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004197 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004198 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4199 break;
4200 }
4201 }
4202
4203 return result;
Junda Liu29340342014-07-10 15:23:27 -07004204 }
Derek Tan89e89d42014-07-08 17:00:10 -07004205
4206 @Override
Junda Liue64de782015-04-16 17:19:16 -07004207 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4208 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4209 loge("phoneId " + phoneId + " is not valid.");
4210 return null;
4211 }
4212 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004213 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004214 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004215 return null ;
4216 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004217 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004218 }
4219
Amith Yamasani6e118872016-02-19 12:53:51 -08004220 @Override
4221 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004222 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004223 List<String> privilegedPackages = new ArrayList<>();
4224 List<PackageInfo> packages = null;
4225 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4226 UiccCard card = UiccController.getInstance().getUiccCard(i);
4227 if (card == null) {
4228 // No UICC in that slot.
4229 continue;
4230 }
4231 if (card.hasCarrierPrivilegeRules()) {
4232 if (packages == null) {
4233 // Only check packages in user 0 for now
4234 packages = pm.getInstalledPackagesAsUser(
4235 PackageManager.MATCH_DISABLED_COMPONENTS
4236 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4237 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4238 }
4239 for (int p = packages.size() - 1; p >= 0; p--) {
4240 PackageInfo pkgInfo = packages.get(p);
4241 if (pkgInfo != null && pkgInfo.packageName != null
4242 && card.getCarrierPrivilegeStatus(pkgInfo)
4243 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4244 privilegedPackages.add(pkgInfo.packageName);
4245 }
4246 }
4247 }
4248 }
4249 return privilegedPackages;
4250 }
4251
Wink Savilleb564aae2014-10-23 10:18:09 -07004252 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004253 final Phone phone = getPhone(subId);
4254 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004255 if (card == null) {
4256 loge("getIccId: No UICC");
4257 return null;
4258 }
4259 String iccId = card.getIccId();
4260 if (TextUtils.isEmpty(iccId)) {
4261 loge("getIccId: ICC ID is null or empty.");
4262 return null;
4263 }
4264 return iccId;
4265 }
4266
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004267 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004268 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4269 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4271 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004272
Malcolm Chend965c8b2018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 final String iccId = getIccId(subId);
4276 final Phone phone = getPhone(subId);
4277 if (phone == null) {
4278 return false;
4279 }
4280 final String subscriberId = phone.getSubscriberId();
4281
4282 if (DBG_MERGE) {
4283 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4284 + subscriberId + " to " + number);
4285 }
4286
4287 if (TextUtils.isEmpty(iccId)) {
4288 return false;
4289 }
4290
4291 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4292
4293 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4294 if (alphaTag == null) {
4295 editor.remove(alphaTagPrefKey);
4296 } else {
4297 editor.putString(alphaTagPrefKey, alphaTag);
4298 }
4299
4300 // Record both the line number and IMSI for this ICCID, since we need to
4301 // track all merged IMSIs based on line number
4302 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4303 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4304 if (number == null) {
4305 editor.remove(numberPrefKey);
4306 editor.remove(subscriberPrefKey);
4307 } else {
4308 editor.putString(numberPrefKey, number);
4309 editor.putString(subscriberPrefKey, subscriberId);
4310 }
4311
4312 editor.commit();
4313 return true;
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004316 }
Derek Tan7226c842014-07-02 17:42:23 -07004317 }
4318
4319 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004320 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004321 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004323 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004324 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004325 return null;
4326 }
Derek Tan97ebb422014-09-05 16:55:38 -07004327
Malcolm Chend965c8b2018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 String iccId = getIccId(subId);
4331 if (iccId != null) {
4332 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4333 if (DBG_MERGE) {
4334 log("getLine1NumberForDisplay returning "
4335 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4336 }
4337 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004338 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004339 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4340 return null;
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004343 }
Derek Tan7226c842014-07-02 17:42:23 -07004344 }
4345
4346 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004347 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004349 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004350 return null;
4351 }
Derek Tan97ebb422014-09-05 16:55:38 -07004352
Malcolm Chend965c8b2018-02-28 15:00:40 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 String iccId = getIccId(subId);
4356 if (iccId != null) {
4357 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4358 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4359 }
4360 return null;
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004363 }
Derek Tan7226c842014-07-02 17:42:23 -07004364 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004365
4366 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004367 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004368 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4369 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004371 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4372 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004373 return null;
4374 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004375
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004376 final long identity = Binder.clearCallingIdentity();
4377 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004378 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004379 final TelephonyManager tele = TelephonyManager.from(context);
4380 final SubscriptionManager sub = SubscriptionManager.from(context);
4381
4382 // Figure out what subscribers are currently active
4383 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4384 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4385 // the process, where TelephonyManager was instantiated.
4386 // Otherwise AppOps check will fail.
4387
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004388 final int[] subIds = sub.getActiveSubscriptionIdList();
4389 for (int subId : subIds) {
4390 activeSubscriberIds.add(tele.getSubscriberId(subId));
4391 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004392
4393 // First pass, find a number override for an active subscriber
4394 String mergeNumber = null;
4395 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4396 for (String key : prefs.keySet()) {
4397 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4398 final String subscriberId = (String) prefs.get(key);
4399 if (activeSubscriberIds.contains(subscriberId)) {
4400 final String iccId = key.substring(
4401 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4402 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4403 mergeNumber = (String) prefs.get(numberKey);
4404 if (DBG_MERGE) {
4405 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4406 + " for active subscriber " + subscriberId);
4407 }
4408 if (!TextUtils.isEmpty(mergeNumber)) {
4409 break;
4410 }
4411 }
4412 }
4413 }
4414
4415 // Shortcut when no active merged subscribers
4416 if (TextUtils.isEmpty(mergeNumber)) {
4417 return null;
4418 }
4419
4420 // Second pass, find all subscribers under that line override
4421 final ArraySet<String> result = new ArraySet<>();
4422 for (String key : prefs.keySet()) {
4423 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4424 final String number = (String) prefs.get(key);
4425 if (mergeNumber.equals(number)) {
4426 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4427 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4428 final String subscriberId = (String) prefs.get(subscriberKey);
4429 if (!TextUtils.isEmpty(subscriberId)) {
4430 result.add(subscriberId);
4431 }
4432 }
4433 }
4434 }
4435
4436 final String[] resultArray = result.toArray(new String[result.size()]);
4437 Arrays.sort(resultArray);
4438 if (DBG_MERGE) {
4439 Slog.d(LOG_TAG,
4440 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4441 }
4442 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004445 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004446 }
4447
4448 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004449 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004450 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4451 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004452
4453 final long identity = Binder.clearCallingIdentity();
4454 try {
4455 final Phone phone = getPhone(subId);
4456 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004460 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004461
4462 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004463 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004464 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4465 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004466 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004467
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 final Phone phone = getPhone(subId);
4471 if (phone == null) {
4472 return false;
4473 }
4474 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4475 cdmaNonRoamingList);
4476 } finally {
4477 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004478 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004479 }
4480
4481 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004482 @Deprecated
4483 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4484 enforceModifyPermission();
4485
4486 int returnValue = 0;
4487 try {
vagdevie435a3e2018-08-15 16:01:53 -07004488 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004489 if(result.exception == null) {
4490 if (result.result != null) {
4491 byte[] responseData = (byte[])(result.result);
4492 if(responseData.length > oemResp.length) {
4493 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4494 responseData.length + "bytes. Buffer Size is " +
4495 oemResp.length + "bytes.");
4496 }
4497 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4498 returnValue = responseData.length;
4499 }
4500 } else {
4501 CommandException ex = (CommandException) result.exception;
4502 returnValue = ex.getCommandError().ordinal();
4503 if(returnValue > 0) returnValue *= -1;
4504 }
4505 } catch (RuntimeException e) {
4506 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4507 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4508 if(returnValue > 0) returnValue *= -1;
4509 }
4510
4511 return returnValue;
4512 }
4513
4514 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004515 public void setRadioCapability(RadioAccessFamily[] rafs) {
4516 try {
4517 ProxyController.getInstance().setRadioCapability(rafs);
4518 } catch (RuntimeException e) {
4519 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4520 }
4521 }
4522
4523 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004524 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004525 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004526 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004527 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004528 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004529 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
chen xufeeed752018-10-26 14:17:57 -07004532 TelephonyPermissions
4533 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4534 mApp, phone.getSubId(), "getRadioAccessFamily");
4535 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
chen xufeeed752018-10-26 14:17:57 -07004539 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004540 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004541
4542 @Override
4543 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004544 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004545 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004546
4547 final long identity = Binder.clearCallingIdentity();
4548 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004549 ImsManager.getInstance(defaultPhone.getContext(),
4550 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004551 } 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) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004558 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004560 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004561 return false;
4562 }
Svet Ganovb320e182015-04-16 12:30:10 -07004563
Malcolm Chend965c8b2018-02-28 15:00:40 -08004564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 // Check the user preference and the system-level IMS setting. Even if the user has
4567 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4568 // In the long run, we may instead need to check if there exists a connection service
4569 // which can support video calling.
4570 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004571 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004572 return imsManager.isVtEnabledByPlatform()
4573 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4574 && imsManager.isVtEnabledByUser();
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004578 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004579
Andrew Leea1239f22015-03-02 17:44:07 -08004580 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004581 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4583 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4584 return false;
4585 }
4586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 CarrierConfigManager configManager =
4590 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004591 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004592 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
Andrew Leea1239f22015-03-02 17:44:07 -08004596 }
4597
4598 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004599 public boolean isWorldPhone(int subId, String callingPackage) {
4600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4601 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4602 return false;
4603 }
4604
4605 final long identity = Binder.clearCallingIdentity();
4606 try {
4607 CarrierConfigManager configManager =
4608 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004609 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004610 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
4613 }
Andrew Leea1239f22015-03-02 17:44:07 -08004614 }
4615
Andrew Lee9431b832015-03-09 18:46:45 -07004616 @Override
4617 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004618 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004619 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004620 }
4621
4622 @Override
4623 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004624 final long identity = Binder.clearCallingIdentity();
4625 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004626 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
Andrew Lee9431b832015-03-09 18:46:45 -07004630 }
4631
Hall Liuf6668912018-10-31 17:05:23 -07004632 /**
4633 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4634 * support for the feature and device firmware support.
4635 *
4636 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4637 */
4638 @Override
4639 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004641 final Phone phone = getPhone(subscriptionId);
4642 if (phone == null) {
4643 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4644 return false;
4645 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004646 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004647 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004648 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4649 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004650 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004651 return isCarrierSupported && isDeviceSupported;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Hall Liu98187582018-01-22 19:15:32 -08004655 }
4656
Hall Liuf6668912018-10-31 17:05:23 -07004657 /**
4658 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4659 * both also support RTT.
4660 */
4661 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004662 final long identity = Binder.clearCallingIdentity();
4663 try {
Hall Liuf6668912018-10-31 17:05:23 -07004664 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004665 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004669 }
4670
Sanket Padawe7310cc72015-01-14 09:53:20 -08004671 /**
4672 * Returns the unique device ID of phone, for example, the IMEI for
4673 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4674 *
4675 * <p>Requires Permission:
4676 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4677 */
4678 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004679 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004680 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004681 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004682 return null;
4683 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004684 int subId = phone.getSubId();
4685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4686 mApp, subId, callingPackage, "getDeviceId")) {
4687 return null;
4688 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 return phone.getDeviceId();
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004696 }
4697
Ping Sunc67b7c22016-03-02 19:16:45 +08004698 /**
4699 * {@hide}
4700 * Returns the IMS Registration Status on a particular subid
4701 *
4702 * @param subId
4703 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004704 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004705 Phone phone = getPhone(subId);
4706 if (phone != null) {
4707 return phone.isImsRegistered();
4708 } else {
4709 return false;
4710 }
4711 }
4712
Santos Cordon7a1885b2015-02-03 11:15:19 -08004713 @Override
4714 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004721 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004722
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004723 /**
4724 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004725 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004726 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 Phone phone = getPhone(subId);
4730 if (phone != null) {
4731 return phone.isWifiCallingEnabled();
4732 } else {
4733 return false;
4734 }
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004737 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004738 }
4739
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004740 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004741 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004742 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004743 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 Phone phone = getPhone(subId);
4747 if (phone != null) {
4748 return phone.isVideoEnabled();
4749 } else {
4750 return false;
4751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004754 }
4755 }
4756
4757 /**
4758 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4759 * defined in {@link ImsRegistrationImplBase}.
4760 */
4761 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004762 final long identity = Binder.clearCallingIdentity();
4763 try {
4764 Phone phone = getPhone(subId);
4765 if (phone != null) {
4766 return phone.getImsRegistrationTech();
4767 } else {
4768 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4769 }
4770 } finally {
4771 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004772 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004773 }
4774
Stuart Scott8eef64f2015-04-08 15:13:54 -07004775 @Override
4776 public void factoryReset(int subId) {
4777 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004778 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4779 return;
4780 }
4781
Svet Ganovcc087f82015-05-12 20:35:54 -07004782 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004783
Svet Ganovcc087f82015-05-12 20:35:54 -07004784 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004785 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4786 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004787 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004788 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004789 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004790 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4791 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004792 }
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004795 }
4796 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004797
4798 @Override
4799 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004800 final long identity = Binder.clearCallingIdentity();
4801 try {
4802 // We query all subscriptions instead of just the active ones, because
4803 // this might be called early on in the provisioning flow when the
4804 // subscriptions potentially aren't active yet.
4805 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4806 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004807 return null;
4808 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004809
Malcolm Chend965c8b2018-02-28 15:00:40 -08004810 // This function may be called very early, say, from the setup wizard, at
4811 // which point we won't have a default subscription set. If that's the case
4812 // we just choose the first, which will be valid in "most cases".
4813 final int defaultSubId = getDefaultSubscription();
4814 SubscriptionInfo info = null;
4815 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4816 info = slist.get(0);
4817 } else {
4818 for (SubscriptionInfo item : slist) {
4819 if (item.getSubscriptionId() == defaultSubId) {
4820 info = item;
4821 break;
4822 }
4823 }
4824
4825 if (info == null) {
4826 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004827 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004828 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004829
Malcolm Chend965c8b2018-02-28 15:00:40 -08004830 // Try and fetch the locale from the carrier properties or from the SIM language
4831 // preferences (EF-PL and EF-LI)...
4832 final int mcc = info.getMcc();
4833 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4834 String simLanguage = null;
4835 if (defaultPhone != null) {
4836 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4837 if (localeFromDefaultSim != null) {
4838 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4839 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4840 return localeFromDefaultSim.toLanguageTag();
4841 } else {
4842 simLanguage = localeFromDefaultSim.getLanguage();
4843 }
4844 }
4845 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004846
Malcolm Chend965c8b2018-02-28 15:00:40 -08004847 // The SIM language preferences only store a language (e.g. fr = French), not an
4848 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4849 // the SIM and carrier preferences does not include a country we add the country
4850 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004851 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004852 if (mccLocale != null) {
4853 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4854 return mccLocale.toLanguageTag();
4855 }
4856
4857 if (DBG) log("No locale found - returning null");
4858 return null;
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
4861 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004862 }
4863
4864 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004865 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004866 }
4867
Malcolm Chend965c8b2018-02-28 15:00:40 -08004868 /**
4869 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4870 */
4871 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004872 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004873 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004874
Chenjie Yu1ba97252018-01-11 18:16:20 -08004875 private final ModemActivityInfo mLastModemActivityInfo =
4876 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4877
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004878 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004879 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4880 * representing the state of the modem.
4881 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004882 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4883 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004884 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004885 */
4886 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004887 public void requestModemActivityInfo(ResultReceiver result) {
4888 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004890
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 ModemActivityInfo ret = null;
4894 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004895 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4896 CMD_GET_MODEM_ACTIVITY_INFO,
4897 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004898 if (isModemActivityInfoValid(info)) {
4899 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4900 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4901 mergedTxTimeMs[i] =
4902 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4903 }
4904 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4905 mLastModemActivityInfo.setSleepTimeMillis(
4906 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4907 mLastModemActivityInfo.setIdleTimeMillis(
4908 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4909 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4910 mLastModemActivityInfo.setRxTimeMillis(
4911 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4912 mLastModemActivityInfo.setEnergyUsed(
4913 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004914 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004915 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4916 mLastModemActivityInfo.getSleepTimeMillis(),
4917 mLastModemActivityInfo.getIdleTimeMillis(),
4918 mLastModemActivityInfo.getTxTimeMillis(),
4919 mLastModemActivityInfo.getRxTimeMillis(),
4920 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004921 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004922 Bundle bundle = new Bundle();
4923 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4924 result.send(0, bundle);
4925 } finally {
4926 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004927 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004928 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004929
Siddharth Rayf5d29552018-06-17 15:02:38 -07004930 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4931 // less than total activity duration.
4932 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4933 if (info == null) {
4934 return false;
4935 }
4936 int activityDurationMs =
4937 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4938 int totalTxTimeMs = 0;
4939 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4940 totalTxTimeMs += info.getTxTimeMillis()[i];
4941 }
4942 return (info.isValid()
4943 && (info.getSleepTimeMillis() <= activityDurationMs)
4944 && (info.getIdleTimeMillis() <= activityDurationMs)
4945 && (info.getRxTimeMillis() <= activityDurationMs)
4946 && (totalTxTimeMs <= activityDurationMs));
4947 }
4948
Jack Yu85bd38a2015-11-09 11:34:32 -08004949 /**
4950 * {@hide}
4951 * Returns the service state information on specified subscription.
4952 */
4953 @Override
4954 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004956 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004957 return null;
4958 }
4959
Malcolm Chend965c8b2018-02-28 15:00:40 -08004960 final long identity = Binder.clearCallingIdentity();
4961 try {
4962 final Phone phone = getPhone(subId);
4963 if (phone == null) {
4964 return null;
4965 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004966
Malcolm Chend965c8b2018-02-28 15:00:40 -08004967 return phone.getServiceState();
4968 } finally {
4969 Binder.restoreCallingIdentity(identity);
4970 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004971 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004972
4973 /**
4974 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4975 *
4976 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4977 * voicemail ringtone.
4978 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4979 * PhoneAccount.
4980 */
4981 @Override
4982 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4986 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004987 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004988 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004989
Malcolm Chend965c8b2018-02-28 15:00:40 -08004990 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004994 }
4995
4996 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004997 * Sets the per-account voicemail ringtone.
4998 *
4999 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5000 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5001 *
5002 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5003 * voicemail ringtone.
5004 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5005 * PhoneAccount.
5006 */
5007 @Override
5008 public void setVoicemailRingtoneUri(String callingPackage,
5009 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005010 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005011 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5012 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005013 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5015 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5016 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005017 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005018
5019 final long identity = Binder.clearCallingIdentity();
5020 try {
5021 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5022 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005023 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005024 }
5025 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005028 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005029 }
5030
5031 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005032 * Returns whether vibration is set for voicemail notification in Phone settings.
5033 *
5034 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5035 * voicemail vibration setting.
5036 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5037 */
5038 @Override
5039 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5043 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005044 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005046
Malcolm Chend965c8b2018-02-28 15:00:40 -08005047 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005051 }
5052
Youhan Wange64578a2016-05-02 15:32:42 -07005053 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005054 * Sets the per-account voicemail vibration.
5055 *
5056 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5057 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5058 *
5059 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5060 * voicemail vibration setting.
5061 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5062 * specific PhoneAccount.
5063 */
5064 @Override
5065 public void setVoicemailVibrationEnabled(String callingPackage,
5066 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005067 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5069 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005070 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5073 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005074 }
5075
Malcolm Chend965c8b2018-02-28 15:00:40 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5079 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005080 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005081 }
5082 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005085 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005086 }
5087
5088 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005089 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5090 *
5091 * @throws SecurityException if the caller does not have the required permission
5092 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005093 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005094 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005095 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005096 }
5097
5098 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005099 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5100 * permission.
5101 *
5102 * @throws SecurityException if the caller does not have the required permission
5103 */
5104 private void enforceSendSmsPermission() {
5105 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5106 }
5107
5108 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005109 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005110 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005111 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005112 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005113 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005114 final long identity = Binder.clearCallingIdentity();
5115 try {
5116 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005117 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005118 if (componentName == null) {
5119 throw new SecurityException(
5120 "Caller not current active visual voicemail package[null]");
5121 }
5122 String vvmPackage = componentName.getPackageName();
5123 if (!callingPackage.equals(vvmPackage)) {
5124 throw new SecurityException("Caller not current active visual voicemail package["
5125 + vvmPackage + "]");
5126 }
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005129 }
5130 }
5131
5132 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005133 * Return the application ID for the app type.
5134 *
5135 * @param subId the subscription ID that this request applies to.
5136 * @param appType the uicc app type.
5137 * @return Application ID for specificied app type, or null if no uicc.
5138 */
5139 @Override
5140 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005141 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005142 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143
5144 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005145 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005146 if (phone == null) {
5147 return null;
5148 }
5149 String aid = null;
5150 try {
5151 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5152 .getApplicationByType(appType).getAid();
5153 } catch (Exception e) {
5154 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5155 }
5156 return aid;
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005159 }
Youhan Wange64578a2016-05-02 15:32:42 -07005160 }
5161
Youhan Wang4001d252016-05-11 10:29:41 -07005162 /**
5163 * Return the Electronic Serial Number.
5164 *
5165 * @param subId the subscription ID that this request applies to.
5166 * @return ESN or null if error.
5167 */
5168 @Override
5169 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005170 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005171 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005172
5173 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005174 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005175 if (phone == null) {
5176 return null;
5177 }
5178 String esn = null;
5179 try {
5180 esn = phone.getEsn();
5181 } catch (Exception e) {
5182 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5183 }
5184 return esn;
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005187 }
Youhan Wang4001d252016-05-11 10:29:41 -07005188 }
5189
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005190 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005191 * Return the Preferred Roaming List Version.
5192 *
5193 * @param subId the subscription ID that this request applies to.
5194 * @return PRLVersion or null if error.
5195 */
5196 @Override
5197 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005198 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005199 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005200
5201 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005202 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005203 if (phone == null) {
5204 return null;
5205 }
5206 String cdmaPrlVersion = null;
5207 try {
5208 cdmaPrlVersion = phone.getCdmaPrlVersion();
5209 } catch (Exception e) {
5210 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5211 }
5212 return cdmaPrlVersion;
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005215 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005216 }
5217
5218 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005219 * Get snapshot of Telephony histograms
5220 * @return List of Telephony histograms
5221 * @hide
5222 */
5223 @Override
5224 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5226 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227
5228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 return RIL.getTelephonyRILTimingHistograms();
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005234 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005235
5236 /**
5237 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005238 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005239 * Require system privileges. In the future we may add this to carrier APIs.
5240 *
5241 * @return The number of carriers set successfully, should match length of carriers
5242 */
5243 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005244 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005245 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005246 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005247
Meng Wang9b7c4e92017-02-17 11:41:27 -08005248 if (carriers == null) {
5249 throw new NullPointerException("carriers cannot be null");
5250 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005251
Malcolm Chend965c8b2018-02-28 15:00:40 -08005252 final long identity = Binder.clearCallingIdentity();
5253 try {
Michele85121de2018-12-19 15:25:20 -08005254 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5255 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005256 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5257 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005258 return retVal[0];
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005262 }
5263
5264 /**
5265 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005266 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005267 * Require system privileges. In the future we may add this to carrier APIs.
5268 *
5269 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5270 * means all carriers are allowed.
5271 */
5272 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005273 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005274 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005276
5277 final long identity = Binder.clearCallingIdentity();
5278 try {
Michele85121de2018-12-19 15:25:20 -08005279 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5280 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005281 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5282 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005286 }
5287
fionaxu59545b42016-05-25 15:53:37 -07005288 /**
5289 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5290 * @param subId the subscription ID that this action applies to.
5291 * @param enabled control enable or disable metered apns.
5292 * {@hide}
5293 */
5294 @Override
5295 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5296 enforceModifyPermission();
5297 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005298
5299 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005300 if (phone == null) {
5301 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5302 return;
5303 }
5304 try {
5305 phone.carrierActionSetMeteredApnsEnabled(enabled);
5306 } catch (Exception e) {
5307 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005308 } finally {
5309 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005310 }
5311 }
5312
5313 /**
5314 * Action set from carrier signalling broadcast receivers to enable/disable radio
5315 * @param subId the subscription ID that this action applies to.
5316 * @param enabled control enable or disable radio.
5317 * {@hide}
5318 */
5319 @Override
5320 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5321 enforceModifyPermission();
5322 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005323
5324 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005325 if (phone == null) {
5326 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5327 return;
5328 }
5329 try {
5330 phone.carrierActionSetRadioEnabled(enabled);
5331 } catch (Exception e) {
5332 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005333 } finally {
5334 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005335 }
5336 }
5337
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005338 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005339 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5340 * network status based on which carrier apps could apply actions accordingly,
5341 * enable/disable default url handler for example.
5342 *
5343 * @param subId the subscription ID that this action applies to.
5344 * @param report control start/stop reporting the default network status.
5345 * {@hide}
5346 */
5347 @Override
5348 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5349 enforceModifyPermission();
5350 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005351
5352 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005353 if (phone == null) {
5354 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5355 return;
5356 }
5357 try {
5358 phone.carrierActionReportDefaultNetworkStatus(report);
5359 } catch (Exception e) {
5360 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005361 } finally {
5362 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005363 }
5364 }
5365
5366 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005367 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5368 * bug report is being generated.
5369 */
5370 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005371 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005372 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5373 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005374 writer.println("Permission Denial: can't dump Phone from pid="
5375 + Binder.getCallingPid()
5376 + ", uid=" + Binder.getCallingUid()
5377 + "without permission "
5378 + android.Manifest.permission.DUMP);
5379 return;
5380 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005381 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005382 }
Jack Yueb89b242016-06-22 13:27:47 -07005383
Brad Ebingerdac2f002018-04-03 15:17:52 -07005384 @Override
5385 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5386 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5387 throws RemoteException {
5388 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5389 }
5390
Jack Yueb89b242016-06-22 13:27:47 -07005391 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005392 * Get aggregated video call data usage since boot.
5393 *
5394 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5395 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005396 * {@hide}
5397 */
5398 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005399 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5401 null);
5402
Malcolm Chend965c8b2018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
5405 // NetworkStatsService keeps tracking the active network interface and identity. It
5406 // records the delta with the corresponding network identity.
5407 // We just return the total video call data usage snapshot since boot.
5408 Phone phone = getPhone(subId);
5409 if (phone != null) {
5410 return phone.getVtDataUsage(perUidStats);
5411 }
5412 return null;
5413 } finally {
5414 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005415 }
Jack Yueb89b242016-06-22 13:27:47 -07005416 }
Jack Yu75ab2952016-07-08 14:29:33 -07005417
5418 /**
5419 * Policy control of data connection. Usually used when data limit is passed.
5420 * @param enabled True if enabling the data, otherwise disabling.
5421 * @param subId Subscription index
5422 * {@hide}
5423 */
5424 @Override
5425 public void setPolicyDataEnabled(boolean enabled, int subId) {
5426 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005427
5428 final long identity = Binder.clearCallingIdentity();
5429 try {
5430 Phone phone = getPhone(subId);
5431 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005432 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005433 }
5434 } finally {
5435 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005436 }
5437 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005438
5439 /**
5440 * Get Client request stats
5441 * @return List of Client Request Stats
5442 * @hide
5443 */
5444 @Override
5445 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005447 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005448 return null;
5449 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005450 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005451
Malcolm Chend965c8b2018-02-28 15:00:40 -08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 if (phone != null) {
5455 return phone.getClientRequestStats();
5456 }
5457
5458 return null;
5459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005462 }
5463
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005464 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005465 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005466 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005467 }
Jack Yueb4124c2017-02-16 15:32:43 -08005468
5469 /**
Grace Chen70990072017-03-24 17:21:30 -07005470 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005471 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005472 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005473 * @param state State of SIM (power down, power up, pass through)
5474 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5475 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5476 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005477 *
5478 **/
5479 @Override
Grace Chen70990072017-03-24 17:21:30 -07005480 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005481 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005482 Phone phone = PhoneFactory.getPhone(slotIndex);
5483
vagdevie435a3e2018-08-15 16:01:53 -07005484 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5485
Malcolm Chend965c8b2018-02-28 15:00:40 -08005486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005489 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005490 }
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005493 }
5494 }
Shuo Qiandd210312017-04-12 22:11:33 +00005495
Tyler Gunn65d45c22017-06-05 11:22:26 -07005496 private boolean isUssdApiAllowed(int subId) {
5497 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005498 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005499 if (configManager == null) {
5500 return false;
5501 }
5502 PersistableBundle pb = configManager.getConfigForSubId(subId);
5503 if (pb == null) {
5504 return false;
5505 }
5506 return pb.getBoolean(
5507 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5508 }
5509
Shuo Qiandd210312017-04-12 22:11:33 +00005510 /**
5511 * Check if phone is in emergency callback mode
5512 * @return true if phone is in emergency callback mode
5513 * @param subId sub id
5514 */
goneil9c5f4872017-12-05 14:07:56 -08005515 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005516 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005517 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005518 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 if (phone != null) {
5523 return phone.isInEcm();
5524 } else {
5525 return false;
5526 }
5527 } finally {
5528 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005529 }
5530 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005531
5532 /**
5533 * Get the current signal strength information for the given subscription.
5534 * Because this information is not updated when the device is in a low power state
5535 * it should not be relied-upon to be current.
5536 * @param subId Subscription index
5537 * @return the most recent cached signal strength info from the modem
5538 */
5539 @Override
5540 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 Phone p = getPhone(subId);
5544 if (p == null) {
5545 return null;
5546 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005547
Malcolm Chend965c8b2018-02-28 15:00:40 -08005548 return p.getSignalStrength();
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005552 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005553
Pengquan Meng9140aec2018-08-22 14:49:57 -07005554 /**
chen xu907e5a22018-10-11 13:21:04 -07005555 * Get the current modem radio state for the given slot.
5556 * @param slotIndex slot index.
5557 * @param callingPackage the name of the package making the call.
5558 * @return the current radio power state from the modem
5559 */
5560 @Override
5561 public int getRadioPowerState(int slotIndex, String callingPackage) {
5562 Phone phone = PhoneFactory.getPhone(slotIndex);
5563 if (phone != null) {
5564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5565 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5566 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5567 }
5568
5569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 return phone.getRadioPowerState();
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
5575 }
5576 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5577 }
5578
5579 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005580 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5581 *
5582 * <p>Requires one of the following permissions:
5583 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5584 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5585 * privileges.
5586 *
5587 * @param subId subscription id
5588 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5589 * {@code false}.
5590 */
5591 @Override
5592 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005593 boolean isEnabled = false;
5594 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005595 try {
5596 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005597 null /* message */);
5598 Phone phone = getPhone(subId);
5599 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005600 } catch (Exception e) {
5601 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5602 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005603 } finally {
5604 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005605 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005606 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005607 }
5608
5609
5610 /**
5611 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5612 *
5613 * <p> Requires permission:
5614 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5615 * privileges.
5616 *
5617 * @param subId subscription id
5618 * @param isEnabled {@code true} means enable, {@code false} means disable.
5619 */
5620 @Override
5621 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005622 final long identity = Binder.clearCallingIdentity();
5623 try {
5624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5625 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005626
Pengquan Meng0c05b502018-09-06 09:59:22 -07005627 Phone phone = getPhone(subId);
5628 if (phone != null) {
5629 phone.setDataRoamingEnabled(isEnabled);
5630 }
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005633 }
5634 }
5635
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005636 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005637 public boolean isManualNetworkSelectionAllowed(int subId) {
5638 boolean isAllowed = true;
5639 final long identity = Binder.clearCallingIdentity();
5640 try {
5641 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5642 mApp, subId, "isManualNetworkSelectionAllowed");
5643 Phone phone = getPhone(subId);
5644 if (phone != null) {
5645 isAllowed = phone.isCspPlmnEnabled();
5646 }
5647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
5650 return isAllowed;
5651 }
5652
5653 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005654 public UiccCardInfo[] getUiccCardsInfo() {
5655 enforceReadPrivilegedPermission("getUiccCardsInfo");
5656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5660 return cards.toArray(new UiccCardInfo[cards.size()]);
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
5664 }
5665
5666 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005667 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005668 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005669
Malcolm Chend965c8b2018-02-28 15:00:40 -08005670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5673 if (slots == null) {
5674 Rlog.i(LOG_TAG, "slots is null.");
5675 return null;
5676 }
5677
5678 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5679 for (int i = 0; i < slots.length; i++) {
5680 UiccSlot slot = slots[i];
5681 if (slot == null) {
5682 continue;
5683 }
5684
5685 String cardId;
5686 UiccCard card = slot.getUiccCard();
5687 if (card != null) {
5688 cardId = card.getCardId();
5689 } else {
5690 cardId = slot.getIccId();
5691 }
5692
5693 int cardState = 0;
5694 switch (slot.getCardState()) {
5695 case CARDSTATE_ABSENT:
5696 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5697 break;
5698 case CARDSTATE_PRESENT:
5699 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5700 break;
5701 case CARDSTATE_ERROR:
5702 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5703 break;
5704 case CARDSTATE_RESTRICTED:
5705 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5706 break;
5707 default:
5708 break;
5709
5710 }
5711
5712 infos[i] = new UiccSlotInfo(
5713 slot.isActive(),
5714 slot.isEuicc(),
5715 cardId,
5716 cardState,
5717 slot.getPhoneId(),
5718 slot.isExtendedApduSupported());
5719 }
5720 return infos;
5721 } finally {
5722 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005723 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005724 }
5725
5726 @Override
5727 public boolean switchSlots(int[] physicalSlots) {
5728 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005729
5730 final long identity = Binder.clearCallingIdentity();
5731 try {
5732 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005736 }
Jack Yu4c988042018-02-27 15:30:01 -08005737
5738 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005739 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5740 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5741 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5742 return TelephonyManager.INVALID_CARD_ID;
5743 }
5744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
5747 return UiccController.getInstance().getCardIdForDefaultEuicc();
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
5751 }
5752
5753 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005754 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5755 enforceModifyPermission();
5756 final Phone phone = getPhone(subId);
5757 if (phone == null) {
5758 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5759 return;
5760 }
5761
Malcolm Chend965c8b2018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
5764 phone.setRadioIndicationUpdateMode(filters, mode);
5765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
Jack Yu4c988042018-02-27 15:30:01 -08005768 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005769
5770 /**
goneil47ffb6e2018-04-06 15:40:58 -07005771 * A test API to reload the UICC profile.
5772 *
5773 * <p>Requires that the calling app has permission
5774 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5775 * @hide
5776 */
5777 @Override
5778 public void refreshUiccProfile(int subId) {
5779 enforceModifyPermission();
5780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 Phone phone = getPhone(subId);
5784 if (phone == null) {
5785 return;
5786 }
5787 UiccCard uiccCard = phone.getUiccCard();
5788 if (uiccCard == null) {
5789 return;
5790 }
5791 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5792 if (uiccProfile == null) {
5793 return;
5794 }
5795 uiccProfile.refresh();
5796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
5799 }
5800
5801 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005802 * Returns false if the mobile data is disabled by default, otherwise return true.
5803 */
5804 private boolean getDefaultDataEnabled() {
5805 return "true".equalsIgnoreCase(
5806 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5807 }
5808
5809 /**
5810 * Returns true if the data roaming is enabled by default, i.e the system property
5811 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5812 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5813 */
5814 private boolean getDefaultDataRoamingEnabled(int subId) {
5815 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005816 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005817 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5818 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5819 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5820 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5821 return isDataRoamingEnabled;
5822 }
5823
5824 /**
5825 * Returns the default network type for the given {@code subId}, if the default network type is
5826 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5827 */
5828 private int getDefaultNetworkType(int subId) {
5829 return Integer.parseInt(
5830 TelephonyManager.getTelephonyProperty(
5831 mSubscriptionController.getPhoneId(subId),
5832 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5833 String.valueOf(Phone.PREFERRED_NT_MODE)));
5834 }
fionaxua13278b2018-03-21 00:08:13 -07005835
5836 @Override
5837 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5838 gid1, String gid2, String plmn, String spn) {
5839 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 final Phone phone = getPhone(subId);
5844 if (phone == null) {
5845 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5846 return;
5847 }
5848 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5849 } finally {
5850 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005851 }
fionaxua13278b2018-03-21 00:08:13 -07005852 }
5853
5854 @Override
5855 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005856 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 final Phone phone = getPhone(subId);
5861 if (phone == null) {
5862 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5863 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5864 }
5865 return phone.getCarrierIdListVersion();
5866 } finally {
5867 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005868 }
fionaxua13278b2018-03-21 00:08:13 -07005869 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005870
5871 @Override
5872 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5874 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5875 return -1;
5876 }
5877
5878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
5884 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005885
5886 @Override
5887 public int getCdmaRoamingMode(int subId) {
5888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5889 mApp, subId, "getCdmaRoamingMode");
5890
5891 final long identity = Binder.clearCallingIdentity();
5892 try {
5893 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
5897 }
5898
5899 @Override
5900 public boolean setCdmaRoamingMode(int subId, int mode) {
5901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5902 mApp, subId, "setCdmaRoamingMode");
5903
5904 final long identity = Binder.clearCallingIdentity();
5905 try {
5906 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
5910 }
5911
5912 @Override
5913 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5915 mApp, subId, "setCdmaSubscriptionMode");
5916
5917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5920 } finally {
5921 Binder.restoreCallingIdentity(identity);
5922 }
5923 }
chen xu7ee67862018-10-30 22:27:10 -07005924
sqian2fff4a32018-11-05 14:18:37 -08005925 private void ensureUserRunning(int userId) {
5926 if (!mUserManager.isUserRunning(userId)) {
5927 throw new IllegalStateException("User " + userId + " does not exist or not running");
5928 }
5929 }
5930
5931 /**
5932 * Returns a list of SMS apps on a given user.
5933 *
5934 * Only the shell user (UID 2000 or 0) can call it.
5935 * Target user must be running.
5936 */
5937 @Override
5938 public String[] getSmsApps(int userId) {
5939 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5940 ensureUserRunning(userId);
5941
5942 final Collection<SmsApplicationData> apps =
5943 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5944
5945 String[] ret = new String[apps.size()];
5946 int i = 0;
5947 for (SmsApplicationData app : apps) {
5948 ret[i++] = app.mPackageName;
5949 }
5950 return ret;
5951 }
5952
5953 /**
5954 * Returns the default SMS app package name on a given user.
5955 *
5956 * Only the shell user (UID 2000 or 0) can call it.
5957 * Target user must be running.
5958 */
5959 @Override
5960 public String getDefaultSmsApp(int userId) {
5961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5962 ensureUserRunning(userId);
5963
5964 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5965 /* updateIfNeeded= */ true, userId);
5966 return cn == null ? null : cn.getPackageName();
5967 }
5968
5969 /**
5970 * Set a package as the default SMS app on a given user.
5971 *
5972 * Only the shell user (UID 2000 or 0) can call it.
5973 * Target user must be running.
5974 */
5975 @Override
5976 public void setDefaultSmsApp(int userId, String packageName) {
5977 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5978 ensureUserRunning(userId);
5979
5980 boolean found = false;
5981 for (String pkg : getSmsApps(userId)) {
5982 if (TextUtils.equals(packageName, pkg)) {
5983 found = true;
5984 break;
5985 }
5986 }
5987 if (!found) {
5988 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5989 }
5990
5991 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5992 }
5993
chen xu7ee67862018-10-30 22:27:10 -07005994 @Override
sqian04b86072018-11-07 14:02:21 -08005995 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5996 String callingPackage) {
5997 // TODO connect with internal content
5998 return null;
5999 }
6000
6001 @Override
6002 public boolean isCurrentEmergencyNumber(String number) {
6003 // TODO connect with internal content
6004 return false;
6005 }
6006
6007 @Override
chen xu7ee67862018-10-30 22:27:10 -07006008 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6009 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6010 Phone phone = getPhone(subId);
6011 if (phone == null) {
6012 return null;
6013 }
6014 final long identity = Binder.clearCallingIdentity();
6015 try {
6016 UiccProfile profile = UiccController.getInstance()
6017 .getUiccProfileForPhone(phone.getPhoneId());
6018 if (profile != null) {
6019 return profile.getCertsFromCarrierPrivilegeAccessRules();
6020 }
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
6024 return null;
6025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006026}