blob: d546bf6e59196ab0331be233d512608d3bf70f88 [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;
Tyler Gunn327a9722019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070051import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070052import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070053import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080058import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070059import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080060import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080061import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070062import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070063import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080064import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070066import android.telephony.CellInfoGsm;
67import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070068import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070070import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070071import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080072import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070073import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080074import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070075import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080076import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080077import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070078import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080079import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070080import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080082import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
Jack Yu40306fc2019-05-13 16:54:09 -070094import android.telephony.data.ApnSetting.ApnType;
calvinpaneed9ae82018-11-01 19:43:06 +080095import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070097import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080098import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070099import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700101import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800102import android.telephony.ims.aidl.IImsMmTelFeature;
103import android.telephony.ims.aidl.IImsRcsFeature;
104import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800106import android.telephony.ims.feature.MmTelFeature;
107import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800108import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800112import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800113import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800114
Andrew Lee312e8172014-10-23 17:01:36 -0700115import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800116import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700118import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700119import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800120import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700121import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800124import com.android.internal.telephony.HalVersion;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700125import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800126import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800128import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700129import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100130import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700131import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700132import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700134import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800135import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700136import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700137import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700138import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700139import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700140import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700141import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800142import com.android.internal.telephony.SmsApplication;
143import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajan716e76c2019-05-13 13:48:32 -0700144import com.android.internal.telephony.SmsController;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700145import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800146import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800147import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chen460810d2019-04-10 18:25:07 -0700148import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqian9d4df8b2019-01-15 18:32:07 -0800149import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700150import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800151import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800152import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.uicc.IccIoResult;
154import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800155import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700156import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800157import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800159import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000160import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700161import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800162import com.android.internal.util.HexDump;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700163import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700164import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800165import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700166import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700167import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800168
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700169import java.io.FileDescriptor;
170import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800173import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800174import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800175import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800176import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100177import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Map;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700179import java.util.NoSuchElementException;
sqian9d4df8b2019-01-15 18:32:07 -0800180import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182/**
183 * Implementation of the ITelephony interface.
184 */
Santos Cordon117fee72014-05-16 17:56:12 -0700185public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private static final String LOG_TAG = "PhoneInterfaceManager";
187 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
188 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191 // Message codes used with mMainThreadHandler
192 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700193 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
194 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195 private static final int CMD_OPEN_CHANNEL = 9;
196 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
197 private static final int CMD_CLOSE_CHANNEL = 11;
198 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800199 private static final int CMD_NV_READ_ITEM = 13;
200 private static final int EVENT_NV_READ_ITEM_DONE = 14;
201 private static final int CMD_NV_WRITE_ITEM = 15;
202 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
203 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
204 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700205 private static final int CMD_RESET_MODEM_CONFIG = 19;
206 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800207 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
208 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
209 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
210 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800211 private static final int CMD_SEND_ENVELOPE = 25;
212 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000213 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
214 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700215 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
216 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
217 private static final int CMD_EXCHANGE_SIM_IO = 31;
218 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800219 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
220 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700221 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
222 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700223 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
224 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700225 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
226 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
227 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700229 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
230 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
231 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
232 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700233 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800234 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
235 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000236 private static final int CMD_SWITCH_SLOTS = 50;
237 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700238 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
239 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
240 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
241 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
242 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
243 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
244 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
245 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700246 private static final int CMD_GET_ALL_CELL_INFO = 60;
247 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
248 private static final int CMD_GET_CELL_LOCATION = 62;
249 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700250 private static final int CMD_MODEM_REBOOT = 64;
251 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700252 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
253 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800254 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
255 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700256 private static final int CMD_GET_MODEM_STATUS = 70;
257 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800259 // Parameters of select command.
260 private static final int SELECT_COMMAND = 0xA4;
261 private static final int SELECT_P1 = 0x04;
262 private static final int SELECT_P2 = 0;
263 private static final int SELECT_P3 = 0x10;
264
Pengquan Meng85728fb2018-03-12 16:31:21 -0700265 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
266 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
267 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
268
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 /** The singleton instance. */
270 private static PhoneInterfaceManager sInstance;
271
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700274 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private AppOpsManager mAppOps;
276 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800277 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700279 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280
Derek Tan97ebb422014-09-05 16:55:38 -0700281 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
282 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800284 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700285
Micheled3107c52018-12-21 15:00:11 -0800286 // String to store multi SIM allowed
287 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
288
Derek Tan740e1672017-06-27 14:56:27 -0700289 // The AID of ISD-R.
290 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
291
yinxub1bed742017-04-17 11:45:04 -0700292 private NetworkScanRequestTracker mNetworkScanRequestTracker;
293
David Kelly5e06a7f2018-03-12 14:10:59 +0000294 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
295 private static final int MANUFACTURER_CODE_LENGTH = 8;
296
Derek Tan89e89d42014-07-08 17:00:10 -0700297 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700298 * A request object to use for transmitting data to an ICC.
299 */
300 private static final class IccAPDUArgument {
301 public int channel, cla, command, p1, p2, p3;
302 public String data;
303
304 public IccAPDUArgument(int channel, int cla, int command,
305 int p1, int p2, int p3, String data) {
306 this.channel = channel;
307 this.cla = cla;
308 this.command = command;
309 this.p1 = p1;
310 this.p2 = p2;
311 this.p3 = p3;
312 this.data = data;
313 }
314 }
315
316 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700317 * A request object to use for transmitting data to an ICC.
318 */
319 private static final class ManualNetworkSelectionArgument {
320 public OperatorInfo operatorInfo;
321 public boolean persistSelection;
322
323 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
324 this.operatorInfo = operatorInfo;
325 this.persistSelection = persistSelection;
326 }
327 }
328
329 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
331 * request after sending. The main thread will notify the request when it is complete.
332 */
333 private static final class MainThreadRequest {
334 /** The argument to use for the request */
335 public Object argument;
336 /** The result of the request that is run on the main thread */
337 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800338 // The subscriber id that this request applies to. Defaults to
339 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
340 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 // In cases where subId is unavailable, the caller needs to specify the phone.
343 public Phone phone;
344
vagdevie435a3e2018-08-15 16:01:53 -0700345 public WorkSource workSource;
346
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 public MainThreadRequest(Object argument) {
348 this.argument = argument;
349 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800350
Nathan Harold92bed182018-10-12 18:16:49 -0700351 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
352 this.argument = argument;
353 if (phone != null) {
354 this.phone = phone;
355 }
356 this.workSource = workSource;
357 }
358
vagdevie435a3e2018-08-15 16:01:53 -0700359 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800360 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800361 if (subId != null) {
362 this.subId = subId;
363 }
vagdevie435a3e2018-08-15 16:01:53 -0700364 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 }
367
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800368 private static final class IncomingThirdPartyCallArgs {
369 public final ComponentName component;
370 public final String callId;
371 public final String callerDisplayName;
372
373 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
374 String callerDisplayName) {
375 this.component = component;
376 this.callId = callId;
377 this.callerDisplayName = callerDisplayName;
378 }
379 }
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 /**
382 * A handler that processes messages on the main thread in the phone process. Since many
383 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
384 * inbound binder threads to the main thread in the phone process. The Binder thread
385 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
386 * on, which will be notified when the operation completes and will contain the result of the
387 * request.
388 *
389 * <p>If a MainThreadRequest object is provided in the msg.obj field,
390 * note that request.result must be set to something non-null for the calling thread to
391 * unblock.
392 */
393 private final class MainThreadHandler extends Handler {
394 @Override
395 public void handleMessage(Message msg) {
396 MainThreadRequest request;
397 Message onCompleted;
398 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800399 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800401 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
403 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700404 case CMD_HANDLE_USSD_REQUEST: {
405 request = (MainThreadRequest) msg.obj;
406 final Phone phone = getPhoneFromRequest(request);
407 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
408 String ussdRequest = ussdObject.first;
409 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Meng0c05b502018-09-06 09:59:22 -0700411 if (!isUssdApiAllowed(request.subId)) {
412 // Carrier does not support use of this API, return failure.
413 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
414 UssdResponse response = new UssdResponse(ussdRequest, null);
415 Bundle returnData = new Bundle();
416 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
417 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700418
Pengquan Meng0c05b502018-09-06 09:59:22 -0700419 request.result = true;
420 notifyRequester(request);
421 return;
422 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Meng0c05b502018-09-06 09:59:22 -0700424 try {
425 request.result = phone != null
426 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
427 } catch (CallStateException cse) {
428 request.result = false;
429 }
430 // Wake up the requesting thread
431 notifyRequester(request);
432 break;
pkanwar32d516d2016-10-14 19:37:38 -0700433 }
434
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 final Phone phone = getPhoneFromRequest(request);
438 request.result = phone != null ?
439 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
440 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700442 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduLogicalChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
456 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 iccArgument.channel, iccArgument.cla, iccArgument.command,
459 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 break;
463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800473 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800475 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 } else {
477 loge("iccTransmitApduLogicalChannel: Unknown exception");
478 }
479 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 break;
482
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccTransmitApduBasicChannel: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
493 request);
494 uiccCard.iccTransmitApduBasicChannel(
495 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
496 iccArgument.p3, iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("iccTransmitApduBasicChannel: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("iccTransmitApduBasicChannel: CommandException: " +
511 ar.exception);
512 } else {
513 loge("iccTransmitApduBasicChannel: Unknown exception");
514 }
515 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
519 case CMD_EXCHANGE_SIM_IO:
520 request = (MainThreadRequest) msg.obj;
521 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 if (uiccCard == null) {
524 loge("iccExchangeSimIO: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
529 request);
530 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
531 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
532 iccArgument.data, onCompleted);
533 }
534 break;
535
536 case EVENT_EXCHANGE_SIM_IO_DONE:
537 ar = (AsyncResult) msg.obj;
538 request = (MainThreadRequest) ar.userObj;
539 if (ar.exception == null && ar.result != null) {
540 request.result = ar.result;
541 } else {
542 request.result = new IccIoResult(0x6f, 0, (byte[])null);
543 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 break;
546
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 case CMD_SEND_ENVELOPE:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("sendEnvelopeWithStatus: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 } else {
555 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
556 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 break;
559
560 case EVENT_SEND_ENVELOPE_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700563 if (ar.exception == null && ar.result != null) {
564 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
567 if (ar.result == null) {
568 loge("sendEnvelopeWithStatus: Empty response");
569 } else if (ar.exception instanceof CommandException) {
570 loge("sendEnvelopeWithStatus: CommandException: " +
571 ar.exception);
572 } else {
573 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
574 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800575 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700576 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 break;
578
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 case CMD_OPEN_CHANNEL:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800582 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 if (uiccCard == null) {
584 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800585 request.result = new IccOpenLogicalChannelResponse(-1,
586 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800590 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
591 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 break;
594
595 case EVENT_OPEN_CHANNEL_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 int[] result = (int[]) ar.result;
601 int channelId = result[0];
602 byte[] selectResponse = null;
603 if (result.length > 1) {
604 selectResponse = new byte[result.length - 1];
605 for (int i = 1; i < result.length; ++i) {
606 selectResponse[i - 1] = (byte) result[i];
607 }
608 }
609 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.result == null) {
613 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 if (ar.exception != null) {
616 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
617 }
618
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700620 if (ar.exception instanceof CommandException) {
621 CommandException.Error error =
622 ((CommandException) (ar.exception)).getCommandError();
623 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700625 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 }
628 }
629 openChannelResp = new IccOpenLogicalChannelResponse(
630 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700632 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case CMD_CLOSE_CHANNEL:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900641 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
644 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
645 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800650 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
651 break;
652
653 case CMD_NV_READ_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800656 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
657 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
660 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800666 request.result = "";
667 if (ar.result == null) {
668 loge("nvReadItem: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("nvReadItem: CommandException: " +
671 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
675 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Jake Hambye994d462014-02-03 13:10:13 -0800679 case CMD_NV_WRITE_ITEM:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
682 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800683 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700684 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
687 case EVENT_NV_WRITE_ITEM_DONE:
688 handleNullReturnEvent(msg, "nvWriteItem");
689 break;
690
691 case CMD_NV_WRITE_CDMA_PRL:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800694 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
697 case EVENT_NV_WRITE_CDMA_PRL_DONE:
698 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
699 break;
700
chen xu1cc0abe2018-10-26 17:39:23 -0700701 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800702 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700703 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800704 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
chen xu1cc0abe2018-10-26 17:39:23 -0700707 case EVENT_RESET_MODEM_CONFIG_DONE:
708 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 case CMD_GET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result; // Integer
722 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800723 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 if (ar.result == null) {
725 loge("getPreferredNetworkType: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("getPreferredNetworkType: CommandException: " +
728 ar.exception);
729 } else {
730 loge("getPreferredNetworkType: Unknown exception");
731 }
732 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700733 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
748 request = (MainThreadRequest)msg.obj;
749 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800750 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 break;
752
753 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
754 ar = (AsyncResult)msg.obj;
755 request = (MainThreadRequest)ar.userObj;
756 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700757 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800760 case CMD_SET_VOICEMAIL_NUMBER:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
763 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800764 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
765 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 break;
767
768 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
769 handleNullReturnEvent(msg, "setVoicemailNumber");
770 break;
771
Stuart Scott54788802015-03-30 13:18:01 -0700772 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
775 request);
776 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
777 break;
778
779 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
780 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
781 break;
782
Shishir Agrawal302c8692015-06-19 13:49:39 -0700783 case CMD_PERFORM_NETWORK_SCAN:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
786 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
787 break;
788
789 case EVENT_PERFORM_NETWORK_SCAN_DONE:
790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
792 CellNetworkScanResult cellScanResult;
793 if (ar.exception == null && ar.result != null) {
794 cellScanResult = new CellNetworkScanResult(
795 CellNetworkScanResult.STATUS_SUCCESS,
796 (List<OperatorInfo>) ar.result);
797 } else {
798 if (ar.result == null) {
799 loge("getCellNetworkScanResults: Empty response");
800 }
801 if (ar.exception != null) {
802 loge("getCellNetworkScanResults: Exception: " + ar.exception);
803 }
804 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
805 if (ar.exception instanceof CommandException) {
806 CommandException.Error error =
807 ((CommandException) (ar.exception)).getCommandError();
808 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
809 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
810 } else if (error == CommandException.Error.GENERIC_FAILURE) {
811 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
812 }
813 }
814 cellScanResult = new CellNetworkScanResult(errorCode, null);
815 }
816 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700817 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 break;
819
820 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
821 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 ManualNetworkSelectionArgument selArg =
823 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
825 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700826 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
827 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 break;
829
830 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null) {
834 request.result = true;
835 } else {
836 request.result = false;
837 loge("setNetworkSelectionModeManual " + ar.exception);
838 }
839 notifyRequester(request);
840 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 case CMD_GET_MODEM_ACTIVITY_INFO:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisc56281c2019-04-03 14:18:34 -0700846 if (defaultPhone != null) {
847 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 break;
850
851 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("queryModemActivityInfo: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("queryModemActivityInfo: CommandException: " +
861 ar.exception);
862 } else {
863 loge("queryModemActivityInfo: Unknown exception");
864 }
865 }
Amit Mahajand4766222016-01-28 15:28:28 -0800866 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
867 if (request.result == null) {
868 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
869 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700870 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700871 break;
872
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 case CMD_SET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800875 CarrierRestrictionRules argument =
876 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800878 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 break;
880
881 case EVENT_SET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800887 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
888 if (ar.exception instanceof CommandException) {
889 loge("setAllowedCarriers: CommandException: " + ar.exception);
890 CommandException.Error error =
891 ((CommandException) (ar.exception)).getCommandError();
892 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
893 request.result =
894 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
895 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 } else {
897 loge("setAllowedCarriers: Unknown exception");
898 }
899 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700900 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 break;
902
903 case CMD_GET_ALLOWED_CARRIERS:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800906 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
909 case EVENT_GET_ALLOWED_CARRIERS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800915 request.result = new IllegalStateException(
916 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 if (ar.result == null) {
918 loge("getAllowedCarriers: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("getAllowedCarriers: CommandException: " +
921 ar.exception);
922 } else {
923 loge("getAllowedCarriers: Unknown exception");
924 }
925 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700926 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700927 break;
928
Nathan Haroldb3014052017-01-25 15:57:32 -0800929 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 request.result = new IllegalArgumentException(
936 "Failed to retrieve Forbidden Plmns");
937 if (ar.result == null) {
938 loge("getForbiddenPlmns: Empty response");
939 } else {
940 loge("getForbiddenPlmns: Unknown exception");
941 }
942 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945
946 case CMD_GET_FORBIDDEN_PLMNS:
947 request = (MainThreadRequest) msg.obj;
948 uiccCard = getUiccCardFromRequest(request);
949 if (uiccCard == null) {
950 loge("getForbiddenPlmns() UiccCard is null");
951 request.result = new IllegalArgumentException(
952 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700953 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800954 break;
955 }
956 Integer appType = (Integer) request.argument;
957 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
958 if (uiccApp == null) {
959 loge("getForbiddenPlmns() no app with specified type -- "
960 + appType);
961 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700962 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800963 break;
964 } else {
965 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
966 + " specified type -- " + appType);
967 }
968 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
969 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
970 onCompleted);
971 break;
972
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000973 case CMD_SWITCH_SLOTS:
974 request = (MainThreadRequest) msg.obj;
975 int[] physicalSlots = (int[]) request.argument;
976 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
977 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
978 break;
979
980 case EVENT_SWITCH_SLOTS_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700984 notifyRequester(request);
985 break;
986 case CMD_GET_NETWORK_SELECTION_MODE:
987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
989 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
990 break;
991
992 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
997 } else {
998 int mode = ((int[]) ar.result)[0];
999 if (mode == 0) {
1000 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1001 } else {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001004 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001005 notifyRequester(request);
1006 break;
1007 case CMD_GET_CDMA_ROAMING_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1010 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1011 break;
1012 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception != null) {
1016 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1017 } else {
1018 request.result = ((int[]) ar.result)[0];
1019 }
1020 notifyRequester(request);
1021 break;
1022 case CMD_SET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1025 int mode = (int) request.argument;
1026 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1027 break;
1028 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 request.result = ar.exception == null;
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1037 int subscriptionMode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001045 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 case CMD_GET_ALL_CELL_INFO:
1047 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001049 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 case EVENT_GET_ALL_CELL_INFO_DONE:
1052 ar = (AsyncResult) msg.obj;
1053 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001054 // If a timeout occurs, the response will be null
1055 request.result = (ar.exception == null && ar.result != null)
1056 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 synchronized (request) {
1058 request.notifyAll();
1059 }
1060 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 case CMD_REQUEST_CELL_INFO_UPDATE:
1062 request = (MainThreadRequest) msg.obj;
1063 request.phone.requestCellInfoUpdate(request.workSource,
1064 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1065 break;
1066 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1070 try {
1071 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1074 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001077 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 } else {
1079 // use the result as returned
1080 cb.onCellInfo((List<CellInfo>) ar.result);
1081 }
1082 } catch (RemoteException re) {
1083 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1084 }
1085 break;
1086 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001087 request = (MainThreadRequest) msg.obj;
1088 WorkSource ws = (WorkSource) request.argument;
1089 Phone phone = getPhoneFromRequest(request);
1090 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1091 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null) {
1096 request.result = ar.result;
1097 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001098 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001099 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1100 ? new CdmaCellLocation() : new GsmCellLocation();
1101 }
1102
1103 synchronized (request) {
1104 request.notifyAll();
1105 }
1106 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001107 case CMD_MODEM_REBOOT:
1108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001110 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001111 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001112 case EVENT_CMD_MODEM_REBOOT_DONE:
1113 handleNullReturnEvent(msg, "rebootModem");
1114 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001115 case CMD_REQUEST_ENABLE_MODEM:
1116 request = (MainThreadRequest) msg.obj;
1117 boolean enable = (boolean) request.argument;
1118 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001119 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001120 PhoneConfigurationManager.getInstance()
1121 .enablePhone(request.phone, enable, onCompleted);
1122 break;
1123 case EVENT_ENABLE_MODEM_DONE:
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 request.result = (ar.exception == null);
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001127 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001128 //update the cache as modem status has changed
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001129 if ((boolean) request.result) {
1130 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1131 updateModemStateMetrics();
1132 } else {
1133 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1134 + ar.exception);
1135 }
1136 notifyRequester(request);
1137 break;
1138 case CMD_GET_MODEM_STATUS:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1141 PhoneConfigurationManager.getInstance()
1142 .getPhoneStatusFromModem(request.phone, onCompleted);
1143 break;
1144 case EVENT_GET_MODEM_STATUS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 int id = request.phone.getPhoneId();
1148 if (ar.exception == null && ar.result != null) {
1149 request.result = ar.result;
1150 //update the cache as modem status has changed
1151 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1152 (boolean) request.result);
1153 } else {
1154 // Return true if modem status cannot be retrieved. For most cases,
1155 // modem status is on. And for older version modems, GET_MODEM_STATUS
1156 // and disable modem are not supported. Modem is always on.
1157 // TODO: this should be fixed in R to support a third
1158 // status UNKNOWN b/131631629
1159 request.result = true;
1160 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1161 + ar.exception);
1162 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08001163 notifyRequester(request);
1164 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 default:
1166 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1167 break;
1168 }
1169 }
Jake Hambye994d462014-02-03 13:10:13 -08001170
Pengquan Meng0c05b502018-09-06 09:59:22 -07001171 private void notifyRequester(MainThreadRequest request) {
1172 synchronized (request) {
1173 request.notifyAll();
1174 }
1175 }
1176
Jake Hambye994d462014-02-03 13:10:13 -08001177 private void handleNullReturnEvent(Message msg, String command) {
1178 AsyncResult ar = (AsyncResult) msg.obj;
1179 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1180 if (ar.exception == null) {
1181 request.result = true;
1182 } else {
1183 request.result = false;
1184 if (ar.exception instanceof CommandException) {
1185 loge(command + ": CommandException: " + ar.exception);
1186 } else {
1187 loge(command + ": Unknown exception");
1188 }
1189 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001190 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 /**
1195 * Posts the specified command to be executed on the main thread,
1196 * waits for the request to complete, and returns the result.
1197 * @see #sendRequestAsync
1198 */
1199 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001200 return sendRequest(
1201 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001202 }
1203
1204 /**
1205 * Posts the specified command to be executed on the main thread,
1206 * waits for the request to complete, and returns the result.
1207 * @see #sendRequestAsync
1208 */
1209 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1210 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001211 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001212 }
1213
1214 /**
1215 * Posts the specified command to be executed on the main thread,
1216 * waits for the request to complete, and returns the result.
1217 * @see #sendRequestAsync
1218 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001219 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001220 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001221 }
1222
1223 /**
1224 * Posts the specified command to be executed on the main thread,
1225 * waits for the request to complete, and returns the result.
1226 * @see #sendRequestAsync
1227 */
Nathan Harold92bed182018-10-12 18:16:49 -07001228 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1229 return sendRequest(command, argument, subId, null, workSource);
1230 }
1231
1232 /**
1233 * Posts the specified command to be executed on the main thread,
1234 * waits for the request to complete, and returns the result.
1235 * @see #sendRequestAsync
1236 */
1237 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1238 return sendRequest(
1239 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1240 }
1241
1242 /**
1243 * Posts the specified command to be executed on the main thread,
1244 * waits for the request to complete, and returns the result.
1245 * @see #sendRequestAsync
1246 */
1247 private Object sendRequest(
1248 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1250 throw new RuntimeException("This method will deadlock if called from the main thread.");
1251 }
1252
Nathan Harold92bed182018-10-12 18:16:49 -07001253 MainThreadRequest request = null;
1254 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1255 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1256 } else if (phone != null) {
1257 request = new MainThreadRequest(argument, phone, workSource);
1258 } else {
1259 request = new MainThreadRequest(argument, subId, workSource);
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 Message msg = mMainThreadHandler.obtainMessage(command, request);
1263 msg.sendToTarget();
1264
1265 // Wait for the request to complete
1266 synchronized (request) {
1267 while (request.result == null) {
1268 try {
1269 request.wait();
1270 } catch (InterruptedException e) {
1271 // Do nothing, go back and wait until the request is complete
1272 }
1273 }
1274 }
1275 return request.result;
1276 }
1277
1278 /**
1279 * Asynchronous ("fire and forget") version of sendRequest():
1280 * Posts the specified command to be executed on the main thread, and
1281 * returns immediately.
1282 * @see #sendRequest
1283 */
1284 private void sendRequestAsync(int command) {
1285 mMainThreadHandler.sendEmptyMessage(command);
1286 }
1287
1288 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001289 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001291 */
1292 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 sendRequestAsync(command, argument, null, null);
1294 }
1295
1296 /**
1297 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1298 * @see {@link #sendRequest(int,Object)}
1299 */
1300 private void sendRequestAsync(
1301 int command, Object argument, Phone phone, WorkSource workSource) {
1302 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001303 Message msg = mMainThreadHandler.obtainMessage(command, request);
1304 msg.sendToTarget();
1305 }
1306
1307 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 * Initialize the singleton PhoneInterfaceManager instance.
1309 * This is only done once, at startup, from PhoneApp.onCreate().
1310 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001311 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 synchronized (PhoneInterfaceManager.class) {
1313 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001314 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 } else {
1316 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1317 }
1318 return sInstance;
1319 }
1320 }
1321
1322 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001323 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001326 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1328 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001329 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001330 mTelephonySharedPreferences =
1331 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001332 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001333 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001334
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 publish();
1336 }
1337
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001338 private Phone getDefaultPhone() {
1339 Phone thePhone = getPhone(getDefaultSubscription());
1340 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1341 }
1342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 private void publish() {
1344 if (DBG) log("publish: " + this);
1345
1346 ServiceManager.addService("phone", this);
1347 }
1348
Stuart Scott584921c2015-01-15 17:10:34 -08001349 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001350 if (request.phone != null) {
1351 return request.phone;
1352 } else {
1353 return getPhoneFromSubId(request.subId);
1354 }
1355 }
1356
1357 private Phone getPhoneFromSubId(int subId) {
1358 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1359 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001360 }
1361
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001362 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1363 Phone phone = getPhoneFromRequest(request);
1364 return phone == null ? null :
1365 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1366 }
1367
Wink Saville36469e72014-06-11 15:17:00 -07001368 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001369 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001370 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372
1373 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 if (DBG) log("dial: " + number);
1379 // No permission check needed here: This is just a wrapper around the
1380 // ACTION_DIAL intent, which is available to any app since it puts up
1381 // the UI before it does anything.
1382
Malcolm Chend965c8b2018-02-28 15:00:40 -08001383 final long identity = Binder.clearCallingIdentity();
1384 try {
1385 String url = createTelUrl(number);
1386 if (url == null) {
1387 return;
1388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389
Malcolm Chend965c8b2018-02-28 15:00:40 -08001390 // PENDING: should we just silently fail if phone is offhook or ringing?
1391 PhoneConstants.State state = mCM.getState(subId);
1392 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1393 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1394 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1395 mApp.startActivity(intent);
1396 }
1397 } finally {
1398 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400 }
1401
1402 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001404 }
1405
Wink Savilleb564aae2014-10-23 10:18:09 -07001406 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 if (DBG) log("call: " + number);
1408
1409 // This is just a wrapper around the ACTION_CALL intent, but we still
1410 // need to do a permission check since we're calling startActivity()
1411 // from the context of the phone app.
1412 enforceCallPermission();
1413
1414 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1415 != AppOpsManager.MODE_ALLOWED) {
1416 return;
1417 }
1418
Malcolm Chend965c8b2018-02-28 15:00:40 -08001419 final long identity = Binder.clearCallingIdentity();
1420 try {
1421 String url = createTelUrl(number);
1422 if (url == null) {
1423 return;
1424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
Malcolm Chend965c8b2018-02-28 15:00:40 -08001426 boolean isValid = false;
1427 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1428 if (slist != null) {
1429 for (SubscriptionInfo subInfoRecord : slist) {
1430 if (subInfoRecord.getSubscriptionId() == subId) {
1431 isValid = true;
1432 break;
1433 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001434 }
Wink Saville08874612014-08-31 19:19:58 -07001435 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001436 if (!isValid) {
1437 return;
1438 }
Wink Saville08874612014-08-31 19:19:58 -07001439
Malcolm Chend965c8b2018-02-28 15:00:40 -08001440 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1441 intent.putExtra(SUBSCRIPTION_KEY, subId);
1442 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1443 mApp.startActivity(intent);
1444 } finally {
1445 Binder.restoreCallingIdentity(identity);
1446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 }
1448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001455 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1456 }
1457
1458 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001460 }
1461
Wink Savilleb564aae2014-10-23 10:18:09 -07001462 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001463 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001464 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1465 }
1466
1467 /** {@hide} */
1468 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001470 }
1471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001474
1475 final long identity = Binder.clearCallingIdentity();
1476 try {
1477 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1478 checkSimPin.start();
1479 return checkSimPin.unlockSim(null, pin);
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
Wink Saville9de0f752013-10-22 19:04:03 -07001485 /** {@hide} */
1486 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001492
1493 final long identity = Binder.clearCallingIdentity();
1494 try {
1495 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1496 checkSimPuk.start();
1497 return checkSimPuk.unlockSim(puk, pin);
1498 } finally {
1499 Binder.restoreCallingIdentity(identity);
1500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502
1503 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001504 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 * a synchronous one.
1506 */
1507 private static class UnlockSim extends Thread {
1508
1509 private final IccCard mSimCard;
1510
1511 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001512 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1513 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514
1515 // For replies from SimCard interface
1516 private Handler mHandler;
1517
1518 // For async handler to identify request type
1519 private static final int SUPPLY_PIN_COMPLETE = 100;
1520
1521 public UnlockSim(IccCard simCard) {
1522 mSimCard = simCard;
1523 }
1524
1525 @Override
1526 public void run() {
1527 Looper.prepare();
1528 synchronized (UnlockSim.this) {
1529 mHandler = new Handler() {
1530 @Override
1531 public void handleMessage(Message msg) {
1532 AsyncResult ar = (AsyncResult) msg.obj;
1533 switch (msg.what) {
1534 case SUPPLY_PIN_COMPLETE:
1535 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1536 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001537 mRetryCount = msg.arg1;
1538 if (ar.exception != null) {
1539 if (ar.exception instanceof CommandException &&
1540 ((CommandException)(ar.exception)).getCommandError()
1541 == CommandException.Error.PASSWORD_INCORRECT) {
1542 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1543 } else {
1544 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1545 }
1546 } else {
1547 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 mDone = true;
1550 UnlockSim.this.notifyAll();
1551 }
1552 break;
1553 }
1554 }
1555 };
1556 UnlockSim.this.notifyAll();
1557 }
1558 Looper.loop();
1559 }
1560
1561 /*
1562 * Use PIN or PUK to unlock SIM card
1563 *
1564 * If PUK is null, unlock SIM card with PIN
1565 *
1566 * If PUK is not null, unlock SIM card with PUK and set PIN code
1567 */
Wink Saville9de0f752013-10-22 19:04:03 -07001568 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569
1570 while (mHandler == null) {
1571 try {
1572 wait();
1573 } catch (InterruptedException e) {
1574 Thread.currentThread().interrupt();
1575 }
1576 }
1577 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1578
1579 if (puk == null) {
1580 mSimCard.supplyPin(pin, callback);
1581 } else {
1582 mSimCard.supplyPuk(puk, pin, callback);
1583 }
1584
1585 while (!mDone) {
1586 try {
1587 Log.d(LOG_TAG, "wait for done");
1588 wait();
1589 } catch (InterruptedException e) {
1590 // Restore the interrupted status
1591 Thread.currentThread().interrupt();
1592 }
1593 }
1594 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001595 int[] resultArray = new int[2];
1596 resultArray[0] = mResult;
1597 resultArray[1] = mRetryCount;
1598 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600 }
1601
1602 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001604
1605 }
1606
Wink Savilleb564aae2014-10-23 10:18:09 -07001607 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 // No permission check needed here: this call is harmless, and it's
1609 // needed for the ServiceState.requestStateUpdate() call (which is
1610 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001611 final long identity = Binder.clearCallingIdentity();
1612 try {
1613 final Phone phone = getPhone(subId);
1614 if (phone != null) {
1615 phone.updateServiceLocation();
1616 }
1617 } finally {
1618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001622 @Override
1623 public boolean isRadioOn(String callingPackage) {
1624 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001627 @Override
1628 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001630 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001631 return false;
1632 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001633
1634 final long identity = Binder.clearCallingIdentity();
1635 try {
1636 return isRadioOnForSubscriber(subId);
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
1639 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001640 }
1641
1642 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001643 final long identity = Binder.clearCallingIdentity();
1644 try {
1645 final Phone phone = getPhone(subId);
1646 if (phone != null) {
1647 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1648 } else {
1649 return false;
1650 }
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
1655
1656 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001657 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
Wink Saville36469e72014-06-11 15:17:00 -07001659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 }
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
1674 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001675 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
Wink Savilleb564aae2014-10-23 10:18:09 -07001678 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001679 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 final Phone phone = getPhone(subId);
1684 if (phone == null) {
1685 return false;
1686 }
1687 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1688 toggleRadioOnOffForSubscriber(subId);
1689 }
1690 return true;
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
Wink Saville36469e72014-06-11 15:17:00 -07001695
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001696 public boolean needMobileRadioShutdown() {
1697 /*
1698 * If any of the Radios are available, it will need to be
1699 * shutdown. So return true if any Radio is available.
1700 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1704 Phone phone = PhoneFactory.getPhone(i);
1705 if (phone != null && phone.isRadioAvailable()) return true;
1706 }
1707 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1708 return false;
1709 } finally {
1710 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
1713
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001716 enforceModifyPermission();
1717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1721 logv("Shutting down Phone " + i);
1722 shutdownRadioUsingPhoneId(i);
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001726 }
1727 }
1728
1729 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001730 Phone phone = PhoneFactory.getPhone(phoneId);
1731 if (phone != null && phone.isRadioAvailable()) {
1732 phone.shutdownRadio();
1733 }
1734 }
1735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001737 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001738
1739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1742 if (defaultPhone != null) {
1743 defaultPhone.setRadioPower(turnOn);
1744 return true;
1745 } else {
1746 loge("There's no default phone.");
1747 return false;
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(turnOn);
1762 return true;
1763 } else {
1764 return false;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Wink Saville36469e72014-06-11 15:17:00 -07001771 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 public boolean enableDataConnectivity() {
1774 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 int subId = mSubscriptionController.getDefaultDataSubId();
1779 final Phone phone = getPhone(subId);
1780 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001781 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001782 return true;
1783 } else {
1784 return false;
1785 }
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Wink Saville36469e72014-06-11 15:17:00 -07001791 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public boolean disableDataConnectivity() {
1794 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001795
1796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 int subId = mSubscriptionController.getDefaultDataSubId();
1799 final Phone phone = getPhone(subId);
1800 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001801 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001802 return true;
1803 } else {
1804 return false;
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001812 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 final Phone phone = getPhone(subId);
1816 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001817 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001818 } else {
1819 return false;
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
1826 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001827 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001828 }
1829
pkanwarae03a6b2016-11-06 20:37:09 -08001830 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001831 enforceCallPermission();
1832
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1836 return;
1837 }
1838 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1839 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
pkanwar32d516d2016-10-14 19:37:38 -07001843 };
1844
Wink Savilleb564aae2014-10-23 10:18:09 -07001845 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1851 return false;
1852 }
1853 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1854 } finally {
1855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 }
1858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001860 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001861 }
1862
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001863 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001864 final long identity = Binder.clearCallingIdentity();
1865 try {
1866 Phone phone = PhoneFactory.getPhone(slotIndex);
1867 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1868 PhoneConstantConversions.convertCallState(phone.getState());
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
1871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001875 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001876 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1877 }
1878
1879 @Override
1880 public int getDataStateForSubId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001881 final long identity = Binder.clearCallingIdentity();
1882 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001883 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001884 if (phone != null) {
1885 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1886 } else {
1887 return PhoneConstantConversions.convertDataState(
1888 PhoneConstants.DataState.DISCONNECTED);
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001896 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001897 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1898 }
1899
1900 @Override
1901 public int getDataActivityForSubId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001902 final long identity = Binder.clearCallingIdentity();
1903 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001904 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001905 if (phone != null) {
1906 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1907 } else {
1908 return TelephonyManager.DATA_ACTIVITY_NONE;
1909 }
1910 } finally {
1911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
1915 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001916 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001917 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001918 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001919
1920 LocationAccessPolicy.LocationPermissionResult locationResult =
1921 LocationAccessPolicy.checkLocationPermission(mApp,
1922 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1923 .setCallingPackage(callingPackage)
1924 .setCallingPid(Binder.getCallingPid())
1925 .setCallingUid(Binder.getCallingUid())
1926 .setMethod("getCellLocation")
1927 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1928 .build());
1929 switch (locationResult) {
1930 case DENIED_HARD:
1931 throw new SecurityException("Not allowed to access cell location");
1932 case DENIED_SOFT:
1933 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001936 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001937 final long identity = Binder.clearCallingIdentity();
1938 try {
1939 if (DBG_LOC) log("getCellLocation: is active user");
1940 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001941 int subId = mSubscriptionController.getDefaultDataSubId();
1942 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1943 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001944 return data;
1945 } finally {
1946 Binder.restoreCallingIdentity(identity);
1947 }
Svetoslav64fad262015-04-14 14:35:21 -07001948 }
1949
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001951 public String getNetworkCountryIsoForPhone(int phoneId) {
1952 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1953 // registered cell info, so return a NULL country instead.
1954 final long identity = Binder.clearCallingIdentity();
1955 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001956 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1957 // Get default phone in this case.
1958 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1959 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001960 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001961 // Todo: fix this when we can get the actual cellular network info when the device
1962 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001963 if (TelephonyManager.NETWORK_TYPE_IWLAN
1964 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1965 return "";
1966 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001967 Phone phone = PhoneFactory.getPhone(phoneId);
1968 if (phone != null) {
1969 ServiceStateTracker sst = phone.getServiceStateTracker();
1970 if (sst != null) {
1971 LocaleTracker lt = sst.getLocaleTracker();
1972 if (lt != null) {
1973 return lt.getCurrentCountry();
1974 }
1975 }
1976 }
1977 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001978 } finally {
1979 Binder.restoreCallingIdentity(identity);
1980 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001981 }
1982
1983 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001985 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001986 }
1987
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001989 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 mApp.enforceCallingOrSelfPermission(
1991 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001992
1993 final long identity = Binder.clearCallingIdentity();
1994 try {
1995 final Phone phone = getPhone(subId);
1996 if (phone != null) {
1997 phone.enableLocationUpdates();
1998 }
1999 } finally {
2000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
2003
2004 @Override
2005 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002006 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002007 }
2008
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002010 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 mApp.enforceCallingOrSelfPermission(
2012 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002013
2014 final long identity = Binder.clearCallingIdentity();
2015 try {
2016 final Phone phone = getPhone(subId);
2017 if (phone != null) {
2018 phone.disableLocationUpdates();
2019 }
2020 } finally {
2021 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002023 }
2024
Nathan Harold31d7ff32018-10-15 20:20:30 -07002025 /**
2026 * Returns the target SDK version number for a given package name.
2027 *
2028 * @return target SDK if the package is found or INT_MAX.
2029 */
2030 private int getTargetSdk(String packageName) {
2031 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002032 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2033 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002034 if (ai != null) return ai.targetSdkVersion;
2035 } catch (PackageManager.NameNotFoundException unexpected) {
2036 }
2037 return Integer.MAX_VALUE;
2038 }
2039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 @Override
2041 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002042 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2043 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002044 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2045 throw new SecurityException(
2046 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2047 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002048
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2050 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2051 return null;
2052 }
Svetoslav64fad262015-04-14 14:35:21 -07002053
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002054 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055
Nathan Haroldf180aac2018-06-01 18:43:55 -07002056 List<CellInfo> info = getAllCellInfo(callingPackage);
2057 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058
Nathan Haroldf180aac2018-06-01 18:43:55 -07002059 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2060 for (CellInfo ci : info) {
2061 if (ci instanceof CellInfoGsm) {
2062 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2063 } else if (ci instanceof CellInfoWcdma) {
2064 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002067 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 }
2069
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002070 private List<CellInfo> getCachedCellInfo() {
2071 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2072 for (Phone phone : PhoneFactory.getPhones()) {
2073 List<CellInfo> info = phone.getAllCellInfo();
2074 if (info != null) cellInfos.addAll(info);
2075 }
2076 return cellInfos;
2077 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078
2079 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002080 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002081 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002082 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002083
2084 LocationAccessPolicy.LocationPermissionResult locationResult =
2085 LocationAccessPolicy.checkLocationPermission(mApp,
2086 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2087 .setCallingPackage(callingPackage)
2088 .setCallingPid(Binder.getCallingPid())
2089 .setCallingUid(Binder.getCallingUid())
2090 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002091 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002092 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2093 .build());
2094 switch (locationResult) {
2095 case DENIED_HARD:
2096 throw new SecurityException("Not allowed to access cell info");
2097 case DENIED_SOFT:
2098 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 }
2100
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002101 final int targetSdk = getTargetSdk(callingPackage);
2102 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2103 return getCachedCellInfo();
2104 }
2105
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002106 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002107 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002108 final long identity = Binder.clearCallingIdentity();
2109 try {
2110 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2111 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002112 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002113 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002114 if (info != null) cellInfos.addAll(info);
2115 }
2116 return cellInfos;
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120 }
2121
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002122 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002123 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2124 requestCellInfoUpdateInternal(
2125 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2126 }
2127
2128 @Override
2129 public void requestCellInfoUpdateWithWorkSource(
2130 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2131 enforceModifyPermission();
2132 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2133 }
2134
2135 private void requestCellInfoUpdateInternal(
2136 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002137 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002138 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002139
2140 LocationAccessPolicy.LocationPermissionResult locationResult =
2141 LocationAccessPolicy.checkLocationPermission(mApp,
2142 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2143 .setCallingPackage(callingPackage)
2144 .setCallingPid(Binder.getCallingPid())
2145 .setCallingUid(Binder.getCallingUid())
2146 .setMethod("requestCellInfoUpdate")
2147 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2148 .build());
2149 switch (locationResult) {
2150 case DENIED_HARD:
2151 throw new SecurityException("Not allowed to access cell info");
2152 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002153 try {
2154 cb.onCellInfo(new ArrayList<CellInfo>());
2155 } catch (RemoteException re) {
2156 // Drop without consequences
2157 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002158 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002159 }
2160
Nathan Harolda939a962019-05-09 10:13:47 -07002161
2162 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002163 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2164
2165 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2166 }
2167
2168 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002170 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002171 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002175 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180
Shishir Agrawala9f32182016-04-12 12:00:16 -07002181 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002182 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002183 Phone phone = PhoneFactory.getPhone(slotIndex);
2184 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002185 return null;
2186 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002187 int subId = phone.getSubId();
2188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2189 mApp, subId, callingPackage, "getImeiForSlot")) {
2190 return null;
2191 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002192
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 return phone.getImei();
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
2198 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002199 }
2200
2201 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002202 public String getTypeAllocationCodeForSlot(int slotIndex) {
2203 Phone phone = PhoneFactory.getPhone(slotIndex);
2204 String tac = null;
2205 if (phone != null) {
2206 String imei = phone.getImei();
2207 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2208 }
2209 return tac;
2210 }
2211
2212 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002213 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002214 Phone phone = PhoneFactory.getPhone(slotIndex);
2215 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002216 return null;
2217 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002218
Jeff Davidson913390f2018-02-23 17:11:49 -08002219 int subId = phone.getSubId();
2220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2221 mApp, subId, callingPackage, "getMeidForSlot")) {
2222 return null;
2223 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002224
2225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 return phone.getMeid();
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
2230 }
Jack Yu2af8d712017-03-15 17:14:14 -07002231 }
2232
2233 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002234 public String getManufacturerCodeForSlot(int slotIndex) {
2235 Phone phone = PhoneFactory.getPhone(slotIndex);
2236 String manufacturerCode = null;
2237 if (phone != null) {
2238 String meid = phone.getMeid();
2239 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2240 }
2241 return manufacturerCode;
2242 }
2243
2244 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002245 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002246 Phone phone = PhoneFactory.getPhone(slotIndex);
2247 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002248 return null;
2249 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002250 int subId = phone.getSubId();
2251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2252 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2253 return null;
2254 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002255
2256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 return phone.getDeviceSvn();
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
2261 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002262 }
2263
fionaxu43304da2017-11-27 22:51:16 -08002264 @Override
2265 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002266 final long identity = Binder.clearCallingIdentity();
2267 try {
2268 final Phone phone = getPhone(subId);
2269 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
2272 }
fionaxu43304da2017-11-27 22:51:16 -08002273 }
2274
2275 @Override
2276 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 final Phone phone = getPhone(subId);
2280 return phone == null ? null : phone.getCarrierName();
2281 } finally {
2282 Binder.restoreCallingIdentity(identity);
2283 }
fionaxu43304da2017-11-27 22:51:16 -08002284 }
2285
calvinpaneed9ae82018-11-01 19:43:06 +08002286 @Override
chen xua31f22b2019-03-06 15:28:50 -08002287 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 final Phone phone = getPhone(subId);
2291 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002292 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
2296 }
2297
2298 @Override
chen xua31f22b2019-03-06 15:28:50 -08002299 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002303 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002304 } finally {
2305 Binder.restoreCallingIdentity(identity);
2306 }
2307 }
2308
chen xu02581692018-11-11 19:03:44 -08002309 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002310 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2311 if (!isSubscriptionMccMnc) {
2312 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2313 }
chen xu02581692018-11-11 19:03:44 -08002314 final Phone phone = PhoneFactory.getPhone(slotIndex);
2315 if (phone == null) {
2316 return TelephonyManager.UNKNOWN_CARRIER_ID;
2317 }
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
2320 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2321 } finally {
2322 Binder.restoreCallingIdentity(identity);
2323 }
2324 }
2325
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 //
2327 // Internal helper methods.
2328 //
2329
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002330 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2332 *
2333 * @throws SecurityException if the caller does not have the required permission
2334 */
2335 private void enforceModifyPermission() {
2336 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2337 }
2338
2339 /**
2340 * Make sure the caller has the CALL_PHONE permission.
2341 *
2342 * @throws SecurityException if the caller does not have the required permission
2343 */
2344 private void enforceCallPermission() {
2345 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2346 }
2347
Stuart Scott8eef64f2015-04-08 15:13:54 -07002348 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002350 "ConnectivityService");
2351 }
2352
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 private String createTelUrl(String number) {
2354 if (TextUtils.isEmpty(number)) {
2355 return null;
2356 }
2357
Jake Hambye994d462014-02-03 13:10:13 -08002358 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
Ihab Awadf9e92732013-12-05 18:02:52 -08002361 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2363 }
2364
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002365 private static void logv(String msg) {
2366 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2367 }
2368
Ihab Awadf9e92732013-12-05 18:02:52 -08002369 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2371 }
2372
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002373 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002375 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002376 }
2377
Sanket Padawe356d7632015-06-22 14:03:32 -07002378 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002379 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 final Phone phone = PhoneFactory.getPhone(slotIndex);
2383 if (phone == null) {
2384 return PhoneConstants.PHONE_TYPE_NONE;
2385 } else {
2386 return phone.getPhoneType();
2387 }
2388 } finally {
2389 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 }
2392
2393 /**
2394 * Returns the CDMA ERI icon index to display
2395 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002396 @Override
2397 public int getCdmaEriIconIndex(String callingPackage) {
2398 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002399 }
2400
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002402 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002404 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 return -1;
2406 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002407
2408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
2411 if (phone != null) {
2412 return phone.getCdmaEriIconIndex();
2413 } else {
2414 return -1;
2415 }
2416 } finally {
2417 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
2421 /**
2422 * Returns the CDMA ERI icon mode,
2423 * 0 - ON
2424 * 1 - FLASHING
2425 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002426 @Override
2427 public int getCdmaEriIconMode(String callingPackage) {
2428 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002429 }
2430
Sanket Padawe356d7632015-06-22 14:03:32 -07002431 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002432 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002434 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002435 return -1;
2436 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 final Phone phone = getPhone(subId);
2441 if (phone != null) {
2442 return phone.getCdmaEriIconMode();
2443 } else {
2444 return -1;
2445 }
2446 } finally {
2447 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
2450
2451 /**
2452 * Returns the CDMA ERI text,
2453 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002454 @Override
2455 public String getCdmaEriText(String callingPackage) {
2456 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002457 }
2458
Sanket Padawe356d7632015-06-22 14:03:32 -07002459 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002460 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002462 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002463 return null;
2464 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002465
2466 final long identity = Binder.clearCallingIdentity();
2467 try {
2468 final Phone phone = getPhone(subId);
2469 if (phone != null) {
2470 return phone.getCdmaEriText();
2471 } else {
2472 return null;
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
2479 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002480 * Returns the CDMA MDN.
2481 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002482 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002483 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2485 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002486
2487 final long identity = Binder.clearCallingIdentity();
2488 try {
2489 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002490 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002491 return phone.getLine1Number();
2492 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002493 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002494 return null;
2495 }
2496 } finally {
2497 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002498 }
2499 }
2500
2501 /**
2502 * Returns the CDMA MIN.
2503 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002505 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2507 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2513 return phone.getCdmaMin();
2514 } else {
2515 return null;
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002519 }
2520 }
2521
Hall Liud892bec2018-11-30 14:51:45 -08002522 @Override
2523 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2524 INumberVerificationCallback callback, String callingPackage) {
2525 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2526 != PERMISSION_GRANTED) {
2527 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2528 }
2529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2530
2531 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2532 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2533 throw new SecurityException("Calling package must be configured in the device config");
2534 }
2535
2536 if (range == null) {
2537 throw new NullPointerException("Range must be non-null");
2538 }
2539
2540 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002541 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002542
2543 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2544 }
2545
Junda Liuca05d5d2014-08-14 22:36:34 -07002546 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 * Returns true if CDMA provisioning needs to run.
2548 */
2549 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002550 final long identity = Binder.clearCallingIdentity();
2551 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002552 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002553 } finally {
2554 Binder.restoreCallingIdentity(identity);
2555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 }
2557
2558 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002559 * Sets the voice mail number of a given subId.
2560 */
2561 @Override
2562 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002563 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2568 new Pair<String, String>(alphaTag, number), new Integer(subId));
2569 return success;
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
2572 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002573 }
2574
Ta-wei Yen87c49842016-05-13 21:19:52 -07002575 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002576 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002578 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002579 if (!TextUtils.equals(callingPackage, systemDialer)) {
2580 throw new SecurityException("caller must be system dialer");
2581 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2586 if (phoneAccountHandle == null) {
2587 return null;
2588 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002589 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002590 } finally {
2591 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002592 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002593 }
2594
2595 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002596 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002599 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002600 return null;
2601 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002602
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002603 final long identity = Binder.clearCallingIdentity();
2604 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002605 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002606 } finally {
2607 Binder.restoreCallingIdentity(identity);
2608 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002609 }
2610
2611 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002612 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2613 VisualVoicemailSmsFilterSettings settings) {
2614 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002619 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002620 } finally {
2621 Binder.restoreCallingIdentity(identity);
2622 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002623 }
2624
2625 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002626 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002632 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002636 }
2637
2638 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002639 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2640 String callingPackage, int subId) {
2641 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002646 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002647 } finally {
2648 Binder.restoreCallingIdentity(identity);
2649 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002650 }
2651
2652 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002653 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002654 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002659 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002663 }
2664
2665 @Override
2666 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2667 String number, int port, String text, PendingIntent sentIntent) {
2668 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002669 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002670 enforceSendSmsPermission();
Amit Mahajan716e76c2019-05-13 13:48:32 -07002671 SmsController smsController = PhoneFactory.getSmsController();
2672 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2673 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002674 }
Amit Mahajan716e76c2019-05-13 13:48:32 -07002675
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002676 /**
fionaxu0152e512016-11-14 13:36:14 -08002677 * Sets the voice activation state of a given subId.
2678 */
2679 @Override
2680 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2682 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 final Phone phone = getPhone(subId);
2687 if (phone != null) {
2688 phone.setVoiceActivationState(activationState);
2689 } else {
2690 loge("setVoiceActivationState fails with invalid subId: " + subId);
2691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002694 }
2695 }
2696
2697 /**
2698 * Sets the data activation state of a given subId.
2699 */
2700 @Override
2701 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2703 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002704
2705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 final Phone phone = getPhone(subId);
2708 if (phone != null) {
2709 phone.setDataActivationState(activationState);
2710 } else {
2711 loge("setVoiceActivationState fails with invalid subId: " + subId);
2712 }
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002715 }
2716 }
2717
2718 /**
2719 * Returns the voice activation state of a given subId.
2720 */
2721 @Override
2722 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002723 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002724
fionaxu0152e512016-11-14 13:36:14 -08002725 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 if (phone != null) {
2729 return phone.getVoiceActivationState();
2730 } else {
2731 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2732 }
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002735 }
2736 }
2737
2738 /**
2739 * Returns the data activation state of a given subId.
2740 */
2741 @Override
2742 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002743 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002744
fionaxu0152e512016-11-14 13:36:14 -08002745 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002746 final long identity = Binder.clearCallingIdentity();
2747 try {
2748 if (phone != null) {
2749 return phone.getDataActivationState();
2750 } else {
2751 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002755 }
2756 }
2757
2758 /**
Wink Saville36469e72014-06-11 15:17:00 -07002759 * Returns the unread count of voicemails for a subId
2760 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002762 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2764 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2765 return 0;
2766 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(subId);
2770 if (phone != null) {
2771 return phone.getVoiceMessageCount();
2772 } else {
2773 return 0;
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
2780 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002781 * returns true, if the device is in a state where both voice and data
2782 * are supported simultaneously. This can change based on location or network condition.
2783 */
2784 @Override
2785 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = getPhone(subId);
2789 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
2792 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002793 }
2794
2795 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002796 * Send the dialer code if called from the current default dialer or the caller has
2797 * carrier privilege.
2798 * @param inputCode The dialer code to send
2799 */
2800 @Override
2801 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002802 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002803 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002804 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2805 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002806 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002807 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2808 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002809 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002810
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002813 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
fionaxu235cc5e2017-03-06 22:25:57 -08002817 }
2818
Pengquan Meng0c05b502018-09-06 09:59:22 -07002819 @Override
2820 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002821 if (!isActiveSubscription(subId)) {
2822 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2823 }
2824
Pengquan Meng0c05b502018-09-06 09:59:22 -07002825 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2826 }
2827
Brad Ebinger4c460712018-10-01 10:40:55 -07002828 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002829 public boolean isInEmergencySmsMode() {
2830 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 for (Phone phone : PhoneFactory.getPhones()) {
2834 if (phone.isInEmergencySmsMode()) {
2835 return true;
2836 }
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
2840 }
2841 return false;
2842 }
2843
2844 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002845 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2846 throws RemoteException {
2847 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002848 final long token = Binder.clearCallingIdentity();
2849 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002851 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002852 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002853 } catch (ImsException e) {
2854 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002855 } finally {
2856 Binder.restoreCallingIdentity(token);
2857 }
2858 }
2859
2860 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002861 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2862 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002863 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2864 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2865 }
2866 Binder.withCleanCallingIdentity(() -> {
2867 try {
2868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002869 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002870 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002871 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002872 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2873 + "is inactive, ignoring unregister.");
2874 // If the subscription is no longer active, just return, since the callback
2875 // will already have been removed internally.
2876 }
2877 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002878 }
2879
2880 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002881 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2882 throws RemoteException {
2883 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2885 final long token = Binder.clearCallingIdentity();
2886 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002887 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002888 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002889 } catch (ImsException e) {
2890 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002891 } finally {
2892 Binder.restoreCallingIdentity(token);
2893 }
2894 }
2895
2896 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002897 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2898 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002899
2900 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2901 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2902 }
2903 Binder.withCleanCallingIdentity(() -> {
2904 try {
2905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002906 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002907 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002908 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002909 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2910 + "is inactive, ignoring unregister.");
2911 // If the subscription is no longer active, just return, since the callback
2912 // will already have been removed internally.
2913 }
2914 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002915 }
2916
2917 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002918 public boolean isCapable(int subId, int capability, int regTech) {
2919 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2921 final long token = Binder.clearCallingIdentity();
2922 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002923 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002924 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002925 } catch (com.android.ims.ImsException e) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002926 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2927 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002928 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002929 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2930 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002931 } finally {
2932 Binder.restoreCallingIdentity(token);
2933 }
2934 }
2935
2936 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002937 public boolean isAvailable(int subId, int capability, int regTech) {
2938 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002939 final long token = Binder.clearCallingIdentity();
2940 try {
2941 Phone phone = getPhone(subId);
2942 if (phone == null) return false;
2943 return phone.isImsCapabilityAvailable(capability, regTech);
2944 } finally {
2945 Binder.restoreCallingIdentity(token);
2946 }
2947 }
2948
2949 @Override
2950 public boolean isAdvancedCallingSettingEnabled(int subId) {
2951 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2953 final long token = Binder.clearCallingIdentity();
2954 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002955 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002956 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002957 } catch (ImsException e) {
2958 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002959 } finally {
2960 Binder.restoreCallingIdentity(token);
2961 }
2962 }
2963
2964 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002965 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002967 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002971 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002972 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002973 } catch (ImsException e) {
2974 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002975 } finally {
2976 Binder.restoreCallingIdentity(identity);
2977 }
2978 }
2979
2980 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002981 public boolean isVtSettingEnabled(int subId) {
2982 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002986 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
2987 } catch (ImsException e) {
2988 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07002989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
2994 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002995 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002997 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002998 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)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003002 } catch (ImsException e) {
3003 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
3010 public boolean isVoWiFiSettingEnabled(int subId) {
3011 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003015 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003016 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003017 } catch (ImsException e) {
3018 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003025 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003027 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003028 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 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003032 } catch (ImsException e) {
3033 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
3040 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3041 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003045 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003046 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003047 } catch (ImsException e) {
3048 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003055 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003057 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003061 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003062 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003063 } catch (ImsException e) {
3064 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3073 "setVoWiFiNonPersistent");
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003077 ImsManager.getInstance(mApp,
Brad Ebinger2bc95702019-05-07 18:33:46 -07003078 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003079 } catch (ImsException e) {
3080 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
3084 }
3085
3086 @Override
3087 public int getVoWiFiModeSetting(int subId) {
3088 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003092 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003093 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003094 } catch (ImsException e) {
3095 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
3099 }
3100
3101 @Override
3102 public void setVoWiFiModeSetting(int subId, int mode) {
3103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3104 "setVoWiFiModeSetting");
3105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003108 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003109 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003110 } catch (ImsException e) {
3111 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003112 } finally {
3113 Binder.restoreCallingIdentity(identity);
3114 }
3115 }
3116
3117 @Override
3118 public int getVoWiFiRoamingModeSetting(int subId) {
3119 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3120 final long identity = Binder.clearCallingIdentity();
3121 try {
3122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003123 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003124 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003125 } catch (ImsException e) {
3126 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
3132 @Override
3133 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3135 "setVoWiFiRoamingModeSetting");
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003139 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003140 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003141 } catch (ImsException e) {
3142 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
3148 @Override
3149 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3151 "setRttCapabilityEnabled");
3152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003155 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3156 } catch (ImsException e) {
3157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
3161 }
3162
3163 @Override
3164 public boolean isTtyOverVolteEnabled(int subId) {
3165 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003169 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003170 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003171 } catch (ImsException e) {
3172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger4c460712018-10-01 10:40:55 -07003173 } finally {
3174 Binder.restoreCallingIdentity(identity);
3175 }
3176 }
3177
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003178 @Override
3179 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3180 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003184 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003185 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003186 } catch (ImsException e) {
3187 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
3191 }
3192
3193 @Override
3194 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3195 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3196 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003197 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3198 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3199 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003200 try {
3201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003202 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003203 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003204 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003205 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3206 + "is inactive, ignoring unregister.");
3207 // If the subscription is no longer active, just return, since the callback will already
3208 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
3212 }
3213
3214 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003215 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3216 boolean isProvisioned) {
3217 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3218 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3219 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3220 }
3221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3222 "setProvisioningStatusForCapability");
3223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3226 Phone phone = getPhone(subId);
3227 if (phone == null) {
3228 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3229 + subId);
3230 return;
3231 }
3232 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3233 return;
3234 }
3235
3236 // this capability requires provisioning, route to the correct API.
3237 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3238 switch (capability) {
3239 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3240 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3241 ims.setVolteProvisioned(isProvisioned);
3242 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3243 ims.setWfcProvisioned(isProvisioned);
3244 }
3245 break;
3246 }
3247 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3248 // There is currently no difference in VT provisioning type.
3249 ims.setVtProvisioned(isProvisioned);
3250 break;
3251 }
3252 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3253 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3254 // change the capability of the feature instead if needed.
3255 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3256 == isProvisioned) {
3257 // No change in provisioning.
3258 return;
3259 }
3260 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3261 try {
3262 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003263 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003264 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3265 + ", Exception" + e.getMessage());
3266 }
3267 break;
3268 }
3269 default: {
3270 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3271 + capability + "', which does not require provisioning.");
3272 }
3273 }
3274
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
3278 }
3279
3280 @Override
3281 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3282 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3283 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3284 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3285 }
3286 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3290 Phone phone = getPhone(subId);
3291 if (phone == null) {
3292 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3293 + subId);
3294 // We will fail with "true" as the provisioning status because this is the default
3295 // if we do not require provisioning.
3296 return true;
3297 }
3298
3299 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3300 return true;
3301 }
3302
3303 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3304 switch (capability) {
3305 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3306 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3307 return ims.isVolteProvisionedOnDevice();
3308 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3309 return ims.isWfcProvisionedOnDevice();
3310 }
3311 // This should never happen, since we are checking tech above to make sure it
3312 // is either LTE or IWLAN.
3313 throw new IllegalArgumentException("Invalid radio technology for voice "
3314 + "capability.");
3315 }
3316 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3317 // There is currently no difference in VT provisioning type.
3318 return ims.isVtProvisionedOnDevice();
3319 }
3320 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3321 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3322 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3323 }
3324 default: {
3325 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3326 + capability + "', which does not require provisioning.");
3327 }
3328 }
3329
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
3333 }
3334
3335 @Override
3336 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3337 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3338 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3339 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3340 }
3341 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3342 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3343 return (provisionedBits & capability) > 0;
3344 }
3345
3346 @Override
3347 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3348 boolean isProvisioned) {
3349 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3350 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3351 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3352 }
3353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3354 "setProvisioningStatusForCapability");
3355 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3356 // If the current provisioning status for capability already matches isProvisioned,
3357 // do nothing.
3358 if (((provisionedBits & capability) > 0) == isProvisioned) {
3359 return;
3360 }
3361 if (isProvisioned) {
3362 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3363 } else {
3364 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3365 }
3366 }
3367
3368 /**
3369 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3370 * technology. The bitfield should mirror the bitfield defined by
3371 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3372 */
3373 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3374 String key = getMmTelProvisioningKey(subId, tech);
3375 // Default is no capabilities are provisioned.
3376 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3377 }
3378
3379 /**
3380 * Sets the MmTel capability provisioning bitfield (defined by
3381 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3382 * technology specified.
3383 *
3384 * Note: This is a synchronous command and should not be called on UI thread.
3385 */
3386 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3387 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3388 String key = getMmTelProvisioningKey(subId, tech);
3389 editor.putInt(key, newField);
3390 editor.commit();
3391 }
3392
3393 private static String getMmTelProvisioningKey(int subId, int tech) {
3394 // resulting key is provision_ims_mmtel_{subId}_{tech}
3395 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3396 }
3397
3398 /**
3399 * Query CarrierConfig to see if the specified capability requires provisioning for the
3400 * carrier associated with the subscription id.
3401 */
3402 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3403 int capability) {
3404 CarrierConfigManager configManager = new CarrierConfigManager(context);
3405 PersistableBundle c = configManager.getConfigForSubId(subId);
3406 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003407 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003408 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3409 false);
3410 boolean requireVoiceVtProvisioning = c.getBoolean(
3411 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3412
3413 // First check to make sure that the capability requires provisioning.
3414 switch (capability) {
3415 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3416 // intentional fallthrough
3417 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3418 if (requireVoiceVtProvisioning) {
3419 // Voice and Video requires provisioning
3420 return true;
3421 }
3422 break;
3423 }
3424 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3425 if (requireUtProvisioning) {
3426 // UT requires provisioning
3427 return true;
3428 }
3429 break;
3430 }
3431 }
3432 return false;
3433 }
3434
3435 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3438 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3439 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 enforceReadPrivilegedPermission("getImsProvisioningInt");
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003444 int slotId = getSlotIndex(subId);
3445 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3446 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3447 + subId + "' for key:" + key);
3448 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3449 }
3450 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003451 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003452 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3453 + subId + "' for key:" + key);
3454 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003455 } finally {
3456 Binder.restoreCallingIdentity(identity);
3457 }
3458 }
3459
3460 @Override
3461 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003462 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3463 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3464 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 enforceReadPrivilegedPermission("getImsProvisioningString");
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003469 int slotId = getSlotIndex(subId);
3470 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3471 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3472 + subId + "' for key:" + key);
3473 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3474 }
3475 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003476 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003477 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3478 + subId + "' for key:" + key);
3479 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
3483 }
3484
3485 @Override
3486 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003487 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3488 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3489 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3491 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003495 int slotId = getSlotIndex(subId);
3496 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3497 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3498 + subId + "' for key:" + key);
3499 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3500 }
3501 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003502 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003503 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3504 + "' for key:" + key);
3505 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
3509 }
3510
3511 @Override
3512 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3514 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3515 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3517 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003521 int slotId = getSlotIndex(subId);
3522 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3523 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3524 + subId + "' for key:" + key);
3525 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3526 }
3527 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003528 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003529 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3530 + "' for key:" + key);
3531 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
3535 }
3536
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger4c460712018-10-01 10:40:55 -07003538 int slotId = SubscriptionManager.getSlotIndex(subId);
3539 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003540 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3541 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger4c460712018-10-01 10:40:55 -07003542 }
3543 return slotId;
3544 }
3545
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003546 private int getSlotIndex(int subId) {
3547 int slotId = SubscriptionManager.getSlotIndex(subId);
3548 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3549 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3550 }
3551 return slotId;
3552 }
3553
Wink Saville36469e72014-06-11 15:17:00 -07003554 /**
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003555 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003556 */
3557 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003559 final int targetSdk = getTargetSdk(callingPackage);
3560 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3561 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3562 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003563 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3564 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003565 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3566 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003567
Malcolm Chend965c8b2018-02-28 15:00:40 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
3571 if (phone != null) {
3572 return phone.getServiceState().getDataNetworkType();
3573 } else {
3574 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3575 }
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003579 }
3580
3581 /**
3582 * Returns the data network type
3583 */
3584 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003585 public int getDataNetworkType(String callingPackage) {
3586 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003587 }
3588
3589 /**
3590 * Returns the data network type for a subId
3591 */
3592 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003593 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003595 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003596 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3597 }
3598
Malcolm Chend965c8b2018-02-28 15:00:40 -08003599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 final Phone phone = getPhone(subId);
3602 if (phone != null) {
3603 return phone.getServiceState().getDataNetworkType();
3604 } else {
3605 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 }
3611
3612 /**
Wink Saville36469e72014-06-11 15:17:00 -07003613 * Returns the Voice network type for a subId
3614 */
3615 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003616 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003618 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003619 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3620 }
3621
Malcolm Chend965c8b2018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone != null) {
3626 return phone.getServiceState().getVoiceNetworkType();
3627 } else {
3628 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003633 }
3634
3635 /**
3636 * @return true if a ICC card is present
3637 */
3638 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003639 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003640 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3641 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003642 }
3643
3644 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003645 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003646 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003647 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003648 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 final Phone phone = PhoneFactory.getPhone(slotIndex);
3652 if (phone != null) {
3653 return phone.getIccCard().hasIccCard();
3654 } else {
3655 return false;
3656 }
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003660 }
3661
3662 /**
3663 * Return if the current radio is LTE on CDMA. This
3664 * is a tri-state return value as for a period of time
3665 * the mode may be unknown.
3666 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003667 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003668 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003669 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003671 @Override
3672 public int getLteOnCdmaMode(String callingPackage) {
3673 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003674 }
3675
Sanket Padawe356d7632015-06-22 14:03:32 -07003676 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003677 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003679 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003680 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3681 }
3682
Malcolm Chend965c8b2018-02-28 15:00:40 -08003683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 if (phone == null) {
3687 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3688 } else {
3689 return phone.getLteOnCdmaMode();
3690 }
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003693 }
Wink Saville36469e72014-06-11 15:17:00 -07003694 }
3695
Wink Saville36469e72014-06-11 15:17:00 -07003696 /**
3697 * {@hide}
3698 * Returns Default subId, 0 in the case of single standby.
3699 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003700 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003701 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003702 }
3703
Shishir Agrawala9f32182016-04-12 12:00:16 -07003704 private int getSlotForDefaultSubscription() {
3705 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3706 }
3707
Wink Savilleb564aae2014-10-23 10:18:09 -07003708 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003709 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003710 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003711
Pengquan Meng466e2482018-09-21 15:54:48 -07003712 private boolean isActiveSubscription(int subId) {
3713 return mSubscriptionController.isActiveSubId(subId);
3714 }
3715
Ihab Awadf2177b72013-11-25 13:33:23 -08003716 /**
3717 * @see android.telephony.TelephonyManager.WifiCallingChoices
3718 */
3719 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003720 final long identity = Binder.clearCallingIdentity();
3721 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003722 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003723 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3724 getWhenToMakeWifiCallsDefaultPreference());
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003728 }
3729
3730 /**
3731 * @see android.telephony.TelephonyManager.WifiCallingChoices
3732 */
3733 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003737 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003738 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003742 }
3743
Sailesh Nepald1e68152013-12-12 19:08:02 -08003744 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003745 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003746 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003747 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003748
Jordan Liu73b078d2019-02-28 12:03:40 -08003749 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3750 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3751 if (phoneId == -1) {
3752 throw new IllegalArgumentException("Given slot index: " + slotIndex
3753 + " does not correspond to an active phone");
3754 }
3755 return PhoneFactory.getPhone(phoneId);
3756 }
3757
Shishir Agrawal566b7612013-10-28 14:41:00 -07003758 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003759 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3760 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3762 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003764 if (DBG) {
3765 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3766 }
3767 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3768 p2);
3769 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003770
Jordan Liu73b078d2019-02-28 12:03:40 -08003771
3772 @Override
3773 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3774 int slotIndex, String callingPackage, String aid, int p2) {
3775 enforceModifyPermission();
3776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3777 if (DBG) {
3778 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3779 }
3780 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3781 callingPackage, aid, p2);
3782 }
3783
3784 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3785 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 if (TextUtils.equals(ISDR_AID, aid)) {
3789 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003790 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3791 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003792 if (bestComponent == null
3793 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3794 loge("The calling package is not allowed to access ISD-R.");
3795 throw new SecurityException(
3796 "The calling package is not allowed to access ISD-R.");
3797 }
Derek Tan740e1672017-06-27 14:56:27 -07003798 }
Derek Tan740e1672017-06-27 14:56:27 -07003799
Malcolm Chend965c8b2018-02-28 15:00:40 -08003800 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003801 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3802 null /* workSource */);
3803 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003804 return response;
3805 } finally {
3806 Binder.restoreCallingIdentity(identity);
3807 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003808 }
3809
3810 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003811 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3813 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003814 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3815 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3816 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003817
Jordan Liu73b078d2019-02-28 12:03:40 -08003818 @Override
3819 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3820 enforceModifyPermission();
3821 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3822 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3823 channel);
3824 }
3825
3826 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003829 if (channel < 0) {
3830 return false;
3831 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003832 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3833 null /* workSource */);
3834 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003835 return success;
3836 } finally {
3837 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003838 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003839 }
3840
3841 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003842 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003843 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3845 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003846 if (DBG) {
3847 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3848 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3849 + p3 + " data=" + data);
3850 }
3851 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3852 command, p1, p2, p3, data);
3853 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003854
Jordan Liu73b078d2019-02-28 12:03:40 -08003855 @Override
3856 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3857 int command, int p1, int p2, int p3, String data) {
3858 enforceModifyPermission();
3859 if (DBG) {
3860 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3861 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3862 + p3 + " data=" + data);
3863 }
3864 return iccTransmitApduLogicalChannelWithPermission(
3865 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3866 data);
3867 }
3868
3869 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3870 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
Hall Liucdcfa292019-05-02 09:16:29 -07003873 if (channel <= 0) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003874 return "";
3875 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003876
Malcolm Chend965c8b2018-02-28 15:00:40 -08003877 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003878 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3879 null /* workSource */);
3880 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003881
Malcolm Chend965c8b2018-02-28 15:00:40 -08003882 // Append the returned status code to the end of the response payload.
3883 String s = Integer.toHexString(
3884 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3885 if (response.payload != null) {
3886 s = IccUtils.bytesToHexString(response.payload) + s;
3887 }
3888 return s;
3889 } finally {
3890 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003891 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003892 }
Jake Hambye994d462014-02-03 13:10:13 -08003893
Evan Charltonc66da362014-05-16 14:06:40 -07003894 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003895 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3896 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3898 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003899 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003900 if (DBG) {
3901 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3902 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3903 }
3904 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3905 cla, command, p1, p2, p3, data);
3906 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003907
Jordan Liu73b078d2019-02-28 12:03:40 -08003908 @Override
3909 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3910 int command, int p1, int p2, int p3, String data) {
3911 enforceModifyPermission();
3912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3913 if (DBG) {
3914 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3915 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3916 + " data=" + data);
3917 }
3918
3919 return iccTransmitApduBasicChannelWithPermission(
3920 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3921 p2, p3, data);
3922 }
3923
3924 // open APDU basic channel assuming the caller has sufficient permissions
3925 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3926 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3930 && TextUtils.equals(ISDR_AID, data)) {
3931 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003932 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3933 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003934 if (bestComponent == null
3935 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3936 loge("The calling package is not allowed to select ISD-R.");
3937 throw new SecurityException(
3938 "The calling package is not allowed to select ISD-R.");
3939 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003940 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003941
Malcolm Chend965c8b2018-02-28 15:00:40 -08003942 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003943 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3944 null /* workSource */);
3945 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003946
Malcolm Chend965c8b2018-02-28 15:00:40 -08003947 // Append the returned status code to the end of the response payload.
3948 String s = Integer.toHexString(
3949 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3950 if (response.payload != null) {
3951 s = IccUtils.bytesToHexString(response.payload) + s;
3952 }
3953 return s;
3954 } finally {
3955 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003956 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003957 }
3958
3959 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003960 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003961 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3963 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003964
Malcolm Chend965c8b2018-02-28 15:00:40 -08003965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 if (DBG) {
3968 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3969 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3970 }
3971
3972 IccIoResult response =
3973 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3974 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3975 subId);
3976
3977 if (DBG) {
3978 log("Exchange SIM_IO [R]" + response);
3979 }
3980
3981 byte[] result = null;
3982 int length = 2;
3983 if (response.payload != null) {
3984 length = 2 + response.payload.length;
3985 result = new byte[length];
3986 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3987 } else {
3988 result = new byte[length];
3989 }
3990
3991 result[length - 1] = (byte) response.sw2;
3992 result[length - 2] = (byte) response.sw1;
3993 return result;
3994 } finally {
3995 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003996 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003997 }
3998
Nathan Haroldb3014052017-01-25 15:57:32 -08003999 /**
4000 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4001 * on a particular subscription
4002 */
sqianb6e41952018-03-12 14:54:01 -07004003 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4005 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4006 return null;
4007 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004008
4009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 if (appType != TelephonyManager.APPTYPE_USIM
4012 && appType != TelephonyManager.APPTYPE_SIM) {
4013 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4014 return null;
4015 }
4016 Object response = sendRequest(
4017 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4018 if (response instanceof String[]) {
4019 return (String[]) response;
4020 }
4021 // Response is an Exception of some kind,
4022 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004023 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004024 } finally {
4025 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004026 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004027 }
4028
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004030 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4032 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004033
Malcolm Chend965c8b2018-02-28 15:00:40 -08004034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4037 if (response.payload == null) {
4038 return "";
4039 }
Evan Charltonc66da362014-05-16 14:06:40 -07004040
Malcolm Chend965c8b2018-02-28 15:00:40 -08004041 // Append the returned status code to the end of the response payload.
4042 String s = Integer.toHexString(
4043 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4044 s = IccUtils.bytesToHexString(response.payload) + s;
4045 return s;
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
Evan Charltonc66da362014-05-16 14:06:40 -07004049 }
4050
Jake Hambye994d462014-02-03 13:10:13 -08004051 /**
4052 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4053 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4054 *
4055 * @param itemID the ID of the item to read
4056 * @return the NV item as a String, or null on error.
4057 */
4058 @Override
4059 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4062 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004067 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004068 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4069 return value;
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Jake Hambye994d462014-02-03 13:10:13 -08004073 }
4074
4075 /**
4076 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4077 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4078 *
4079 * @param itemID the ID of the item to read
4080 * @param itemValue the value to write, as a String
4081 * @return true on success; false on any failure
4082 */
4083 @Override
4084 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004085 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4087 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004088
4089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4092 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004093 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004094 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4095 return success;
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
Jake Hambye994d462014-02-03 13:10:13 -08004099 }
4100
4101 /**
4102 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4103 * Used for device configuration by some CDMA operators.
4104 *
4105 * @param preferredRoamingList byte array containing the new PRL
4106 * @return true on success; false on any failure
4107 */
4108 @Override
4109 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4111 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004112
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4116 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4117 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4118 return success;
4119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
Jake Hambye994d462014-02-03 13:10:13 -08004122 }
4123
4124 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004125 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004126 * Used for device configuration by some CDMA operators.
4127 *
chen xu1cc0abe2018-10-26 17:39:23 -07004128 * @param slotIndex - device slot.
4129 *
Jake Hambye994d462014-02-03 13:10:13 -08004130 * @return true on success; false on any failure
4131 */
4132 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004133 public boolean resetModemConfig(int slotIndex) {
4134 Phone phone = PhoneFactory.getPhone(slotIndex);
4135 if (phone != null) {
4136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4137 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004138
chen xu1cc0abe2018-10-26 17:39:23 -07004139 final long identity = Binder.clearCallingIdentity();
4140 try {
4141 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4142 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4143 return success;
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004147 }
chen xu1cc0abe2018-10-26 17:39:23 -07004148 return false;
4149 }
4150
4151 /**
4152 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4153 *
4154 * @param slotIndex - device slot.
4155 *
4156 * @return true on success; false on any failure
4157 */
4158 @Override
4159 public boolean rebootModem(int slotIndex) {
4160 Phone phone = PhoneFactory.getPhone(slotIndex);
4161 if (phone != null) {
4162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4163 mApp, phone.getSubId(), "rebootModem");
4164
4165 final long identity = Binder.clearCallingIdentity();
4166 try {
4167 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4168 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4169 return success;
4170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
4173 }
4174 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004175 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004176
Svet Ganovb320e182015-04-16 12:30:10 -07004177 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004178 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004180 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004181 return new String[0];
4182 }
4183
Malcolm Chend965c8b2018-02-28 15:00:40 -08004184 final long identity = Binder.clearCallingIdentity();
4185 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004186 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004187 } finally {
4188 Binder.restoreCallingIdentity(identity);
4189 }
Wink Saville36469e72014-06-11 15:17:00 -07004190 }
4191
Brad Ebinger51f743a2017-01-23 13:50:20 -08004192 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004193 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4194 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004195 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004196 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004197 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004198
4199 final long identity = Binder.clearCallingIdentity();
4200 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004201 ImsResolver resolver = PhoneFactory.getImsResolver();
4202 if (resolver == null) {
4203 // may happen if the device does not support IMS.
4204 return;
4205 }
4206 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004210 }
4211
4212 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004213 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4214 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004215 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004216 public void disableIms(int slotId) {
4217 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004218
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004221 ImsResolver resolver = PhoneFactory.getImsResolver();
4222 if (resolver == null) {
4223 // may happen if the device does not support IMS.
4224 return;
4225 }
4226 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004230 }
4231
4232 /**
4233 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4234 * feature or {@link null} if the service is not available. If the feature is available, the
4235 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4236 */
4237 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004238 IImsServiceFeatureCallback callback) {
4239 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004240
4241 final long identity = Binder.clearCallingIdentity();
4242 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004243 ImsResolver resolver = PhoneFactory.getImsResolver();
4244 if (resolver == null) {
4245 // may happen if the device does not support IMS.
4246 return null;
4247 }
4248 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004252 }
4253
4254 /**
4255 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4256 * feature during emergency calling or {@link null} if the service is not available. If the
4257 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4258 * listener for feature updates.
4259 */
4260 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4261 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004262
4263 final long identity = Binder.clearCallingIdentity();
4264 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004265 ImsResolver resolver = PhoneFactory.getImsResolver();
4266 if (resolver == null) {
4267 // may happen if the device does not support IMS.
4268 return null;
4269 }
4270 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004274 }
4275
Brad Ebinger5f64b052017-12-14 14:26:15 -08004276 /**
4277 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004278 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004279 */
4280 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4281 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004282
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004285 ImsResolver resolver = PhoneFactory.getImsResolver();
4286 if (resolver == null) {
4287 // may happen if the device does not support IMS.
4288 return null;
4289 }
4290 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004294 }
4295
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004296 /**
4297 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004298 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004299 */
4300 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4301 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004302
4303 final long identity = Binder.clearCallingIdentity();
4304 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004305 ImsResolver resolver = PhoneFactory.getImsResolver();
4306 if (resolver == null) {
4307 // may happen if the device does not support IMS.
4308 return null;
4309 }
4310 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004314 }
4315
Brad Ebinger884c07b2018-02-15 16:17:40 -08004316 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004317 * Sets the ImsService Package Name that Telephony will bind to.
4318 *
4319 * @param slotId the slot ID that the ImsService should bind for.
4320 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4321 * ImsService is the device default ImsService.
4322 * @param packageName The package name of the application that contains the ImsService to bind
4323 * to.
4324 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4325 * @hide
4326 */
4327 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004328 int[] subIds = SubscriptionManager.getSubId(slotId);
4329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4330 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4331 "setImsService");
4332
Malcolm Chend965c8b2018-02-28 15:00:40 -08004333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004335 ImsResolver resolver = PhoneFactory.getImsResolver();
4336 if (resolver == null) {
4337 // may happen if the device does not support IMS.
4338 return false;
4339 }
4340 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4341 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004345 }
4346
4347 /**
4348 * Return the ImsService configuration.
4349 *
4350 * @param slotId The slot that the ImsService is associated with.
4351 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4352 * the device default.
4353 * @return the package name of the ImsService configuration.
4354 */
4355 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004356 int[] subIds = SubscriptionManager.getSubId(slotId);
4357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4358 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4359 "getImsService");
4360
Malcolm Chend965c8b2018-02-28 15:00:40 -08004361 final long identity = Binder.clearCallingIdentity();
4362 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004363 ImsResolver resolver = PhoneFactory.getImsResolver();
4364 if (resolver == null) {
4365 // may happen if the device does not support IMS.
4366 return "";
4367 }
4368 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004369 } finally {
4370 Binder.restoreCallingIdentity(identity);
4371 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004372 }
4373
Wink Saville36469e72014-06-11 15:17:00 -07004374 public void setImsRegistrationState(boolean registered) {
4375 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004376
4377 final long identity = Binder.clearCallingIdentity();
4378 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004379 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Wink Saville36469e72014-06-11 15:17:00 -07004383 }
4384
4385 /**
Stuart Scott54788802015-03-30 13:18:01 -07004386 * Set the network selection mode to automatic.
4387 *
4388 */
4389 @Override
4390 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4392 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004393
Pengquan Meng466e2482018-09-21 15:54:48 -07004394 if (!isActiveSubscription(subId)) {
4395 return;
4396 }
4397
Malcolm Chend965c8b2018-02-28 15:00:40 -08004398 final long identity = Binder.clearCallingIdentity();
4399 try {
4400 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4401 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
Stuart Scott54788802015-03-30 13:18:01 -07004405 }
4406
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004407 /**
4408 * Ask the radio to connect to the input network and change selection mode to manual.
4409 *
4410 * @param subId the id of the subscription.
4411 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4412 * the operator to attach to.
4413 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4414 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4415 * normal network selection next time.
4416 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004417 */
4418 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004419 public boolean setNetworkSelectionModeManual(
4420 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4422 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004423
4424 if (!isActiveSubscription(subId)) {
4425 return false;
4426 }
4427
Malcolm Chend965c8b2018-02-28 15:00:40 -08004428 final long identity = Binder.clearCallingIdentity();
4429 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004430 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004431 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004432 if (DBG) {
4433 log("setNetworkSelectionModeManual: subId: " + subId
4434 + " operator: " + operatorInfo);
4435 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004436 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004440 }
4441
4442 /**
4443 * Scans for available networks.
4444 */
4445 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004446 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4448 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004449 LocationAccessPolicy.LocationPermissionResult locationResult =
4450 LocationAccessPolicy.checkLocationPermission(mApp,
4451 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4452 .setCallingPackage(callingPackage)
4453 .setCallingPid(Binder.getCallingPid())
4454 .setCallingUid(Binder.getCallingUid())
4455 .setMethod("getCellNetworkScanResults")
4456 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4457 .build());
4458 switch (locationResult) {
4459 case DENIED_HARD:
4460 throw new SecurityException("Not allowed to access scan results -- location");
4461 case DENIED_SOFT:
4462 return null;
4463 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004464
Pengquan Meng0c05b502018-09-06 09:59:22 -07004465 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004466 try {
4467 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004468 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004469 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004473 }
4474
4475 /**
yinxub1bed742017-04-17 11:45:04 -07004476 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004477 *
yinxub1bed742017-04-17 11:45:04 -07004478 * @param subId id of the subscription
4479 * @param request contains the radio access networks with bands/channels to scan
4480 * @param messenger callback messenger for scan results or errors
4481 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004482 * @return the id of the requested scan which can be used to stop the scan.
4483 */
4484 @Override
4485 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004486 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4488 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004489 LocationAccessPolicy.LocationPermissionResult locationResult =
4490 LocationAccessPolicy.checkLocationPermission(mApp,
4491 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4492 .setCallingPackage(callingPackage)
4493 .setCallingPid(Binder.getCallingPid())
4494 .setCallingUid(Binder.getCallingUid())
4495 .setMethod("requestNetworkScan")
4496 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4497 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004498 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4499 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4500 if (e != null) {
4501 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4502 throw e;
4503 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004504 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004505 return TelephonyScanManager.INVALID_SCAN_ID;
4506 }
4507 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004508 }
Hall Liubac7d482019-04-25 14:02:26 -07004509 int callingUid = Binder.getCallingUid();
4510 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004511 final long identity = Binder.clearCallingIdentity();
4512 try {
4513 return mNetworkScanRequestTracker.startNetworkScan(
4514 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004515 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
yinxu504e1392017-04-12 16:03:22 -07004519 }
4520
Hall Liub2ac8ef2019-02-28 15:56:23 -08004521 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4522 NetworkScanRequest request) {
4523 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4524 != PERMISSION_GRANTED) {
4525 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4526 + " without location access.");
4527 }
4528
4529 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4530 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004531 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4532 return new SecurityException("Specific channels must not be"
4533 + " scanned without location access.");
4534 }
4535 }
4536 }
4537
Hall Liub2ac8ef2019-02-28 15:56:23 -08004538 return null;
4539 }
4540
yinxu504e1392017-04-12 16:03:22 -07004541 /**
4542 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004543 *
4544 * @param subId id of the subscription
4545 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004546 */
4547 @Override
4548 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4550 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004551
Hall Liubac7d482019-04-25 14:02:26 -07004552 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
Hall Liubac7d482019-04-25 14:02:26 -07004555 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
yinxu504e1392017-04-12 16:03:22 -07004559 }
4560
4561 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004562 * Get the calculated preferred network type.
4563 * Used for debugging incorrect network type.
4564 *
4565 * @return the preferred network type, defined in RILConstants.java.
4566 */
4567 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004568 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004569 final Phone defaultPhone = getDefaultPhone();
4570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4571 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004572 return RILConstants.PREFERRED_NETWORK_MODE;
4573 }
4574
Malcolm Chend965c8b2018-02-28 15:00:40 -08004575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004578 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Junda Liu84d15a22014-07-02 11:21:04 -07004582 }
4583
4584 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004585 * Get the preferred network type.
4586 * Used for device configuration by some CDMA operators.
4587 *
4588 * @return the preferred network type, defined in RILConstants.java.
4589 */
4590 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004591 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004592 TelephonyPermissions
4593 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4594 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004595
4596 final long identity = Binder.clearCallingIdentity();
4597 try {
4598 if (DBG) log("getPreferredNetworkType");
4599 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4600 int networkType = (result != null ? result[0] : -1);
4601 if (DBG) log("getPreferredNetworkType: " + networkType);
4602 return networkType;
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004606 }
4607
4608 /**
4609 * Set the preferred network type.
4610 * Used for device configuration by some CDMA operators.
4611 *
4612 * @param networkType the preferred network type, defined in RILConstants.java.
4613 * @return true on success; false on any failure.
4614 */
4615 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004616 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4618 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004619
4620 final long identity = Binder.clearCallingIdentity();
4621 try {
4622 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4623 Boolean success = (Boolean) sendRequest(
4624 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4625 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4626 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004627 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004628 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4629 }
4630 return success;
4631 } finally {
4632 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004633 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004634 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004635
4636 /**
Miaoa84611c2019-03-15 09:21:10 +08004637 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004638 *
Miaoa84611c2019-03-15 09:21:10 +08004639 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004640 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004641 * @hide
4642 */
4643 @Override
Miaoa84611c2019-03-15 09:21:10 +08004644 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004645 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004646 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004647 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004648 try {
Miaoa84611c2019-03-15 09:21:10 +08004649 if (phone != null) {
4650 return phone.hasMatchedTetherApnSetting();
4651 } else {
4652 return false;
4653 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004654 } finally {
4655 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004656 }
Junda Liu475951f2014-11-07 16:45:03 -08004657 }
4658
4659 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004660 * Set mobile data enabled
4661 * Used by the user through settings etc to turn on/off mobile data
4662 *
4663 * @param enable {@code true} turn turn data on, else {@code false}
4664 */
4665 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004666 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4668 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004669
4670 final long identity = Binder.clearCallingIdentity();
4671 try {
4672 int phoneId = mSubscriptionController.getPhoneId(subId);
4673 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4674 Phone phone = PhoneFactory.getPhone(phoneId);
4675 if (phone != null) {
4676 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004677 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004678 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004679 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004680 }
4681 } finally {
4682 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004683 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004684 }
4685
4686 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004687 * Get the user enabled state of Mobile Data.
4688 *
4689 * TODO: remove and use isUserDataEnabled.
4690 * This can't be removed now because some vendor codes
4691 * calls through ITelephony directly while they should
4692 * use TelephonyManager.
4693 *
4694 * @return true on enabled
4695 */
4696 @Override
4697 public boolean getDataEnabled(int subId) {
4698 return isUserDataEnabled(subId);
4699 }
4700
4701 /**
4702 * Get whether mobile data is enabled per user setting.
4703 *
4704 * There are other factors deciding whether mobile data is actually enabled, but they are
4705 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004706 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004707 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004708 *
4709 * @return {@code true} if data is enabled else {@code false}
4710 */
4711 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004712 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004713 try {
4714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4715 null);
4716 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4718 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004719 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004720
4721 final long identity = Binder.clearCallingIdentity();
4722 try {
4723 int phoneId = mSubscriptionController.getPhoneId(subId);
4724 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4725 Phone phone = PhoneFactory.getPhone(phoneId);
4726 if (phone != null) {
4727 boolean retVal = phone.isUserDataEnabled();
4728 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4729 return retVal;
4730 } else {
4731 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4732 return false;
4733 }
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004736 }
4737 }
4738
4739 /**
4740 * Get whether mobile data is enabled.
4741 *
4742 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4743 * whether mobile data is actually enabled.
4744 *
4745 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4746 *
4747 * @return {@code true} if data is enabled else {@code false}
4748 */
4749 @Override
4750 public boolean isDataEnabled(int subId) {
4751 try {
4752 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4753 null);
4754 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4756 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004757 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004758
4759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 int phoneId = mSubscriptionController.getPhoneId(subId);
4762 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4763 Phone phone = PhoneFactory.getPhone(phoneId);
4764 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004765 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004766 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4767 return retVal;
4768 } else {
4769 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4770 return false;
4771 }
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004774 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004775 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004776
4777 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004778 public int getCarrierPrivilegeStatus(int subId) {
4779 final Phone phone = getPhone(subId);
4780 if (phone == null) {
4781 loge("getCarrierPrivilegeStatus: Invalid subId");
4782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4783 }
4784 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004785 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004786 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4788 }
4789 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004790 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004791 }
Junda Liu29340342014-07-10 15:23:27 -07004792
4793 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004794 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4795 final Phone phone = getPhone(subId);
4796 if (phone == null) {
4797 loge("getCarrierPrivilegeStatus: Invalid subId");
4798 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4799 }
4800 UiccProfile profile =
4801 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4802 if (profile == null) {
4803 loge("getCarrierPrivilegeStatus: No UICC");
4804 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4805 }
4806 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4807 }
4808
4809 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004810 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004811 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004812 if (TextUtils.isEmpty(pkgName))
4813 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004814 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004815 if (card == null) {
4816 loge("checkCarrierPrivilegesForPackage: No UICC");
4817 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4818 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004819 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4820 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004821 }
4822
4823 @Override
4824 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004825 if (TextUtils.isEmpty(pkgName))
4826 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004827 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4828 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4829 UiccCard card = UiccController.getInstance().getUiccCard(i);
4830 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004831 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004832 continue;
4833 }
4834
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004835 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004836 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4837 break;
4838 }
4839 }
4840
4841 return result;
Junda Liu29340342014-07-10 15:23:27 -07004842 }
Derek Tan89e89d42014-07-08 17:00:10 -07004843
4844 @Override
Junda Liue64de782015-04-16 17:19:16 -07004845 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4846 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4847 loge("phoneId " + phoneId + " is not valid.");
4848 return null;
4849 }
4850 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004851 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004852 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004853 return null ;
4854 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004855 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004856 }
4857
Amith Yamasani6e118872016-02-19 12:53:51 -08004858 @Override
4859 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004860 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004861 List<String> privilegedPackages = new ArrayList<>();
4862 List<PackageInfo> packages = null;
4863 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4864 UiccCard card = UiccController.getInstance().getUiccCard(i);
4865 if (card == null) {
4866 // No UICC in that slot.
4867 continue;
4868 }
4869 if (card.hasCarrierPrivilegeRules()) {
4870 if (packages == null) {
4871 // Only check packages in user 0 for now
4872 packages = pm.getInstalledPackagesAsUser(
4873 PackageManager.MATCH_DISABLED_COMPONENTS
4874 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4875 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4876 }
4877 for (int p = packages.size() - 1; p >= 0; p--) {
4878 PackageInfo pkgInfo = packages.get(p);
4879 if (pkgInfo != null && pkgInfo.packageName != null
4880 && card.getCarrierPrivilegeStatus(pkgInfo)
4881 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4882 privilegedPackages.add(pkgInfo.packageName);
4883 }
4884 }
4885 }
4886 }
4887 return privilegedPackages;
4888 }
4889
Wink Savilleb564aae2014-10-23 10:18:09 -07004890 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004891 final Phone phone = getPhone(subId);
4892 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004893 if (card == null) {
4894 loge("getIccId: No UICC");
4895 return null;
4896 }
4897 String iccId = card.getIccId();
4898 if (TextUtils.isEmpty(iccId)) {
4899 loge("getIccId: ICC ID is null or empty.");
4900 return null;
4901 }
4902 return iccId;
4903 }
4904
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004905 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004906 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4907 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004908 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4909 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004910
Malcolm Chend965c8b2018-02-28 15:00:40 -08004911 final long identity = Binder.clearCallingIdentity();
4912 try {
4913 final String iccId = getIccId(subId);
4914 final Phone phone = getPhone(subId);
4915 if (phone == null) {
4916 return false;
4917 }
4918 final String subscriberId = phone.getSubscriberId();
4919
4920 if (DBG_MERGE) {
4921 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4922 + subscriberId + " to " + number);
4923 }
4924
4925 if (TextUtils.isEmpty(iccId)) {
4926 return false;
4927 }
4928
4929 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4930
4931 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4932 if (alphaTag == null) {
4933 editor.remove(alphaTagPrefKey);
4934 } else {
4935 editor.putString(alphaTagPrefKey, alphaTag);
4936 }
4937
4938 // Record both the line number and IMSI for this ICCID, since we need to
4939 // track all merged IMSIs based on line number
4940 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4941 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4942 if (number == null) {
4943 editor.remove(numberPrefKey);
4944 editor.remove(subscriberPrefKey);
4945 } else {
4946 editor.putString(numberPrefKey, number);
4947 editor.putString(subscriberPrefKey, subscriberId);
4948 }
4949
4950 editor.commit();
4951 return true;
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004954 }
Derek Tan7226c842014-07-02 17:42:23 -07004955 }
4956
4957 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004958 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004959 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004961 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004962 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004963 return null;
4964 }
Derek Tan97ebb422014-09-05 16:55:38 -07004965
Malcolm Chend965c8b2018-02-28 15:00:40 -08004966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 String iccId = getIccId(subId);
4969 if (iccId != null) {
4970 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4971 if (DBG_MERGE) {
4972 log("getLine1NumberForDisplay returning "
4973 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4974 }
4975 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004976 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004977 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4978 return null;
4979 } finally {
4980 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004981 }
Derek Tan7226c842014-07-02 17:42:23 -07004982 }
4983
4984 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004985 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004987 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004988 return null;
4989 }
Derek Tan97ebb422014-09-05 16:55:38 -07004990
Malcolm Chend965c8b2018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 String iccId = getIccId(subId);
4994 if (iccId != null) {
4995 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4996 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4997 }
4998 return null;
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005001 }
Derek Tan7226c842014-07-02 17:42:23 -07005002 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005003
5004 @Override
Jordan Liu9775d4b2019-05-06 14:45:15 -07005005 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005006 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5007 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005009 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5010 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005011 return null;
5012 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005013
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005014 final long identity = Binder.clearCallingIdentity();
5015 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005016 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005017 final TelephonyManager tele = TelephonyManager.from(context);
5018 final SubscriptionManager sub = SubscriptionManager.from(context);
5019
5020 // Figure out what subscribers are currently active
5021 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
5022 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5023 // the process, where TelephonyManager was instantiated.
5024 // Otherwise AppOps check will fail.
5025
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005026 final int[] subIds = sub.getActiveSubscriptionIdList();
Jordan Liu9775d4b2019-05-06 14:45:15 -07005027 for (int id : subIds) {
5028 // Only consider subs which match the current subId
5029 // This logic can be simplified. See b/131189269 for progress.
5030 if (subId != id) {
5031 continue;
5032 }
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005033 activeSubscriberIds.add(tele.getSubscriberId(subId));
5034 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005035
5036 // First pass, find a number override for an active subscriber
5037 String mergeNumber = null;
5038 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5039 for (String key : prefs.keySet()) {
5040 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5041 final String subscriberId = (String) prefs.get(key);
5042 if (activeSubscriberIds.contains(subscriberId)) {
5043 final String iccId = key.substring(
5044 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5045 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5046 mergeNumber = (String) prefs.get(numberKey);
5047 if (DBG_MERGE) {
5048 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5049 + " for active subscriber " + subscriberId);
5050 }
5051 if (!TextUtils.isEmpty(mergeNumber)) {
5052 break;
5053 }
5054 }
5055 }
5056 }
5057
5058 // Shortcut when no active merged subscribers
5059 if (TextUtils.isEmpty(mergeNumber)) {
5060 return null;
5061 }
5062
5063 // Second pass, find all subscribers under that line override
5064 final ArraySet<String> result = new ArraySet<>();
5065 for (String key : prefs.keySet()) {
5066 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5067 final String number = (String) prefs.get(key);
5068 if (mergeNumber.equals(number)) {
5069 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5070 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5071 final String subscriberId = (String) prefs.get(subscriberKey);
5072 if (!TextUtils.isEmpty(subscriberId)) {
5073 result.add(subscriberId);
5074 }
5075 }
5076 }
5077 }
5078
5079 final String[] resultArray = result.toArray(new String[result.size()]);
5080 Arrays.sort(resultArray);
5081 if (DBG_MERGE) {
5082 Slog.d(LOG_TAG,
5083 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5084 }
5085 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005086 } finally {
5087 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005088 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005089 }
5090
5091 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005092 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005093 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5094 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005095
5096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 final Phone phone = getPhone(subId);
5099 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005103 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005104
5105 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005106 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005107 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5108 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005110
5111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 final Phone phone = getPhone(subId);
5114 if (phone == null) {
5115 return false;
5116 }
5117 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5118 cdmaNonRoamingList);
5119 } finally {
5120 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005121 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005122 }
5123
5124 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005125 @Deprecated
5126 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5127 enforceModifyPermission();
5128
5129 int returnValue = 0;
5130 try {
vagdevie435a3e2018-08-15 16:01:53 -07005131 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005132 if(result.exception == null) {
5133 if (result.result != null) {
5134 byte[] responseData = (byte[])(result.result);
5135 if(responseData.length > oemResp.length) {
5136 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5137 responseData.length + "bytes. Buffer Size is " +
5138 oemResp.length + "bytes.");
5139 }
5140 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5141 returnValue = responseData.length;
5142 }
5143 } else {
5144 CommandException ex = (CommandException) result.exception;
5145 returnValue = ex.getCommandError().ordinal();
5146 if(returnValue > 0) returnValue *= -1;
5147 }
5148 } catch (RuntimeException e) {
5149 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5150 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5151 if(returnValue > 0) returnValue *= -1;
5152 }
5153
5154 return returnValue;
5155 }
5156
5157 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005158 public void setRadioCapability(RadioAccessFamily[] rafs) {
5159 try {
5160 ProxyController.getInstance().setRadioCapability(rafs);
5161 } catch (RuntimeException e) {
5162 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5163 }
5164 }
5165
5166 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005167 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005168 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005169 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005170 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005171 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005172 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005173 final long identity = Binder.clearCallingIdentity();
5174 try {
chen xufeeed752018-10-26 14:17:57 -07005175 TelephonyPermissions
5176 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5177 mApp, phone.getSubId(), "getRadioAccessFamily");
5178 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
chen xufeeed752018-10-26 14:17:57 -07005182 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005183 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005184
5185 @Override
5186 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005187 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005188 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005189
5190 final long identity = Binder.clearCallingIdentity();
5191 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005192 ImsManager.getInstance(defaultPhone.getContext(),
5193 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005197 }
5198
5199 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005200 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005201 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005203 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005204 return false;
5205 }
Svet Ganovb320e182015-04-16 12:30:10 -07005206
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207 final long identity = Binder.clearCallingIdentity();
5208 try {
5209 // Check the user preference and the system-level IMS setting. Even if the user has
5210 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5211 // In the long run, we may instead need to check if there exists a connection service
5212 // which can support video calling.
5213 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005214 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005215 return imsManager.isVtEnabledByPlatform()
5216 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5217 && imsManager.isVtEnabledByUser();
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005221 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005222
Andrew Leea1239f22015-03-02 17:44:07 -08005223 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005224 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5226 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5227 return false;
5228 }
5229
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 CarrierConfigManager configManager =
5233 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005234 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005235 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Andrew Leea1239f22015-03-02 17:44:07 -08005239 }
5240
5241 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005242 public boolean isWorldPhone(int subId, String callingPackage) {
5243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5244 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5245 return false;
5246 }
5247
5248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 CarrierConfigManager configManager =
5251 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005252 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005253 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
Andrew Leea1239f22015-03-02 17:44:07 -08005257 }
5258
Andrew Lee9431b832015-03-09 18:46:45 -07005259 @Override
5260 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005261 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005262 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005263 }
5264
5265 @Override
5266 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005267 final long identity = Binder.clearCallingIdentity();
5268 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005269 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
Andrew Lee9431b832015-03-09 18:46:45 -07005273 }
5274
Hall Liuf6668912018-10-31 17:05:23 -07005275 /**
5276 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5277 * support for the feature and device firmware support.
5278 *
5279 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5280 */
5281 @Override
5282 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005284 final Phone phone = getPhone(subscriptionId);
5285 if (phone == null) {
5286 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5287 return false;
5288 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005289 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005290 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005291 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5292 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005293 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005294 return isCarrierSupported && isDeviceSupported;
5295 } finally {
5296 Binder.restoreCallingIdentity(identity);
5297 }
Hall Liu98187582018-01-22 19:15:32 -08005298 }
5299
Hall Liuf6668912018-10-31 17:05:23 -07005300 /**
5301 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5302 * both also support RTT.
5303 */
5304 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005305 final long identity = Binder.clearCallingIdentity();
5306 try {
Hall Liuf6668912018-10-31 17:05:23 -07005307 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005308 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005312 }
5313
Sanket Padawe7310cc72015-01-14 09:53:20 -08005314 /**
5315 * Returns the unique device ID of phone, for example, the IMEI for
5316 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5317 *
5318 * <p>Requires Permission:
5319 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5320 */
5321 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005322 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005323 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005324 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005325 return null;
5326 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005327 int subId = phone.getSubId();
5328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5329 mApp, subId, callingPackage, "getDeviceId")) {
5330 return null;
5331 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005332
5333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 return phone.getDeviceId();
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005339 }
5340
Ping Sunc67b7c22016-03-02 19:16:45 +08005341 /**
5342 * {@hide}
5343 * Returns the IMS Registration Status on a particular subid
5344 *
5345 * @param subId
5346 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005347 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005348 Phone phone = getPhone(subId);
5349 if (phone != null) {
5350 return phone.isImsRegistered();
5351 } else {
5352 return false;
5353 }
5354 }
5355
Santos Cordon7a1885b2015-02-03 11:15:19 -08005356 @Override
5357 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
5360 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5361 } finally {
5362 Binder.restoreCallingIdentity(identity);
5363 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005364 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005365
Tyler Gunn327a9722019-04-03 15:28:53 -07005366 @Override
5367 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5368 final long identity = Binder.clearCallingIdentity();
5369 try {
5370 Phone phone = getPhone(subscriptionId);
5371 if (phone == null) {
5372 return null;
5373 }
5374 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
5377 }
5378 }
5379
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005380 /**
5381 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005382 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005383 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
5386 Phone phone = getPhone(subId);
5387 if (phone != null) {
5388 return phone.isWifiCallingEnabled();
5389 } else {
5390 return false;
5391 }
5392 } finally {
5393 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005394 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005395 }
5396
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005397 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005398 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005399 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005400 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 Phone phone = getPhone(subId);
5404 if (phone != null) {
5405 return phone.isVideoEnabled();
5406 } else {
5407 return false;
5408 }
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005411 }
5412 }
5413
5414 /**
5415 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5416 * defined in {@link ImsRegistrationImplBase}.
5417 */
5418 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 Phone phone = getPhone(subId);
5422 if (phone != null) {
5423 return phone.getImsRegistrationTech();
5424 } else {
5425 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5426 }
5427 } finally {
5428 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005429 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005430 }
5431
Stuart Scott8eef64f2015-04-08 15:13:54 -07005432 @Override
5433 public void factoryReset(int subId) {
5434 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005435 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5436 return;
5437 }
5438
Svet Ganovcc087f82015-05-12 20:35:54 -07005439 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005440
Svet Ganovcc087f82015-05-12 20:35:54 -07005441 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005442 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5443 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005444 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005445 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005446 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005447 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5448 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005449 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005450 // There has been issues when Sms raw table somehow stores orphan
5451 // fragments. They lead to garbled message when new fragments come
5452 // in and combined with those stale ones. In case this happens again,
5453 // user can reset all network settings which will clean up this table.
5454 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005455 } finally {
5456 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005457 }
5458 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005459
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005460 private void cleanUpSmsRawTable(Context context) {
5461 ContentResolver resolver = context.getContentResolver();
5462 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5463 resolver.delete(uri, null, null);
5464 }
5465
Narayan Kamath1c496c22015-04-16 14:40:19 +01005466 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005467 public String getSimLocaleForSubscriber(int subId) {
5468 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5469 final Phone phone = getPhone(subId);
5470 if (phone == null) {
5471 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005472 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005473 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005474 final long identity = Binder.clearCallingIdentity();
5475 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005476 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5477 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005478 // Try and fetch the locale from the carrier properties or from the SIM language
5479 // preferences (EF-PL and EF-LI)...
5480 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005481 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005482 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5483 if (localeFromDefaultSim != null) {
5484 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5485 if (DBG) log("Using locale from subId: " + subId + " locale: "
5486 + localeFromDefaultSim);
5487 return localeFromDefaultSim.toLanguageTag();
5488 } else {
5489 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005490 }
5491 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005492
Malcolm Chend965c8b2018-02-28 15:00:40 -08005493 // The SIM language preferences only store a language (e.g. fr = French), not an
5494 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5495 // the SIM and carrier preferences does not include a country we add the country
5496 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005497 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005498 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005499 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005500 return mccLocale.toLanguageTag();
5501 }
5502
5503 if (DBG) log("No locale found - returning null");
5504 return null;
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005508 }
5509
5510 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005511 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005512 }
5513
Malcolm Chend965c8b2018-02-28 15:00:40 -08005514 /**
5515 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5516 */
5517 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005518 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005519 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005520
Chenjie Yu1ba97252018-01-11 18:16:20 -08005521 private final ModemActivityInfo mLastModemActivityInfo =
5522 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5523
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005524 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005525 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5526 * representing the state of the modem.
5527 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005528 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5529 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005530 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005531 */
5532 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005533 public void requestModemActivityInfo(ResultReceiver result) {
5534 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005535 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 ModemActivityInfo ret = null;
5540 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005541 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5542 CMD_GET_MODEM_ACTIVITY_INFO,
5543 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005544 if (isModemActivityInfoValid(info)) {
5545 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5546 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5547 mergedTxTimeMs[i] =
5548 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5549 }
5550 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5551 mLastModemActivityInfo.setSleepTimeMillis(
5552 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5553 mLastModemActivityInfo.setIdleTimeMillis(
5554 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5555 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5556 mLastModemActivityInfo.setRxTimeMillis(
5557 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5558 mLastModemActivityInfo.setEnergyUsed(
5559 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005560 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005561 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5562 mLastModemActivityInfo.getSleepTimeMillis(),
5563 mLastModemActivityInfo.getIdleTimeMillis(),
5564 mLastModemActivityInfo.getTxTimeMillis(),
5565 mLastModemActivityInfo.getRxTimeMillis(),
5566 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005567 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005568 Bundle bundle = new Bundle();
5569 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5570 result.send(0, bundle);
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005573 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005574 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005575
Siddharth Rayf5d29552018-06-17 15:02:38 -07005576 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5577 // less than total activity duration.
5578 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5579 if (info == null) {
5580 return false;
5581 }
5582 int activityDurationMs =
5583 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5584 int totalTxTimeMs = 0;
5585 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5586 totalTxTimeMs += info.getTxTimeMillis()[i];
5587 }
5588 return (info.isValid()
5589 && (info.getSleepTimeMillis() <= activityDurationMs)
5590 && (info.getIdleTimeMillis() <= activityDurationMs)
5591 && (info.getRxTimeMillis() <= activityDurationMs)
5592 && (totalTxTimeMs <= activityDurationMs));
5593 }
5594
Jack Yu85bd38a2015-11-09 11:34:32 -08005595 /**
5596 * {@hide}
5597 * Returns the service state information on specified subscription.
5598 */
5599 @Override
5600 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005602 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005603 return null;
5604 }
5605
Hall Liuf19c44f2018-11-27 14:38:17 -08005606 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5607 LocationAccessPolicy.checkLocationPermission(mApp,
5608 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5609 .setCallingPackage(callingPackage)
5610 .setCallingPid(Binder.getCallingPid())
5611 .setCallingUid(Binder.getCallingUid())
5612 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005613 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005614 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5615 .build());
5616
5617 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5618 LocationAccessPolicy.checkLocationPermission(mApp,
5619 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5620 .setCallingPackage(callingPackage)
5621 .setCallingPid(Binder.getCallingPid())
5622 .setCallingUid(Binder.getCallingUid())
5623 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005624 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005625 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5626 .build());
5627 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5628 boolean hasFinePermission =
5629 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5630 boolean hasCoarsePermission =
5631 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5632
Malcolm Chend965c8b2018-02-28 15:00:40 -08005633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 final Phone phone = getPhone(subId);
5636 if (phone == null) {
5637 return null;
5638 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005639
Hall Liuf19c44f2018-11-27 14:38:17 -08005640 ServiceState ss = phone.getServiceState();
5641
5642 // Scrub out the location info in ServiceState depending on what level of access
5643 // the caller has.
5644 if (hasFinePermission) return ss;
5645 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5646 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005650 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005651
5652 /**
5653 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5654 *
5655 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5656 * voicemail ringtone.
5657 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5658 * PhoneAccount.
5659 */
5660 @Override
5661 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5665 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005666 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005667 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005668
Malcolm Chend965c8b2018-02-28 15:00:40 -08005669 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
5672 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005673 }
5674
5675 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005676 * Sets the per-account voicemail ringtone.
5677 *
5678 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5679 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5680 *
5681 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5682 * voicemail ringtone.
5683 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5684 * PhoneAccount.
5685 */
5686 @Override
5687 public void setVoicemailRingtoneUri(String callingPackage,
5688 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005689 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5691 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005692 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5695 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005696 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005697
5698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5701 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005702 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005703 }
5704 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005707 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005708 }
5709
5710 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005711 * Returns whether vibration is set for voicemail notification in Phone settings.
5712 *
5713 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5714 * voicemail vibration setting.
5715 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5716 */
5717 @Override
5718 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5722 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005723 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005724 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005725
Malcolm Chend965c8b2018-02-28 15:00:40 -08005726 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005730 }
5731
Youhan Wange64578a2016-05-02 15:32:42 -07005732 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005733 * Sets the per-account voicemail vibration.
5734 *
5735 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5736 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5737 *
5738 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5739 * voicemail vibration setting.
5740 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5741 * specific PhoneAccount.
5742 */
5743 @Override
5744 public void setVoicemailVibrationEnabled(String callingPackage,
5745 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005746 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005747 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5748 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005749 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5751 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5752 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005753 }
5754
Malcolm Chend965c8b2018-02-28 15:00:40 -08005755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5758 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005759 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005760 }
5761 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005764 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005765 }
5766
5767 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005768 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5769 *
5770 * @throws SecurityException if the caller does not have the required permission
5771 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005772 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005773 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005774 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005775 }
5776
5777 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005778 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5779 * permission.
5780 *
5781 * @throws SecurityException if the caller does not have the required permission
5782 */
5783 private void enforceSendSmsPermission() {
5784 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5785 }
5786
5787 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005788 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005789 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005790 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005791 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005792 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005796 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005797 if (componentName == null) {
5798 throw new SecurityException(
5799 "Caller not current active visual voicemail package[null]");
5800 }
5801 String vvmPackage = componentName.getPackageName();
5802 if (!callingPackage.equals(vvmPackage)) {
5803 throw new SecurityException("Caller not current active visual voicemail package["
5804 + vvmPackage + "]");
5805 }
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005808 }
5809 }
5810
5811 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005812 * Return the application ID for the app type.
5813 *
5814 * @param subId the subscription ID that this request applies to.
5815 * @param appType the uicc app type.
5816 * @return Application ID for specificied app type, or null if no uicc.
5817 */
5818 @Override
5819 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005820 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005821 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005822
5823 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005824 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005825 if (phone == null) {
5826 return null;
5827 }
5828 String aid = null;
5829 try {
5830 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5831 .getApplicationByType(appType).getAid();
5832 } catch (Exception e) {
5833 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5834 }
5835 return aid;
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005838 }
Youhan Wange64578a2016-05-02 15:32:42 -07005839 }
5840
Youhan Wang4001d252016-05-11 10:29:41 -07005841 /**
5842 * Return the Electronic Serial Number.
5843 *
5844 * @param subId the subscription ID that this request applies to.
5845 * @return ESN or null if error.
5846 */
5847 @Override
5848 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005849 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005850 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005851
5852 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005853 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005854 if (phone == null) {
5855 return null;
5856 }
5857 String esn = null;
5858 try {
5859 esn = phone.getEsn();
5860 } catch (Exception e) {
5861 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5862 }
5863 return esn;
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005866 }
Youhan Wang4001d252016-05-11 10:29:41 -07005867 }
5868
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005869 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005870 * Return the Preferred Roaming List Version.
5871 *
5872 * @param subId the subscription ID that this request applies to.
5873 * @return PRLVersion or null if error.
5874 */
5875 @Override
5876 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005877 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005878 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005881 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005882 if (phone == null) {
5883 return null;
5884 }
5885 String cdmaPrlVersion = null;
5886 try {
5887 cdmaPrlVersion = phone.getCdmaPrlVersion();
5888 } catch (Exception e) {
5889 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5890 }
5891 return cdmaPrlVersion;
5892 } finally {
5893 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005894 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005895 }
5896
5897 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005898 * Get snapshot of Telephony histograms
5899 * @return List of Telephony histograms
5900 * @hide
5901 */
5902 @Override
5903 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5905 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005906
5907 final long identity = Binder.clearCallingIdentity();
5908 try {
5909 return RIL.getTelephonyRILTimingHistograms();
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005913 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005914
5915 /**
5916 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005917 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5918 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005919 * Require system privileges. In the future we may add this to carrier APIs.
5920 *
Michele Berionne0963c862018-11-27 18:57:59 -08005921 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005922 */
5923 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005924 @TelephonyManager.SetCarrierRestrictionResult
5925 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005926 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005927 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005928
Michele Berionne0963c862018-11-27 18:57:59 -08005929 if (carrierRestrictionRules == null) {
5930 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005931 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005932
Malcolm Chend965c8b2018-02-28 15:00:40 -08005933 final long identity = Binder.clearCallingIdentity();
5934 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005935 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005936 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005940 }
5941
5942 /**
5943 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005944 * Get the allowed carrier list and the excluded carrier list, including the priority between
5945 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005946 * Require system privileges. In the future we may add this to carrier APIs.
5947 *
Michele Berionne0963c862018-11-27 18:57:59 -08005948 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005949 */
5950 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005951 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005952 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005953 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005954
5955 final long identity = Binder.clearCallingIdentity();
5956 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005957 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5958 if (response instanceof CarrierRestrictionRules) {
5959 return (CarrierRestrictionRules) response;
5960 }
5961 // Response is an Exception of some kind,
5962 // which is signalled to the user as a NULL retval
5963 return null;
5964 } catch (Exception e) {
5965 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5966 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005970 }
5971
fionaxu59545b42016-05-25 15:53:37 -07005972 /**
5973 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5974 * @param subId the subscription ID that this action applies to.
5975 * @param enabled control enable or disable metered apns.
5976 * {@hide}
5977 */
5978 @Override
5979 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5980 enforceModifyPermission();
5981 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005982
5983 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005984 if (phone == null) {
5985 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5986 return;
5987 }
5988 try {
5989 phone.carrierActionSetMeteredApnsEnabled(enabled);
5990 } catch (Exception e) {
5991 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005992 } finally {
5993 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005994 }
5995 }
5996
5997 /**
5998 * Action set from carrier signalling broadcast receivers to enable/disable radio
5999 * @param subId the subscription ID that this action applies to.
6000 * @param enabled control enable or disable radio.
6001 * {@hide}
6002 */
6003 @Override
6004 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6005 enforceModifyPermission();
6006 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006007
6008 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006009 if (phone == null) {
6010 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6011 return;
6012 }
6013 try {
6014 phone.carrierActionSetRadioEnabled(enabled);
6015 } catch (Exception e) {
6016 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006019 }
6020 }
6021
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006022 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006023 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6024 * network status based on which carrier apps could apply actions accordingly,
6025 * enable/disable default url handler for example.
6026 *
6027 * @param subId the subscription ID that this action applies to.
6028 * @param report control start/stop reporting the default network status.
6029 * {@hide}
6030 */
6031 @Override
6032 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6033 enforceModifyPermission();
6034 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006035
6036 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006037 if (phone == null) {
6038 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6039 return;
6040 }
6041 try {
6042 phone.carrierActionReportDefaultNetworkStatus(report);
6043 } catch (Exception e) {
6044 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006047 }
6048 }
6049
6050 /**
fionaxud9622282017-07-17 17:51:30 -07006051 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6052 * @param subId the subscription ID that this action applies to.
6053 * {@hide}
6054 */
6055 @Override
6056 public void carrierActionResetAll(int subId) {
6057 enforceModifyPermission();
6058 final Phone phone = getPhone(subId);
6059 if (phone == null) {
6060 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6061 return;
6062 }
6063 try {
6064 phone.carrierActionResetAll();
6065 } catch (Exception e) {
6066 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6067 }
6068 }
6069
6070 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006071 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6072 * bug report is being generated.
6073 */
6074 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006075 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006076 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6077 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006078 writer.println("Permission Denial: can't dump Phone from pid="
6079 + Binder.getCallingPid()
6080 + ", uid=" + Binder.getCallingUid()
6081 + "without permission "
6082 + android.Manifest.permission.DUMP);
6083 return;
6084 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006085 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006086 }
Jack Yueb89b242016-06-22 13:27:47 -07006087
Brad Ebingerdac2f002018-04-03 15:17:52 -07006088 @Override
6089 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6090 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6091 throws RemoteException {
6092 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6093 }
6094
Jack Yueb89b242016-06-22 13:27:47 -07006095 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006096 * Get aggregated video call data usage since boot.
6097 *
6098 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6099 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006100 * {@hide}
6101 */
6102 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006103 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006104 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6105 null);
6106
Malcolm Chend965c8b2018-02-28 15:00:40 -08006107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 // NetworkStatsService keeps tracking the active network interface and identity. It
6110 // records the delta with the corresponding network identity.
6111 // We just return the total video call data usage snapshot since boot.
6112 Phone phone = getPhone(subId);
6113 if (phone != null) {
6114 return phone.getVtDataUsage(perUidStats);
6115 }
6116 return null;
6117 } finally {
6118 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006119 }
Jack Yueb89b242016-06-22 13:27:47 -07006120 }
Jack Yu75ab2952016-07-08 14:29:33 -07006121
6122 /**
6123 * Policy control of data connection. Usually used when data limit is passed.
6124 * @param enabled True if enabling the data, otherwise disabling.
6125 * @param subId Subscription index
6126 * {@hide}
6127 */
6128 @Override
6129 public void setPolicyDataEnabled(boolean enabled, int subId) {
6130 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006131
6132 final long identity = Binder.clearCallingIdentity();
6133 try {
6134 Phone phone = getPhone(subId);
6135 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006136 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006137 }
6138 } finally {
6139 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006140 }
6141 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006142
6143 /**
6144 * Get Client request stats
6145 * @return List of Client Request Stats
6146 * @hide
6147 */
6148 @Override
6149 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006151 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006152 return null;
6153 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006154 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006155
Malcolm Chend965c8b2018-02-28 15:00:40 -08006156 final long identity = Binder.clearCallingIdentity();
6157 try {
6158 if (phone != null) {
6159 return phone.getClientRequestStats();
6160 }
6161
6162 return null;
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006166 }
6167
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006168 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006169 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006170 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006171 }
Jack Yueb4124c2017-02-16 15:32:43 -08006172
6173 /**
Grace Chen70990072017-03-24 17:21:30 -07006174 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006175 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006176 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006177 * @param state State of SIM (power down, power up, pass through)
6178 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6179 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6180 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006181 *
6182 **/
6183 @Override
Grace Chen70990072017-03-24 17:21:30 -07006184 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006185 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006186 Phone phone = PhoneFactory.getPhone(slotIndex);
6187
vagdevie435a3e2018-08-15 16:01:53 -07006188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6189
Malcolm Chend965c8b2018-02-28 15:00:40 -08006190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006193 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006194 }
6195 } finally {
6196 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006197 }
6198 }
Shuo Qiandd210312017-04-12 22:11:33 +00006199
Tyler Gunn65d45c22017-06-05 11:22:26 -07006200 private boolean isUssdApiAllowed(int subId) {
6201 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006202 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006203 if (configManager == null) {
6204 return false;
6205 }
6206 PersistableBundle pb = configManager.getConfigForSubId(subId);
6207 if (pb == null) {
6208 return false;
6209 }
6210 return pb.getBoolean(
6211 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6212 }
6213
Shuo Qiandd210312017-04-12 22:11:33 +00006214 /**
6215 * Check if phone is in emergency callback mode
6216 * @return true if phone is in emergency callback mode
6217 * @param subId sub id
6218 */
goneil9c5f4872017-12-05 14:07:56 -08006219 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006220 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006221 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006222 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006223
6224 final long identity = Binder.clearCallingIdentity();
6225 try {
6226 if (phone != null) {
6227 return phone.isInEcm();
6228 } else {
6229 return false;
6230 }
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006233 }
6234 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006235
6236 /**
6237 * Get the current signal strength information for the given subscription.
6238 * Because this information is not updated when the device is in a low power state
6239 * it should not be relied-upon to be current.
6240 * @param subId Subscription index
6241 * @return the most recent cached signal strength info from the modem
6242 */
6243 @Override
6244 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006245 final long identity = Binder.clearCallingIdentity();
6246 try {
6247 Phone p = getPhone(subId);
6248 if (p == null) {
6249 return null;
6250 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006251
Malcolm Chend965c8b2018-02-28 15:00:40 -08006252 return p.getSignalStrength();
6253 } finally {
6254 Binder.restoreCallingIdentity(identity);
6255 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006256 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006257
Pengquan Meng9140aec2018-08-22 14:49:57 -07006258 /**
chen xu907e5a22018-10-11 13:21:04 -07006259 * Get the current modem radio state for the given slot.
6260 * @param slotIndex slot index.
6261 * @param callingPackage the name of the package making the call.
6262 * @return the current radio power state from the modem
6263 */
6264 @Override
6265 public int getRadioPowerState(int slotIndex, String callingPackage) {
6266 Phone phone = PhoneFactory.getPhone(slotIndex);
6267 if (phone != null) {
6268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6269 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6270 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6271 }
6272
6273 final long identity = Binder.clearCallingIdentity();
6274 try {
6275 return phone.getRadioPowerState();
6276 } finally {
6277 Binder.restoreCallingIdentity(identity);
6278 }
6279 }
6280 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6281 }
6282
6283 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006284 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6285 *
6286 * <p>Requires one of the following permissions:
6287 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6288 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6289 * privileges.
6290 *
6291 * @param subId subscription id
6292 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6293 * {@code false}.
6294 */
6295 @Override
6296 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006297 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6298 null /* message */);
6299
Pengquan Meng0c05b502018-09-06 09:59:22 -07006300 boolean isEnabled = false;
6301 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006302 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006303 Phone phone = getPhone(subId);
6304 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006305 } catch (Exception e) {
6306 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6307 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006308 } finally {
6309 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006310 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006311 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006312 }
6313
6314
6315 /**
6316 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6317 *
6318 * <p> Requires permission:
6319 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6320 * privileges.
6321 *
6322 * @param subId subscription id
6323 * @param isEnabled {@code true} means enable, {@code false} means disable.
6324 */
6325 @Override
6326 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6328 mApp, subId, "setDataRoamingEnabled");
6329
Pengquan Meng0c05b502018-09-06 09:59:22 -07006330 final long identity = Binder.clearCallingIdentity();
6331 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006332 Phone phone = getPhone(subId);
6333 if (phone != null) {
6334 phone.setDataRoamingEnabled(isEnabled);
6335 }
6336 } finally {
6337 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006338 }
6339 }
6340
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006341 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006342 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006343 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6344 mApp, subId, "isManualNetworkSelectionAllowed");
6345
Pengquan Meng312de0c2018-10-03 12:19:13 -07006346 boolean isAllowed = true;
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006349 Phone phone = getPhone(subId);
6350 if (phone != null) {
6351 isAllowed = phone.isCspPlmnEnabled();
6352 }
6353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
6356 return isAllowed;
6357 }
6358
6359 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006360 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006361 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006362 try {
6363 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006364 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006365 } catch (SecurityException e) {
6366 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6367 // has carrier privileges on an active UICC
6368 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6369 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006370 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006371 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006372 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006373
6374 final long identity = Binder.clearCallingIdentity();
6375 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006376 UiccController uiccController = UiccController.getInstance();
6377 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006378 if (hasReadPermission) {
6379 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006380 }
Jordan Liu67997952019-04-22 15:10:43 -07006381
6382 // Remove private info if the caller doesn't have access
6383 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6384 for (UiccCardInfo cardInfo : cardInfos) {
6385 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6386 // is available
6387 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6388 if (card == null || card.getUiccProfile() == null) {
6389 // assume no access if the card or profile is unavailable
6390 filteredInfos.add(cardInfo.getUnprivileged());
6391 continue;
6392 }
6393 UiccProfile profile = card.getUiccProfile();
6394 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6395 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6396 filteredInfos.add(cardInfo);
6397 } else {
6398 filteredInfos.add(cardInfo.getUnprivileged());
6399 }
6400 }
6401 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
6405 }
6406
6407 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006408 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006409 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006410
Malcolm Chend965c8b2018-02-28 15:00:40 -08006411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6414 if (slots == null) {
6415 Rlog.i(LOG_TAG, "slots is null.");
6416 return null;
6417 }
6418
6419 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6420 for (int i = 0; i < slots.length; i++) {
6421 UiccSlot slot = slots[i];
6422 if (slot == null) {
6423 continue;
6424 }
6425
6426 String cardId;
6427 UiccCard card = slot.getUiccCard();
6428 if (card != null) {
6429 cardId = card.getCardId();
6430 } else {
6431 cardId = slot.getIccId();
6432 }
6433
Jordan Liu857451f2019-05-09 16:35:35 -07006434 if (cardId != null) {
6435 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6436 // if cardId is an EID, it's all digits so this is fine
6437 cardId = IccUtils.stripTrailingFs(cardId);
6438 }
6439
Malcolm Chend965c8b2018-02-28 15:00:40 -08006440 int cardState = 0;
6441 switch (slot.getCardState()) {
6442 case CARDSTATE_ABSENT:
6443 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6444 break;
6445 case CARDSTATE_PRESENT:
6446 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6447 break;
6448 case CARDSTATE_ERROR:
6449 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6450 break;
6451 case CARDSTATE_RESTRICTED:
6452 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6453 break;
6454 default:
6455 break;
6456
6457 }
6458
6459 infos[i] = new UiccSlotInfo(
6460 slot.isActive(),
6461 slot.isEuicc(),
6462 cardId,
6463 cardState,
6464 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006465 slot.isExtendedApduSupported(),
6466 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006467 }
6468 return infos;
6469 } finally {
6470 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006471 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006472 }
6473
6474 @Override
6475 public boolean switchSlots(int[] physicalSlots) {
6476 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006477
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
6480 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6481 } finally {
6482 Binder.restoreCallingIdentity(identity);
6483 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006484 }
Jack Yu4c988042018-02-27 15:30:01 -08006485
6486 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006487 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006488 final long identity = Binder.clearCallingIdentity();
6489 try {
6490 return UiccController.getInstance().getCardIdForDefaultEuicc();
6491 } finally {
6492 Binder.restoreCallingIdentity(identity);
6493 }
6494 }
6495
6496 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006497 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6498 enforceModifyPermission();
6499 final Phone phone = getPhone(subId);
6500 if (phone == null) {
6501 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6502 return;
6503 }
6504
Malcolm Chend965c8b2018-02-28 15:00:40 -08006505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 phone.setRadioIndicationUpdateMode(filters, mode);
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
6510 }
Jack Yu4c988042018-02-27 15:30:01 -08006511 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006512
6513 /**
goneil47ffb6e2018-04-06 15:40:58 -07006514 * A test API to reload the UICC profile.
6515 *
6516 * <p>Requires that the calling app has permission
6517 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6518 * @hide
6519 */
6520 @Override
6521 public void refreshUiccProfile(int subId) {
6522 enforceModifyPermission();
6523
6524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 Phone phone = getPhone(subId);
6527 if (phone == null) {
6528 return;
6529 }
6530 UiccCard uiccCard = phone.getUiccCard();
6531 if (uiccCard == null) {
6532 return;
6533 }
6534 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6535 if (uiccProfile == null) {
6536 return;
6537 }
6538 uiccProfile.refresh();
6539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
6542 }
6543
6544 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006545 * Returns false if the mobile data is disabled by default, otherwise return true.
6546 */
6547 private boolean getDefaultDataEnabled() {
6548 return "true".equalsIgnoreCase(
6549 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6550 }
6551
6552 /**
6553 * Returns true if the data roaming is enabled by default, i.e the system property
6554 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6555 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6556 */
6557 private boolean getDefaultDataRoamingEnabled(int subId) {
6558 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006559 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006560 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6561 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6562 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6563 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6564 return isDataRoamingEnabled;
6565 }
6566
6567 /**
6568 * Returns the default network type for the given {@code subId}, if the default network type is
6569 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6570 */
6571 private int getDefaultNetworkType(int subId) {
6572 return Integer.parseInt(
6573 TelephonyManager.getTelephonyProperty(
6574 mSubscriptionController.getPhoneId(subId),
6575 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6576 String.valueOf(Phone.PREFERRED_NT_MODE)));
6577 }
fionaxua13278b2018-03-21 00:08:13 -07006578
6579 @Override
6580 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6581 gid1, String gid2, String plmn, String spn) {
6582 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006583
6584 final long identity = Binder.clearCallingIdentity();
6585 try {
6586 final Phone phone = getPhone(subId);
6587 if (phone == null) {
6588 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6589 return;
6590 }
6591 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6592 } finally {
6593 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006594 }
fionaxua13278b2018-03-21 00:08:13 -07006595 }
6596
6597 @Override
6598 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006599 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 final Phone phone = getPhone(subId);
6604 if (phone == null) {
6605 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6606 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6607 }
6608 return phone.getCarrierIdListVersion();
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006611 }
fionaxua13278b2018-03-21 00:08:13 -07006612 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006613
6614 @Override
6615 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6617 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6618 return -1;
6619 }
6620
6621 final long identity = Binder.clearCallingIdentity();
6622 try {
6623 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
6627 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006628
6629 @Override
6630 public int getCdmaRoamingMode(int subId) {
6631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6632 mApp, subId, "getCdmaRoamingMode");
6633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
6640 }
6641
6642 @Override
6643 public boolean setCdmaRoamingMode(int subId, int mode) {
6644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6645 mApp, subId, "setCdmaRoamingMode");
6646
6647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
6652 }
6653 }
6654
6655 @Override
6656 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6658 mApp, subId, "setCdmaSubscriptionMode");
6659
6660 final long identity = Binder.clearCallingIdentity();
6661 try {
6662 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
6665 }
6666 }
chen xu7ee67862018-10-30 22:27:10 -07006667
sqian2fff4a32018-11-05 14:18:37 -08006668 private void ensureUserRunning(int userId) {
6669 if (!mUserManager.isUserRunning(userId)) {
6670 throw new IllegalStateException("User " + userId + " does not exist or not running");
6671 }
6672 }
6673
6674 /**
6675 * Returns a list of SMS apps on a given user.
6676 *
6677 * Only the shell user (UID 2000 or 0) can call it.
6678 * Target user must be running.
6679 */
6680 @Override
6681 public String[] getSmsApps(int userId) {
6682 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6683 ensureUserRunning(userId);
6684
6685 final Collection<SmsApplicationData> apps =
6686 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6687
6688 String[] ret = new String[apps.size()];
6689 int i = 0;
6690 for (SmsApplicationData app : apps) {
6691 ret[i++] = app.mPackageName;
6692 }
6693 return ret;
6694 }
6695
6696 /**
6697 * Returns the default SMS app package name on a given user.
6698 *
6699 * Only the shell user (UID 2000 or 0) can call it.
6700 * Target user must be running.
6701 */
6702 @Override
6703 public String getDefaultSmsApp(int userId) {
6704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6705 ensureUserRunning(userId);
6706
6707 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6708 /* updateIfNeeded= */ true, userId);
6709 return cn == null ? null : cn.getPackageName();
6710 }
6711
6712 /**
6713 * Set a package as the default SMS app on a given user.
6714 *
6715 * Only the shell user (UID 2000 or 0) can call it.
6716 * Target user must be running.
6717 */
6718 @Override
6719 public void setDefaultSmsApp(int userId, String packageName) {
6720 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6721 ensureUserRunning(userId);
6722
6723 boolean found = false;
6724 for (String pkg : getSmsApps(userId)) {
6725 if (TextUtils.equals(packageName, pkg)) {
6726 found = true;
6727 break;
6728 }
6729 }
6730 if (!found) {
6731 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6732 }
6733
6734 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6735 }
6736
chen xu7ee67862018-10-30 22:27:10 -07006737 @Override
sqian65eefe12019-02-22 15:55:18 -08006738 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006739 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006740 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006741 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006742 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6743 }
6744 final long identity = Binder.clearCallingIdentity();
6745 try {
sqian991b35e2018-12-12 16:48:18 -08006746 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6747 for (Phone phone: PhoneFactory.getPhones()) {
6748 if (phone.getEmergencyNumberTracker() != null
6749 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6750 emergencyNumberListInternal.put(
6751 phone.getSubId(),
6752 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6753 }
sqian03bca152018-12-05 18:48:28 -08006754 }
sqian991b35e2018-12-12 16:48:18 -08006755 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
sqian04b86072018-11-07 14:02:21 -08006759 }
6760
6761 @Override
sqian65eefe12019-02-22 15:55:18 -08006762 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006763 final Phone defaultPhone = getDefaultPhone();
6764 if (!exactMatch) {
6765 TelephonyPermissions
6766 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006767 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006768 }
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
sqian991b35e2018-12-12 16:48:18 -08006771 for (Phone phone: PhoneFactory.getPhones()) {
6772 if (phone.getEmergencyNumberTracker() != null
6773 && phone.getEmergencyNumberTracker() != null) {
6774 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6775 number, exactMatch)) {
6776 return true;
sqian03bca152018-12-05 18:48:28 -08006777 }
6778 }
sqian03bca152018-12-05 18:48:28 -08006779 }
6780 return false;
6781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
6784 }
6785
sqian9d4df8b2019-01-15 18:32:07 -08006786 /**
6787 * Update emergency number list for test mode.
6788 */
6789 @Override
6790 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6791 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6792 "updateEmergencyNumberListTestMode");
6793
6794 final long identity = Binder.clearCallingIdentity();
6795 try {
6796 for (Phone phone: PhoneFactory.getPhones()) {
6797 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6798 if (tracker != null) {
6799 tracker.executeEmergencyNumberTestModeCommand(action, num);
6800 }
6801 }
6802 } finally {
6803 Binder.restoreCallingIdentity(identity);
6804 }
6805 }
6806
6807 /**
6808 * Get the full emergency number list for test mode.
6809 */
6810 @Override
6811 public List<String> getEmergencyNumberListTestMode() {
6812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6813 "getEmergencyNumberListTestMode");
6814
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
6817 Set<String> emergencyNumbers = new HashSet<>();
6818 for (Phone phone: PhoneFactory.getPhones()) {
6819 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6820 if (tracker != null) {
6821 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6822 emergencyNumbers.add(num.getNumber());
6823 }
6824 }
6825 }
6826 return new ArrayList<>(emergencyNumbers);
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
6829 }
6830 }
6831
sqian04b86072018-11-07 14:02:21 -08006832 @Override
chen xu7ee67862018-10-30 22:27:10 -07006833 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6834 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6835 Phone phone = getPhone(subId);
6836 if (phone == null) {
6837 return null;
6838 }
6839 final long identity = Binder.clearCallingIdentity();
6840 try {
6841 UiccProfile profile = UiccController.getInstance()
6842 .getUiccProfileForPhone(phone.getPhoneId());
6843 if (profile != null) {
6844 return profile.getCertsFromCarrierPrivilegeAccessRules();
6845 }
6846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848 }
6849 return null;
6850 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006851
6852 /**
6853 * Enable or disable a modem stack.
6854 */
6855 @Override
6856 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6857 enforceModifyPermission();
6858
6859 final long identity = Binder.clearCallingIdentity();
6860 try {
6861 Phone phone = PhoneFactory.getPhone(slotIndex);
6862 if (phone == null) {
6863 return false;
6864 } else {
6865 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6866 }
6867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
6870 }
Micheled3107c52018-12-21 15:00:11 -08006871
Malcolm Chen33f55e12019-03-27 18:34:05 -07006872 /**
6873 * Whether a modem stack is enabled or not.
6874 */
6875 @Override
6876 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6877 Phone phone = PhoneFactory.getPhone(slotIndex);
6878 if (phone == null) return false;
6879
6880 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6881 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6882 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6883 }
6884
6885 final long identity = Binder.clearCallingIdentity();
6886 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006887 try {
6888 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6889 } catch (NoSuchElementException ex) {
6890 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6891 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
6895 }
6896
Micheled3107c52018-12-21 15:00:11 -08006897 @Override
Michele2fb0f222019-03-19 14:58:42 -07006898 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006899 enforceModifyPermission();
6900
6901 final long identity = Binder.clearCallingIdentity();
6902 try {
6903 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006904 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006905 .commit();
6906 } finally {
6907 Binder.restoreCallingIdentity(identity);
6908 }
6909 }
6910
6911 @Override
Michele2fb0f222019-03-19 14:58:42 -07006912 @TelephonyManager.IsMultiSimSupportedResult
6913 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006915 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6916 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006917 }
Micheled3107c52018-12-21 15:00:11 -08006918
6919 final long identity = Binder.clearCallingIdentity();
6920 try {
Michele2fb0f222019-03-19 14:58:42 -07006921 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006926
Michele2fb0f222019-03-19 14:58:42 -07006927 @TelephonyManager.IsMultiSimSupportedResult
6928 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006929 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6930 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6931 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006932 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6933 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006934 }
6935 // Check if the hardware supports multisim functionality. If usage of multisim is not
6936 // supported by the modem, indicate that it is restricted.
6937 PhoneCapability staticCapability =
6938 mPhoneConfigurationManager.getStaticPhoneCapability();
6939 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006940 loge("isMultiSimSupportedInternal: no static configuration available");
6941 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006942 }
6943 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006944 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6945 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006946 }
6947 // Check if support of multiple SIMs is restricted by carrier
6948 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006949 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006950 }
6951
Michele2fb0f222019-03-19 14:58:42 -07006952 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006953 }
6954
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006955 /**
6956 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006957 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6958 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6959 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006960 * @param numOfSims number of active sims we want to switch to
6961 */
6962 @Override
6963 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006964 if (numOfSims == 1) {
6965 enforceModifyPermission();
6966 } else {
6967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6968 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6969 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006970 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006971
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006972 try {
Michele30b57b22019-03-01 12:01:14 -08006973 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006974 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006975 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6976 return;
6977 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006978 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
6981 }
6982 }
6983
6984 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006985 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006986 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006987 */
6988 @Override
6989 public boolean isRebootRequiredForModemConfigChange() {
6990 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6991 final long identity = Binder.clearCallingIdentity();
6992 try {
6993 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
6996 }
6997 }
6998
Pengquan Meng92d253b2019-02-06 11:12:53 -08006999 private void updateModemStateMetrics() {
7000 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7001 // TODO: check the state for each modem if the api is ready.
7002 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7003 }
7004
Pengquan Meng3aceaec2019-01-23 11:16:29 -08007005 @Override
7006 public int[] getSlotsMapping() {
7007 enforceReadPrivilegedPermission("getSlotsMapping");
7008
7009 final long identity = Binder.clearCallingIdentity();
7010 try {
7011 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7012 // All logical slots should have a mapping to a physical slot.
7013 int[] logicalSlotsMapping = new int[phoneCount];
7014 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7015 for (int i = 0; i < slotInfos.length; i++) {
7016 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7017 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7018 }
7019 }
7020 return logicalSlotsMapping;
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
7023 }
7024 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007025
7026 /**
7027 * Get the IRadio HAL Version
7028 */
7029 @Override
7030 public int getRadioHalVersion() {
7031 Phone phone = getDefaultPhone();
7032 if (phone == null) return -1;
7033 HalVersion hv = phone.getHalVersion();
7034 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7035 return hv.major * 100 + hv.minor;
7036 }
Malcolm Chen460810d2019-04-10 18:25:07 -07007037
7038 /**
Malcolm Chen29739692019-04-18 13:51:02 -07007039 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7040 * corresponding network requests on a subId.
7041 *
7042 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07007043 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07007044 * 2) APN is un-metered for this subscription, or
7045 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7046 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7047 *
7048 * @return whether data is allowed for a apn type.
7049 *
7050 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07007051 */
7052 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07007053 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07007054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07007055 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7056 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007057 }
7058
7059 // Now that all security checks passes, perform the operation as ourselves.
7060 final long identity = Binder.clearCallingIdentity();
7061 try {
7062 Phone phone = getPhone(subId);
7063 if (phone == null) return false;
7064
Jack Yu40306fc2019-05-13 16:54:09 -07007065 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen29739692019-04-18 13:51:02 -07007066 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
7070 }
7071
7072 @Override
Jack Yu40306fc2019-05-13 16:54:09 -07007073 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chen29739692019-04-18 13:51:02 -07007074 enforceReadPrivilegedPermission("isApnMetered");
7075
7076 // Now that all security checks passes, perform the operation as ourselves.
7077 final long identity = Binder.clearCallingIdentity();
7078 try {
7079 Phone phone = getPhone(subId);
7080 if (phone == null) return true; // By default return true.
7081
Jack Yu40306fc2019-05-13 16:54:09 -07007082 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007083 } finally {
7084 Binder.restoreCallingIdentity(identity);
7085 }
7086 }
chen xu7bc8e072019-05-28 15:20:57 -07007087
7088 @Override
Brad Ebinger5ff97f62019-04-23 16:31:13 -07007089 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7090 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7091 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7092 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7093 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7094 }
7095 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7096 Intent intent = new Intent();
7097 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7098 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7099 // Bring up choose default SMS subscription dialog right now
7100 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7101 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7102 mApp.startActivity(intent);
7103 }
7104
7105 @Override
chen xu7bc8e072019-05-28 15:20:57 -07007106 public String getMmsUAProfUrl(int subId) {
7107 //TODO investigate if this API should require proper permission check in R b/133791609
7108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7111 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114 }
7115 }
7116
7117 @Override
7118 public String getMmsUserAgent(int subId) {
7119 //TODO investigate if this API should require proper permission check in R b/133791609
7120 final long identity = Binder.clearCallingIdentity();
7121 try {
7122 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7123 .getString(com.android.internal.R.string.config_mms_user_agent);
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
7127 }
Jack Yuea3bebe2019-05-28 16:12:25 -07007128
7129 @Override
7130 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7131 enforceModifyPermission();
7132
7133 // Now that all security checks passes, perform the operation as ourselves.
7134 final long identity = Binder.clearCallingIdentity();
7135 try {
7136 Phone phone = getPhone(subId);
7137 if (phone == null) return false;
7138
7139 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
7143 }
7144
7145 @Override
7146 public boolean isDataAllowedInVoiceCall(int subId) {
7147 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7148
7149 // Now that all security checks passes, perform the operation as ourselves.
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 Phone phone = getPhone(subId);
7153 if (phone == null) return false;
7154
7155 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7156 } finally {
7157 Binder.restoreCallingIdentity(identity);
7158 }
7159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007160}