blob: 47786086e794245d896f4967b1e1056cbe39db35 [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 Gunnf70ed162019-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;
Malcolm Chen6ca97372019-07-01 16:28:21 -070047import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070048import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080049import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070050import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.ServiceManager;
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 Berionne482f8202018-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;
Michele4245e952019-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 Yub5d8f642018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070094import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080095import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070098import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700100import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsMmTelFeature;
102import android.telephony.ims.aidl.IImsRcsFeature;
103import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800105import android.telephony.ims.feature.MmTelFeature;
106import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800107import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800111import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800113
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import com.android.ims.ImsException;
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 xu651eec72018-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 Ebingera63db5f2019-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 Chen2c63d402018-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;
Makoto Onukida3bf792018-09-18 16:06:29 -0700142import com.android.internal.telephony.SmsApplication;
143import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700144import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-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 Chendc8c10e2019-04-10 18:25:07 -0700148import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-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 Ebinger9c0eb502019-01-23 15:06:19 -0800151import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-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 Ebingera63db5f2019-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;
Makoto Onukida3bf792018-09-18 16:06:29 -0700173import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800174import java.util.HashMap;
sqianf4ca7ed2019-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 Bakhshif71371d2019-04-29 17:29:44 -0700179import java.util.NoSuchElementException;
sqianf4ca7ed2019-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 xu6dac5ab2018-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 Menga1bb6272018-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 xu6dac5ab2018-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 Chen8e4ed912019-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 Bakhshif71371d2019-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 Chen2c63d402018-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
Michelecea4cf22018-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
vagdeviaf9a5b92018-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
vagdeviaf9a5b92018-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 }
vagdeviaf9a5b92018-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 Bakhshif782e562018-12-11 15:15:39 -0800401 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
403 switch (msg.what) {
Pengquan Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-09-06 09:59:22 -0700419 request.result = true;
420 notifyRequester(request);
421 return;
422 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Bakhshif782e562018-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 Menga1bb6272018-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 Bakhshif782e562018-12-11 15:15:39 -0800683 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-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 Bakhshif782e562018-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 xu6dac5ab2018-10-26 17:39:23 -0700701 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800702 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700703 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800704 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
chen xu6dac5ab2018-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 Menga1bb6272018-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 Bakhshif782e562018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menge3d01e22018-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 Mattisab947702019-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 Menga1bb6272018-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 Berionne482f8202018-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 Berionne482f8202018-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 Berionne482f8202018-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 Menga1bb6272018-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 Bakhshif782e562018-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 Berionne482f8202018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 xu6dac5ab2018-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 Bakhshif782e562018-12-11 15:15:39 -08001110 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case EVENT_CMD_MODEM_REBOOT_DONE:
1113 handleNullReturnEvent(msg, "rebootModem");
1114 break;
Malcolm Chen8e4ed912019-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 Bakhshi33d584b2019-02-27 10:44:32 -08001119 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-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 Bakhshif71371d2019-04-29 17:29:44 -07001127 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-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 Chen8e4ed912019-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 Menga1bb6272018-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 Menga1bb6272018-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);
vagdeviaf9a5b92018-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);
vagdeviaf9a5b92018-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 Bakhshif782e562018-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 Bakhshif782e562018-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 Bakhshif782e562018-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();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001329 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001330 mTelephonySharedPreferences =
1331 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001332 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-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 Bakhshif782e562018-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 Liu4c733742019-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001436 if (!isValid) {
1437 return;
1438 }
Wink Saville08874612014-08-31 19:19:58 -07001439
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001714 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Yud79fba22018-12-13 11:51:28 -08001781 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Yud79fba22018-12-13 11:51:28 -08001801 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 final Phone phone = getPhone(subId);
1816 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001817 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 public int getDataState() {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001876 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1877 }
1878
1879 @Override
1880 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881 final long identity = Binder.clearCallingIdentity();
1882 try {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001883 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-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
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 public int getDataActivity() {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001897 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1898 }
1899
1900 @Override
1901 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902 final long identity = Binder.clearCallingIdentity();
1903 try {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001904 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-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 Bakhshif782e562018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001967 Phone phone = PhoneFactory.getPhone(phoneId);
1968 if (phone != null) {
1969 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07001970 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001971 if (sst != null) {
1972 LocaleTracker lt = sst.getLocaleTracker();
1973 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07001974 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
1975 return lt.getCurrentCountry();
1976 } else if (emergencyNumberTracker != null) {
1977 return emergencyNumberTracker.getEmergencyCountryIso();
1978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 }
1980 }
1981 }
1982 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001983 } finally {
1984 Binder.restoreCallingIdentity(identity);
1985 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001986 }
1987
1988 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001990 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001991 }
1992
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001994 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 mApp.enforceCallingOrSelfPermission(
1996 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997
1998 final long identity = Binder.clearCallingIdentity();
1999 try {
2000 final Phone phone = getPhone(subId);
2001 if (phone != null) {
2002 phone.enableLocationUpdates();
2003 }
2004 } finally {
2005 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 }
2008
2009 @Override
2010 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002011 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002012 }
2013
Sanket Padawe356d7632015-06-22 14:03:32 -07002014 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002015 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 mApp.enforceCallingOrSelfPermission(
2017 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002018
2019 final long identity = Binder.clearCallingIdentity();
2020 try {
2021 final Phone phone = getPhone(subId);
2022 if (phone != null) {
2023 phone.disableLocationUpdates();
2024 }
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
Nathan Harold31d7ff32018-10-15 20:20:30 -07002030 /**
2031 * Returns the target SDK version number for a given package name.
2032 *
Nathan Haroldba61eeb2019-07-10 17:04:16 -07002033 * This call MUST be invoked before clearing the calling UID.
2034 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002035 * @return target SDK if the package is found or INT_MAX.
2036 */
2037 private int getTargetSdk(String packageName) {
2038 try {
Nathan Haroldba61eeb2019-07-10 17:04:16 -07002039 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
2040 packageName, 0, UserHandle.getUserId(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002041 if (ai != null) return ai.targetSdkVersion;
2042 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldba61eeb2019-07-10 17:04:16 -07002043 loge("Failed to get package info for pkg="
2044 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002045 }
2046 return Integer.MAX_VALUE;
2047 }
2048
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 @Override
2050 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002051 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2052 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002053 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2054 throw new SecurityException(
2055 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2056 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002057
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2059 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2060 return null;
2061 }
Svetoslav64fad262015-04-14 14:35:21 -07002062
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002063 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064
Nathan Haroldf180aac2018-06-01 18:43:55 -07002065 List<CellInfo> info = getAllCellInfo(callingPackage);
2066 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067
Nathan Haroldf180aac2018-06-01 18:43:55 -07002068 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2069 for (CellInfo ci : info) {
2070 if (ci instanceof CellInfoGsm) {
2071 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2072 } else if (ci instanceof CellInfoWcdma) {
2073 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002076 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 }
2078
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002079 private List<CellInfo> getCachedCellInfo() {
2080 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2081 for (Phone phone : PhoneFactory.getPhones()) {
2082 List<CellInfo> info = phone.getAllCellInfo();
2083 if (info != null) cellInfos.addAll(info);
2084 }
2085 return cellInfos;
2086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087
2088 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002089 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002090 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002091 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002092
2093 LocationAccessPolicy.LocationPermissionResult locationResult =
2094 LocationAccessPolicy.checkLocationPermission(mApp,
2095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2096 .setCallingPackage(callingPackage)
2097 .setCallingPid(Binder.getCallingPid())
2098 .setCallingUid(Binder.getCallingUid())
2099 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002100 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2102 .build());
2103 switch (locationResult) {
2104 case DENIED_HARD:
2105 throw new SecurityException("Not allowed to access cell info");
2106 case DENIED_SOFT:
2107 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002110 final int targetSdk = getTargetSdk(callingPackage);
2111 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2112 return getCachedCellInfo();
2113 }
2114
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002115 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2120 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002121 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002122 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002123 if (info != null) cellInfos.addAll(info);
2124 }
2125 return cellInfos;
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129 }
2130
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002131 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2133 requestCellInfoUpdateInternal(
2134 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2135 }
2136
2137 @Override
2138 public void requestCellInfoUpdateWithWorkSource(
2139 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2140 enforceModifyPermission();
2141 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2142 }
2143
2144 private void requestCellInfoUpdateInternal(
2145 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002146 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002147 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002148
2149 LocationAccessPolicy.LocationPermissionResult locationResult =
2150 LocationAccessPolicy.checkLocationPermission(mApp,
2151 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2152 .setCallingPackage(callingPackage)
2153 .setCallingPid(Binder.getCallingPid())
2154 .setCallingUid(Binder.getCallingUid())
2155 .setMethod("requestCellInfoUpdate")
2156 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2157 .build());
2158 switch (locationResult) {
2159 case DENIED_HARD:
2160 throw new SecurityException("Not allowed to access cell info");
2161 case DENIED_SOFT:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002162 try {
2163 cb.onCellInfo(new ArrayList<CellInfo>());
2164 } catch (RemoteException re) {
2165 // Drop without consequences
2166 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002167 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002168 }
2169
Nathan Harold32e84c42019-05-09 10:13:47 -07002170
2171 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002172 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2173
2174 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2175 }
2176
2177 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002179 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002180 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002184 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185 } finally {
2186 Binder.restoreCallingIdentity(identity);
2187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
2189
Shishir Agrawala9f32182016-04-12 12:00:16 -07002190 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002191 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002192 Phone phone = PhoneFactory.getPhone(slotIndex);
2193 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002194 return null;
2195 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002196 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002197 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2198 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002199 return null;
2200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201
2202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 return phone.getImei();
2205 } finally {
2206 Binder.restoreCallingIdentity(identity);
2207 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002208 }
2209
2210 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002211 public String getTypeAllocationCodeForSlot(int slotIndex) {
2212 Phone phone = PhoneFactory.getPhone(slotIndex);
2213 String tac = null;
2214 if (phone != null) {
2215 String imei = phone.getImei();
2216 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2217 }
2218 return tac;
2219 }
2220
2221 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002222 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002223 Phone phone = PhoneFactory.getPhone(slotIndex);
2224 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002225 return null;
2226 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002227
Jeff Davidson913390f2018-02-23 17:11:49 -08002228 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002229 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2230 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002231 return null;
2232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002233
2234 final long identity = Binder.clearCallingIdentity();
2235 try {
2236 return phone.getMeid();
2237 } finally {
2238 Binder.restoreCallingIdentity(identity);
2239 }
Jack Yu2af8d712017-03-15 17:14:14 -07002240 }
2241
2242 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002243 public String getManufacturerCodeForSlot(int slotIndex) {
2244 Phone phone = PhoneFactory.getPhone(slotIndex);
2245 String manufacturerCode = null;
2246 if (phone != null) {
2247 String meid = phone.getMeid();
2248 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2249 }
2250 return manufacturerCode;
2251 }
2252
2253 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002254 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002255 Phone phone = PhoneFactory.getPhone(slotIndex);
2256 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002257 return null;
2258 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002259 int subId = phone.getSubId();
2260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2261 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2262 return null;
2263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264
2265 final long identity = Binder.clearCallingIdentity();
2266 try {
2267 return phone.getDeviceSvn();
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
2270 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002271 }
2272
fionaxu43304da2017-11-27 22:51:16 -08002273 @Override
2274 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 final Phone phone = getPhone(subId);
2278 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
fionaxu43304da2017-11-27 22:51:16 -08002282 }
2283
2284 @Override
2285 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 final Phone phone = getPhone(subId);
2289 return phone == null ? null : phone.getCarrierName();
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
fionaxu43304da2017-11-27 22:51:16 -08002293 }
2294
calvinpanffe225e2018-11-01 19:43:06 +08002295 @Override
chen xu0026ca62019-03-06 15:28:50 -08002296 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002297 final long identity = Binder.clearCallingIdentity();
2298 try {
2299 final Phone phone = getPhone(subId);
2300 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002301 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
2305 }
2306
2307 @Override
chen xu0026ca62019-03-06 15:28:50 -08002308 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002309 final long identity = Binder.clearCallingIdentity();
2310 try {
2311 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002312 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
2316 }
2317
chen xu651eec72018-11-11 19:03:44 -08002318 @Override
chen xu864e11c2018-12-06 22:10:03 -08002319 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2320 if (!isSubscriptionMccMnc) {
2321 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2322 }
chen xu651eec72018-11-11 19:03:44 -08002323 final Phone phone = PhoneFactory.getPhone(slotIndex);
2324 if (phone == null) {
2325 return TelephonyManager.UNKNOWN_CARRIER_ID;
2326 }
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
2333 }
2334
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 //
2336 // Internal helper methods.
2337 //
2338
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002339 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2341 *
2342 * @throws SecurityException if the caller does not have the required permission
2343 */
2344 private void enforceModifyPermission() {
2345 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2346 }
2347
2348 /**
2349 * Make sure the caller has the CALL_PHONE permission.
2350 *
2351 * @throws SecurityException if the caller does not have the required permission
2352 */
2353 private void enforceCallPermission() {
2354 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2355 }
2356
Stuart Scott8eef64f2015-04-08 15:13:54 -07002357 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002359 "ConnectivityService");
2360 }
2361
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 private String createTelUrl(String number) {
2363 if (TextUtils.isEmpty(number)) {
2364 return null;
2365 }
2366
Jake Hambye994d462014-02-03 13:10:13 -08002367 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 }
2369
Ihab Awadf9e92732013-12-05 18:02:52 -08002370 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2372 }
2373
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002374 private static void logv(String msg) {
2375 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2376 }
2377
Ihab Awadf9e92732013-12-05 18:02:52 -08002378 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2380 }
2381
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002384 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002385 }
2386
Sanket Padawe356d7632015-06-22 14:03:32 -07002387 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002388 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 final Phone phone = PhoneFactory.getPhone(slotIndex);
2392 if (phone == null) {
2393 return PhoneConstants.PHONE_TYPE_NONE;
2394 } else {
2395 return phone.getPhoneType();
2396 }
2397 } finally {
2398 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 }
2401
2402 /**
2403 * Returns the CDMA ERI icon index to display
2404 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 @Override
2406 public int getCdmaEriIconIndex(String callingPackage) {
2407 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002408 }
2409
Sanket Padawe356d7632015-06-22 14:03:32 -07002410 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002411 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002413 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002414 return -1;
2415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416
2417 final long identity = Binder.clearCallingIdentity();
2418 try {
2419 final Phone phone = getPhone(subId);
2420 if (phone != null) {
2421 return phone.getCdmaEriIconIndex();
2422 } else {
2423 return -1;
2424 }
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
2430 /**
2431 * Returns the CDMA ERI icon mode,
2432 * 0 - ON
2433 * 1 - FLASHING
2434 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002435 @Override
2436 public int getCdmaEriIconMode(String callingPackage) {
2437 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002438 }
2439
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002441 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002443 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002444 return -1;
2445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 final Phone phone = getPhone(subId);
2450 if (phone != null) {
2451 return phone.getCdmaEriIconMode();
2452 } else {
2453 return -1;
2454 }
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 }
2459
2460 /**
2461 * Returns the CDMA ERI text,
2462 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002463 @Override
2464 public String getCdmaEriText(String callingPackage) {
2465 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002466 }
2467
Sanket Padawe356d7632015-06-22 14:03:32 -07002468 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002469 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002471 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002472 return null;
2473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474
2475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 final Phone phone = getPhone(subId);
2478 if (phone != null) {
2479 return phone.getCdmaEriText();
2480 } else {
2481 return null;
2482 }
2483 } finally {
2484 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 }
2487
2488 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002489 * Returns the CDMA MDN.
2490 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002492 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2494 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495
2496 final long identity = Binder.clearCallingIdentity();
2497 try {
2498 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002499 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 return phone.getLine1Number();
2501 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002502 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 return null;
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002507 }
2508 }
2509
2510 /**
2511 * Returns the CDMA MIN.
2512 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002513 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002514 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2516 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 final Phone phone = getPhone(subId);
2521 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2522 return phone.getCdmaMin();
2523 } else {
2524 return null;
2525 }
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002528 }
2529 }
2530
Hall Liud892bec2018-11-30 14:51:45 -08002531 @Override
2532 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2533 INumberVerificationCallback callback, String callingPackage) {
2534 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2535 != PERMISSION_GRANTED) {
2536 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2537 }
2538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2539
2540 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2541 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2542 throw new SecurityException("Calling package must be configured in the device config");
2543 }
2544
2545 if (range == null) {
2546 throw new NullPointerException("Range must be non-null");
2547 }
2548
2549 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002550 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002551
2552 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2553 }
2554
Junda Liuca05d5d2014-08-14 22:36:34 -07002555 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 * Returns true if CDMA provisioning needs to run.
2557 */
2558 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 final long identity = Binder.clearCallingIdentity();
2560 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002561 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 }
2566
2567 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002568 * Sets the voice mail number of a given subId.
2569 */
2570 @Override
2571 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002572 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2577 new Pair<String, String>(alphaTag, number), new Integer(subId));
2578 return success;
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
2581 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002582 }
2583
Ta-wei Yen87c49842016-05-13 21:19:52 -07002584 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002585 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2586 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002587 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002588 if (!TextUtils.equals(callingPackage, systemDialer)) {
2589 throw new SecurityException("caller must be system dialer");
2590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2595 if (phoneAccountHandle == null) {
2596 return null;
2597 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002598 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 } finally {
2600 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002601 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002602 }
2603
2604 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002605 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002606 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002608 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002609 return null;
2610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002612 final long identity = Binder.clearCallingIdentity();
2613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002614 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002615 } finally {
2616 Binder.restoreCallingIdentity(identity);
2617 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002618 }
2619
2620 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002621 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2622 VisualVoicemailSmsFilterSettings settings) {
2623 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624
2625 final long identity = Binder.clearCallingIdentity();
2626 try {
2627 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002628 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 } finally {
2630 Binder.restoreCallingIdentity(identity);
2631 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002632 }
2633
2634 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002635 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2636 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637
2638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002641 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002645 }
2646
2647 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002648 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2649 String callingPackage, int subId) {
2650 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002655 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002659 }
2660
2661 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002662 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002663 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664
2665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002668 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 } finally {
2670 Binder.restoreCallingIdentity(identity);
2671 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002672 }
2673
2674 @Override
2675 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2676 String number, int port, String text, PendingIntent sentIntent) {
2677 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002678 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002679 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002680 SmsController smsController = PhoneFactory.getSmsController();
2681 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2682 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002683 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002684
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002685 /**
fionaxu0152e512016-11-14 13:36:14 -08002686 * Sets the voice activation state of a given subId.
2687 */
2688 @Override
2689 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2691 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692
2693 final long identity = Binder.clearCallingIdentity();
2694 try {
2695 final Phone phone = getPhone(subId);
2696 if (phone != null) {
2697 phone.setVoiceActivationState(activationState);
2698 } else {
2699 loge("setVoiceActivationState fails with invalid subId: " + subId);
2700 }
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002703 }
2704 }
2705
2706 /**
2707 * Sets the data activation state of a given subId.
2708 */
2709 @Override
2710 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2712 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713
2714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 final Phone phone = getPhone(subId);
2717 if (phone != null) {
2718 phone.setDataActivationState(activationState);
2719 } else {
2720 loge("setVoiceActivationState fails with invalid subId: " + subId);
2721 }
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002724 }
2725 }
2726
2727 /**
2728 * Returns the voice activation state of a given subId.
2729 */
2730 @Override
2731 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002732 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733
fionaxu0152e512016-11-14 13:36:14 -08002734 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 if (phone != null) {
2738 return phone.getVoiceActivationState();
2739 } else {
2740 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002744 }
2745 }
2746
2747 /**
2748 * Returns the data activation state of a given subId.
2749 */
2750 @Override
2751 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002752 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
fionaxu0152e512016-11-14 13:36:14 -08002754 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 if (phone != null) {
2758 return phone.getDataActivationState();
2759 } else {
2760 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2761 }
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002764 }
2765 }
2766
2767 /**
Wink Saville36469e72014-06-11 15:17:00 -07002768 * Returns the unread count of voicemails for a subId
2769 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002771 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2773 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2774 return 0;
2775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 final Phone phone = getPhone(subId);
2779 if (phone != null) {
2780 return phone.getVoiceMessageCount();
2781 } else {
2782 return 0;
2783 }
2784 } finally {
2785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788
2789 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002790 * returns true, if the device is in a state where both voice and data
2791 * are supported simultaneously. This can change based on location or network condition.
2792 */
2793 @Override
2794 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 final Phone phone = getPhone(subId);
2798 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002802 }
2803
2804 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002805 * Send the dialer code if called from the current default dialer or the caller has
2806 * carrier privilege.
2807 * @param inputCode The dialer code to send
2808 */
2809 @Override
2810 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002811 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002812 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002813 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2814 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002815 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002816 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2817 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002822 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 } finally {
2824 Binder.restoreCallingIdentity(identity);
2825 }
fionaxu235cc5e2017-03-06 22:25:57 -08002826 }
2827
Pengquan Menga1bb6272018-09-06 09:59:22 -07002828 @Override
2829 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002830 if (!isActiveSubscription(subId)) {
2831 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2832 }
2833
Pengquan Menga1bb6272018-09-06 09:59:22 -07002834 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2835 }
2836
Brad Ebinger35c841c2018-10-01 10:40:55 -07002837 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002838 public boolean isInEmergencySmsMode() {
2839 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 for (Phone phone : PhoneFactory.getPhones()) {
2843 if (phone.isInEmergencySmsMode()) {
2844 return true;
2845 }
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
2849 }
2850 return false;
2851 }
2852
2853 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002854 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2855 throws RemoteException {
2856 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002857 final long token = Binder.clearCallingIdentity();
2858 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002860 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 .addRegistrationCallbackForSubscription(c, subId);
2862 } finally {
2863 Binder.restoreCallingIdentity(token);
2864 }
2865 }
2866
2867 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002868 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2869 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002870 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2871 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2872 }
2873 Binder.withCleanCallingIdentity(() -> {
2874 try {
2875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002876 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002877 .removeRegistrationCallbackForSubscription(c, subId);
2878 } catch (IllegalArgumentException e) {
2879 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2880 + "is inactive, ignoring unregister.");
2881 // If the subscription is no longer active, just return, since the callback
2882 // will already have been removed internally.
2883 }
2884 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002885 }
2886
2887 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002888 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2889 throws RemoteException {
2890 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2892 final long token = Binder.clearCallingIdentity();
2893 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002894 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002895 .addCapabilitiesCallbackForSubscription(c, subId);
2896 } finally {
2897 Binder.restoreCallingIdentity(token);
2898 }
2899 }
2900
2901 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002902 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2903 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002904
2905 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2906 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2907 }
2908 Binder.withCleanCallingIdentity(() -> {
2909 try {
2910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002912 .removeCapabilitiesCallbackForSubscription(c, subId);
2913 } catch (IllegalArgumentException e) {
2914 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2915 + "is inactive, ignoring unregister.");
2916 // If the subscription is no longer active, just return, since the callback
2917 // will already have been removed internally.
2918 }
2919 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002920 }
2921
2922 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002923 public boolean isCapable(int subId, int capability, int regTech) {
2924 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2926 final long token = Binder.clearCallingIdentity();
2927 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002928 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002929 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2930 } catch (ImsException e) {
2931 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2932 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002933 } catch (IllegalArgumentException e) {
2934 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2935 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002936 } finally {
2937 Binder.restoreCallingIdentity(token);
2938 }
2939 }
2940
2941 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002942 public boolean isAvailable(int subId, int capability, int regTech) {
2943 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002944 final long token = Binder.clearCallingIdentity();
2945 try {
2946 Phone phone = getPhone(subId);
2947 if (phone == null) return false;
2948 return phone.isImsCapabilityAvailable(capability, regTech);
2949 } finally {
2950 Binder.restoreCallingIdentity(token);
2951 }
2952 }
2953
2954 @Override
2955 public boolean isAdvancedCallingSettingEnabled(int subId) {
2956 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2958 final long token = Binder.clearCallingIdentity();
2959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002960 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2962 } finally {
2963 Binder.restoreCallingIdentity(token);
2964 }
2965 }
2966
2967 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002968 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002970 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002974 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 }
2980
2981 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002982 public boolean isVtSettingEnabled(int subId) {
2983 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 getSlotIndexOrException(subId)).isVtEnabledByUser();
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
2994 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002995 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002997 "setVtSettingEnabled");
Brad Ebinger35c841c2018-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 Bakhshif782e562018-12-11 15:15:39 -08003001 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
3005 }
3006
3007 @Override
3008 public boolean isVoWiFiSettingEnabled(int subId) {
3009 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003013 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003014 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
3018 }
3019
3020 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003021 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003023 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
3031 }
3032
3033 @Override
3034 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3035 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003039 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003040 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
3046 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003047 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003049 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003053 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003054 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
3058 }
3059
3060 @Override
3061 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3063 "setVoWiFiNonPersistent");
3064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003067 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003068 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 @Override
3075 public int getVoWiFiModeSetting(int subId) {
3076 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003080 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003081 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
3085 }
3086
3087 @Override
3088 public void setVoWiFiModeSetting(int subId, int mode) {
3089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3090 "setVoWiFiModeSetting");
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003094 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003095 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
3099 }
3100
3101 @Override
3102 public int getVoWiFiRoamingModeSetting(int subId) {
3103 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
3114 @Override
3115 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3117 "setVoWiFiRoamingModeSetting");
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003121 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
3126 }
3127
3128 @Override
3129 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3131 "setRttCapabilityEnabled");
3132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003135 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
3140 }
3141
3142 @Override
3143 public boolean isTtyOverVolteEnabled(int subId) {
3144 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003148 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003155 @Override
3156 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3157 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003161 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003162 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 }
3167
3168 @Override
3169 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3170 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3171 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003172 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3173 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3174 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003175 try {
3176 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003178 .removeProvisioningCallbackForSubscription(callback, subId);
3179 } catch (IllegalArgumentException e) {
3180 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3181 + "is inactive, ignoring unregister.");
3182 // If the subscription is no longer active, just return, since the callback will already
3183 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
3187 }
3188
3189 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003190 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3191 boolean isProvisioned) {
3192 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3193 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3194 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3195 }
3196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3197 "setProvisioningStatusForCapability");
3198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3201 Phone phone = getPhone(subId);
3202 if (phone == null) {
3203 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3204 + subId);
3205 return;
3206 }
3207 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3208 return;
3209 }
3210
3211 // this capability requires provisioning, route to the correct API.
3212 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3213 switch (capability) {
3214 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3215 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3216 ims.setVolteProvisioned(isProvisioned);
3217 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3218 ims.setWfcProvisioned(isProvisioned);
3219 }
3220 break;
3221 }
3222 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3223 // There is currently no difference in VT provisioning type.
3224 ims.setVtProvisioned(isProvisioned);
3225 break;
3226 }
3227 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3228 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3229 // change the capability of the feature instead if needed.
3230 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3231 == isProvisioned) {
3232 // No change in provisioning.
3233 return;
3234 }
3235 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3236 try {
3237 ims.changeMmTelCapability(capability, tech, isProvisioned);
3238 } catch (ImsException e) {
3239 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3240 + ", Exception" + e.getMessage());
3241 }
3242 break;
3243 }
3244 default: {
3245 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3246 + capability + "', which does not require provisioning.");
3247 }
3248 }
3249
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
3253 }
3254
3255 @Override
3256 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3257 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3258 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3259 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3260 }
3261 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3265 Phone phone = getPhone(subId);
3266 if (phone == null) {
3267 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3268 + subId);
3269 // We will fail with "true" as the provisioning status because this is the default
3270 // if we do not require provisioning.
3271 return true;
3272 }
3273
3274 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3275 return true;
3276 }
3277
3278 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3279 switch (capability) {
3280 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3281 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3282 return ims.isVolteProvisionedOnDevice();
3283 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3284 return ims.isWfcProvisionedOnDevice();
3285 }
3286 // This should never happen, since we are checking tech above to make sure it
3287 // is either LTE or IWLAN.
3288 throw new IllegalArgumentException("Invalid radio technology for voice "
3289 + "capability.");
3290 }
3291 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3292 // There is currently no difference in VT provisioning type.
3293 return ims.isVtProvisionedOnDevice();
3294 }
3295 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3296 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3297 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3298 }
3299 default: {
3300 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3301 + capability + "', which does not require provisioning.");
3302 }
3303 }
3304
3305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
3311 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3312 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3313 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3314 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3315 }
3316 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3317 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3318 return (provisionedBits & capability) > 0;
3319 }
3320
3321 @Override
3322 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3323 boolean isProvisioned) {
3324 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3325 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3326 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3327 }
3328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3329 "setProvisioningStatusForCapability");
3330 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3331 // If the current provisioning status for capability already matches isProvisioned,
3332 // do nothing.
3333 if (((provisionedBits & capability) > 0) == isProvisioned) {
3334 return;
3335 }
3336 if (isProvisioned) {
3337 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3338 } else {
3339 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3340 }
3341 }
3342
3343 /**
3344 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3345 * technology. The bitfield should mirror the bitfield defined by
3346 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3347 */
3348 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3349 String key = getMmTelProvisioningKey(subId, tech);
3350 // Default is no capabilities are provisioned.
3351 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3352 }
3353
3354 /**
3355 * Sets the MmTel capability provisioning bitfield (defined by
3356 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3357 * technology specified.
3358 *
3359 * Note: This is a synchronous command and should not be called on UI thread.
3360 */
3361 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3362 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3363 String key = getMmTelProvisioningKey(subId, tech);
3364 editor.putInt(key, newField);
3365 editor.commit();
3366 }
3367
3368 private static String getMmTelProvisioningKey(int subId, int tech) {
3369 // resulting key is provision_ims_mmtel_{subId}_{tech}
3370 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3371 }
3372
3373 /**
3374 * Query CarrierConfig to see if the specified capability requires provisioning for the
3375 * carrier associated with the subscription id.
3376 */
3377 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3378 int capability) {
3379 CarrierConfigManager configManager = new CarrierConfigManager(context);
3380 PersistableBundle c = configManager.getConfigForSubId(subId);
3381 boolean requireUtProvisioning = c.getBoolean(
3382 // By default, this config is true (even if there is no SIM). We also check to make
3383 // sure the subscription needs provisioning here, so we do not need to check for
3384 // the no-SIM case, where we would normally shortcut this to false.
3385 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3386 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3387 false);
3388 boolean requireVoiceVtProvisioning = c.getBoolean(
3389 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3390
3391 // First check to make sure that the capability requires provisioning.
3392 switch (capability) {
3393 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3394 // intentional fallthrough
3395 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3396 if (requireVoiceVtProvisioning) {
3397 // Voice and Video requires provisioning
3398 return true;
3399 }
3400 break;
3401 }
3402 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3403 if (requireUtProvisioning) {
3404 // UT requires provisioning
3405 return true;
3406 }
3407 break;
3408 }
3409 }
3410 return false;
3411 }
3412
3413 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003414 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3416 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3417 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 enforceReadPrivilegedPermission("getImsProvisioningInt");
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003422 int slotId = getSlotIndex(subId);
3423 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3424 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3425 + subId + "' for key:" + key);
3426 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3427 }
3428 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003429 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003430 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3431 + subId + "' for key:" + key);
3432 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003433 } finally {
3434 Binder.restoreCallingIdentity(identity);
3435 }
3436 }
3437
3438 @Override
3439 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003440 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3441 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3442 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003443 enforceReadPrivilegedPermission("getImsProvisioningString");
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 int slotId = getSlotIndex(subId);
3448 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3449 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3450 + subId + "' for key:" + key);
3451 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3452 }
3453 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003454 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3456 + subId + "' for key:" + key);
3457 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
3461 }
3462
3463 @Override
3464 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3466 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3467 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3469 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 int slotId = getSlotIndex(subId);
3474 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3475 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3476 + subId + "' for key:" + key);
3477 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3478 }
3479 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003480 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003481 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3482 + "' for key:" + key);
3483 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
3487 }
3488
3489 @Override
3490 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003491 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3492 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3493 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3495 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003499 int slotId = getSlotIndex(subId);
3500 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3501 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3502 + subId + "' for key:" + key);
3503 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3504 }
3505 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003506 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003507 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3508 + "' for key:" + key);
3509 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003510 } finally {
3511 Binder.restoreCallingIdentity(identity);
3512 }
3513 }
3514
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3516 int slotId = SubscriptionManager.getSlotIndex(subId);
3517 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003518 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 }
3520 return slotId;
3521 }
3522
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003523 private int getSlotIndex(int subId) {
3524 int slotId = SubscriptionManager.getSlotIndex(subId);
3525 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3526 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3527 }
3528 return slotId;
3529 }
3530
Wink Saville36469e72014-06-11 15:17:00 -07003531 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003532 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003533 */
3534 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Harold9042f0b2019-05-21 15:51:27 -07003536 if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q
3537 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3538 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003539 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3540 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 final Phone phone = getPhone(subId);
3545 if (phone != null) {
3546 return phone.getServiceState().getDataNetworkType();
3547 } else {
3548 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3549 }
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003553 }
3554
3555 /**
3556 * Returns the data network type
3557 */
3558 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003559 public int getDataNetworkType(String callingPackage) {
3560 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003561 }
3562
3563 /**
3564 * Returns the data network type for a subId
3565 */
3566 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003567 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003569 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003570 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3571 }
3572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
3576 if (phone != null) {
3577 return phone.getServiceState().getDataNetworkType();
3578 } else {
3579 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3580 }
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003584 }
3585
3586 /**
Wink Saville36469e72014-06-11 15:17:00 -07003587 * Returns the Voice network type for a subId
3588 */
3589 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003590 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003592 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003593 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3594 }
3595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 final Phone phone = getPhone(subId);
3599 if (phone != null) {
3600 return phone.getServiceState().getVoiceNetworkType();
3601 } else {
3602 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003607 }
3608
3609 /**
3610 * @return true if a ICC card is present
3611 */
3612 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003613 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003614 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3615 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003616 }
3617
3618 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003619 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003620 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003622 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 final Phone phone = PhoneFactory.getPhone(slotIndex);
3626 if (phone != null) {
3627 return phone.getIccCard().hasIccCard();
3628 } else {
3629 return false;
3630 }
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003634 }
3635
3636 /**
3637 * Return if the current radio is LTE on CDMA. This
3638 * is a tri-state return value as for a period of time
3639 * the mode may be unknown.
3640 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003641 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003642 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003643 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003645 @Override
3646 public int getLteOnCdmaMode(String callingPackage) {
3647 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003648 }
3649
Sanket Padawe356d7632015-06-22 14:03:32 -07003650 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003651 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003653 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003654 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3655 }
3656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 final long identity = Binder.clearCallingIdentity();
3658 try {
3659 final Phone phone = getPhone(subId);
3660 if (phone == null) {
3661 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3662 } else {
3663 return phone.getLteOnCdmaMode();
3664 }
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003667 }
Wink Saville36469e72014-06-11 15:17:00 -07003668 }
3669
Wink Saville36469e72014-06-11 15:17:00 -07003670 /**
3671 * {@hide}
3672 * Returns Default subId, 0 in the case of single standby.
3673 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003674 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003675 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003676 }
3677
Shishir Agrawala9f32182016-04-12 12:00:16 -07003678 private int getSlotForDefaultSubscription() {
3679 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3680 }
3681
Wink Savilleb564aae2014-10-23 10:18:09 -07003682 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003683 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003684 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003685
Pengquan Menge92a50d2018-09-21 15:54:48 -07003686 private boolean isActiveSubscription(int subId) {
3687 return mSubscriptionController.isActiveSubId(subId);
3688 }
3689
Ihab Awadf2177b72013-11-25 13:33:23 -08003690 /**
3691 * @see android.telephony.TelephonyManager.WifiCallingChoices
3692 */
3693 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694 final long identity = Binder.clearCallingIdentity();
3695 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003696 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3698 getWhenToMakeWifiCallsDefaultPreference());
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003702 }
3703
3704 /**
3705 * @see android.telephony.TelephonyManager.WifiCallingChoices
3706 */
3707 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003716 }
3717
Sailesh Nepald1e68152013-12-12 19:08:02 -08003718 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003719 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003720 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003721 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003722
Jordan Liu4c733742019-02-28 12:03:40 -08003723 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3724 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3725 if (phoneId == -1) {
3726 throw new IllegalArgumentException("Given slot index: " + slotIndex
3727 + " does not correspond to an active phone");
3728 }
3729 return PhoneFactory.getPhone(phoneId);
3730 }
3731
Shishir Agrawal566b7612013-10-28 14:41:00 -07003732 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003733 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3734 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3736 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003738 if (DBG) {
3739 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3740 }
3741 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3742 p2);
3743 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003744
Jordan Liu4c733742019-02-28 12:03:40 -08003745
3746 @Override
3747 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3748 int slotIndex, String callingPackage, String aid, int p2) {
3749 enforceModifyPermission();
3750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3751 if (DBG) {
3752 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3753 }
3754 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3755 callingPackage, aid, p2);
3756 }
3757
3758 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3759 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 if (TextUtils.equals(ISDR_AID, aid)) {
3763 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003764 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3765 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 if (bestComponent == null
3767 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3768 loge("The calling package is not allowed to access ISD-R.");
3769 throw new SecurityException(
3770 "The calling package is not allowed to access ISD-R.");
3771 }
Derek Tan740e1672017-06-27 14:56:27 -07003772 }
Derek Tan740e1672017-06-27 14:56:27 -07003773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003775 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3776 null /* workSource */);
3777 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778 return response;
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
3781 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003782 }
3783
3784 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003785 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003788 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3789 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003791
Jordan Liu4c733742019-02-28 12:03:40 -08003792 @Override
3793 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3794 enforceModifyPermission();
3795 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3796 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3797 channel);
3798 }
3799
3800 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 final long identity = Binder.clearCallingIdentity();
3802 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 if (channel < 0) {
3804 return false;
3805 }
Jordan Liu4c733742019-02-28 12:03:40 -08003806 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3807 null /* workSource */);
3808 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 return success;
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003813 }
3814
3815 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003816 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003817 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3819 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003820 if (DBG) {
3821 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3822 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3823 + p3 + " data=" + data);
3824 }
3825 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3826 command, p1, p2, p3, data);
3827 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003828
Jordan Liu4c733742019-02-28 12:03:40 -08003829 @Override
3830 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3831 int command, int p1, int p2, int p3, String data) {
3832 enforceModifyPermission();
3833 if (DBG) {
3834 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3835 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3836 + p3 + " data=" + data);
3837 }
3838 return iccTransmitApduLogicalChannelWithPermission(
3839 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3840 data);
3841 }
3842
3843 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3844 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003845 final long identity = Binder.clearCallingIdentity();
3846 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003847 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 return "";
3849 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003852 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3853 null /* workSource */);
3854 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 // Append the returned status code to the end of the response payload.
3857 String s = Integer.toHexString(
3858 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3859 if (response.payload != null) {
3860 s = IccUtils.bytesToHexString(response.payload) + s;
3861 }
3862 return s;
3863 } finally {
3864 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003865 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003866 }
Jake Hambye994d462014-02-03 13:10:13 -08003867
Evan Charltonc66da362014-05-16 14:06:40 -07003868 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003869 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3870 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3872 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003873 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003874 if (DBG) {
3875 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3876 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3877 }
3878 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3879 cla, command, p1, p2, p3, data);
3880 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003881
Jordan Liu4c733742019-02-28 12:03:40 -08003882 @Override
3883 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3884 int command, int p1, int p2, int p3, String data) {
3885 enforceModifyPermission();
3886 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3887 if (DBG) {
3888 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3889 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3890 + " data=" + data);
3891 }
3892
3893 return iccTransmitApduBasicChannelWithPermission(
3894 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3895 p2, p3, data);
3896 }
3897
3898 // open APDU basic channel assuming the caller has sufficient permissions
3899 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3900 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3904 && TextUtils.equals(ISDR_AID, data)) {
3905 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003906 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3907 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 if (bestComponent == null
3909 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3910 loge("The calling package is not allowed to select ISD-R.");
3911 throw new SecurityException(
3912 "The calling package is not allowed to select ISD-R.");
3913 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003914 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003915
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003916 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003917 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3918 null /* workSource */);
3919 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 // Append the returned status code to the end of the response payload.
3922 String s = Integer.toHexString(
3923 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3924 if (response.payload != null) {
3925 s = IccUtils.bytesToHexString(response.payload) + s;
3926 }
3927 return s;
3928 } finally {
3929 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003930 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003931 }
3932
3933 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003934 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003935 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3937 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 if (DBG) {
3942 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3943 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3944 }
3945
3946 IccIoResult response =
3947 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3948 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3949 subId);
3950
3951 if (DBG) {
3952 log("Exchange SIM_IO [R]" + response);
3953 }
3954
3955 byte[] result = null;
3956 int length = 2;
3957 if (response.payload != null) {
3958 length = 2 + response.payload.length;
3959 result = new byte[length];
3960 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3961 } else {
3962 result = new byte[length];
3963 }
3964
3965 result[length - 1] = (byte) response.sw2;
3966 result[length - 2] = (byte) response.sw1;
3967 return result;
3968 } finally {
3969 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003970 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003971 }
3972
Nathan Haroldb3014052017-01-25 15:57:32 -08003973 /**
3974 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3975 * on a particular subscription
3976 */
sqianb6e41952018-03-12 14:54:01 -07003977 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3979 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3980 return null;
3981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982
3983 final long identity = Binder.clearCallingIdentity();
3984 try {
3985 if (appType != TelephonyManager.APPTYPE_USIM
3986 && appType != TelephonyManager.APPTYPE_SIM) {
3987 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3988 return null;
3989 }
3990 Object response = sendRequest(
3991 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3992 if (response instanceof String[]) {
3993 return (String[]) response;
3994 }
3995 // Response is an Exception of some kind,
3996 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003997 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998 } finally {
3999 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004000 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004001 }
4002
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004003 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004004 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4006 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4011 if (response.payload == null) {
4012 return "";
4013 }
Evan Charltonc66da362014-05-16 14:06:40 -07004014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 // Append the returned status code to the end of the response payload.
4016 String s = Integer.toHexString(
4017 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4018 s = IccUtils.bytesToHexString(response.payload) + s;
4019 return s;
4020 } finally {
4021 Binder.restoreCallingIdentity(identity);
4022 }
Evan Charltonc66da362014-05-16 14:06:40 -07004023 }
4024
Jake Hambye994d462014-02-03 13:10:13 -08004025 /**
4026 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4027 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4028 *
4029 * @param itemID the ID of the item to read
4030 * @return the NV item as a String, or null on error.
4031 */
4032 @Override
4033 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4036 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037
4038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004041 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4043 return value;
4044 } finally {
4045 Binder.restoreCallingIdentity(identity);
4046 }
Jake Hambye994d462014-02-03 13:10:13 -08004047 }
4048
4049 /**
4050 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4051 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4052 *
4053 * @param itemID the ID of the item to read
4054 * @param itemValue the value to write, as a String
4055 * @return true on success; false on any failure
4056 */
4057 @Override
4058 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004059 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4061 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062
4063 final long identity = Binder.clearCallingIdentity();
4064 try {
4065 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4066 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004067 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4069 return success;
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Jake Hambye994d462014-02-03 13:10:13 -08004073 }
4074
4075 /**
4076 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4077 * Used for device configuration by some CDMA operators.
4078 *
4079 * @param preferredRoamingList byte array containing the new PRL
4080 * @return true on success; false on any failure
4081 */
4082 @Override
4083 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4085 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4090 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4091 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4092 return success;
4093 } finally {
4094 Binder.restoreCallingIdentity(identity);
4095 }
Jake Hambye994d462014-02-03 13:10:13 -08004096 }
4097
4098 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004099 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004100 * Used for device configuration by some CDMA operators.
4101 *
chen xu6dac5ab2018-10-26 17:39:23 -07004102 * @param slotIndex - device slot.
4103 *
Jake Hambye994d462014-02-03 13:10:13 -08004104 * @return true on success; false on any failure
4105 */
4106 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004107 public boolean resetModemConfig(int slotIndex) {
4108 Phone phone = PhoneFactory.getPhone(slotIndex);
4109 if (phone != null) {
4110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4111 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112
chen xu6dac5ab2018-10-26 17:39:23 -07004113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4116 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4117 return success;
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 }
chen xu6dac5ab2018-10-26 17:39:23 -07004122 return false;
4123 }
4124
4125 /**
4126 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4127 *
4128 * @param slotIndex - device slot.
4129 *
4130 * @return true on success; false on any failure
4131 */
4132 @Override
4133 public boolean rebootModem(int slotIndex) {
4134 Phone phone = PhoneFactory.getPhone(slotIndex);
4135 if (phone != null) {
4136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4137 mApp, phone.getSubId(), "rebootModem");
4138
4139 final long identity = Binder.clearCallingIdentity();
4140 try {
4141 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4142 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4143 return success;
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004149 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004150
Svet Ganovb320e182015-04-16 12:30:10 -07004151 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004152 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004154 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004155 return new String[0];
4156 }
4157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158 final long identity = Binder.clearCallingIdentity();
4159 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004160 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 } finally {
4162 Binder.restoreCallingIdentity(identity);
4163 }
Wink Saville36469e72014-06-11 15:17:00 -07004164 }
4165
Brad Ebinger51f743a2017-01-23 13:50:20 -08004166 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004167 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4168 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004169 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004170 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004171 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004175 ImsResolver resolver = PhoneFactory.getImsResolver();
4176 if (resolver == null) {
4177 // may happen if the device does not support IMS.
4178 return;
4179 }
4180 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004184 }
4185
4186 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004187 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4188 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004189 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004190 public void disableIms(int slotId) {
4191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192
4193 final long identity = Binder.clearCallingIdentity();
4194 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004195 ImsResolver resolver = PhoneFactory.getImsResolver();
4196 if (resolver == null) {
4197 // may happen if the device does not support IMS.
4198 return;
4199 }
4200 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 } finally {
4202 Binder.restoreCallingIdentity(identity);
4203 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004204 }
4205
4206 /**
4207 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4208 * feature or {@link null} if the service is not available. If the feature is available, the
4209 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4210 */
4211 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004212 IImsServiceFeatureCallback callback) {
4213 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214
4215 final long identity = Binder.clearCallingIdentity();
4216 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004217 ImsResolver resolver = PhoneFactory.getImsResolver();
4218 if (resolver == null) {
4219 // may happen if the device does not support IMS.
4220 return null;
4221 }
4222 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004226 }
4227
4228 /**
4229 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4230 * feature during emergency calling or {@link null} if the service is not available. If the
4231 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4232 * listener for feature updates.
4233 */
4234 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4235 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236
4237 final long identity = Binder.clearCallingIdentity();
4238 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004239 ImsResolver resolver = PhoneFactory.getImsResolver();
4240 if (resolver == null) {
4241 // may happen if the device does not support IMS.
4242 return null;
4243 }
4244 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004248 }
4249
Brad Ebinger5f64b052017-12-14 14:26:15 -08004250 /**
4251 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004252 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004253 */
4254 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4255 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256
4257 final long identity = Binder.clearCallingIdentity();
4258 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004259 ImsResolver resolver = PhoneFactory.getImsResolver();
4260 if (resolver == null) {
4261 // may happen if the device does not support IMS.
4262 return null;
4263 }
4264 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004268 }
4269
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004270 /**
4271 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004272 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004273 */
4274 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4275 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004279 ImsResolver resolver = PhoneFactory.getImsResolver();
4280 if (resolver == null) {
4281 // may happen if the device does not support IMS.
4282 return null;
4283 }
4284 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004288 }
4289
Brad Ebinger884c07b2018-02-15 16:17:40 -08004290 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004291 * Sets the ImsService Package Name that Telephony will bind to.
4292 *
4293 * @param slotId the slot ID that the ImsService should bind for.
4294 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4295 * ImsService is the device default ImsService.
4296 * @param packageName The package name of the application that contains the ImsService to bind
4297 * to.
4298 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4299 * @hide
4300 */
4301 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004302 int[] subIds = SubscriptionManager.getSubId(slotId);
4303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4304 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4305 "setImsService");
4306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 final long identity = Binder.clearCallingIdentity();
4308 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004309 ImsResolver resolver = PhoneFactory.getImsResolver();
4310 if (resolver == null) {
4311 // may happen if the device does not support IMS.
4312 return false;
4313 }
4314 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4315 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004319 }
4320
4321 /**
4322 * Return the ImsService configuration.
4323 *
4324 * @param slotId The slot that the ImsService is associated with.
4325 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4326 * the device default.
4327 * @return the package name of the ImsService configuration.
4328 */
4329 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004330 int[] subIds = SubscriptionManager.getSubId(slotId);
4331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4332 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4333 "getImsService");
4334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 final long identity = Binder.clearCallingIdentity();
4336 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004337 ImsResolver resolver = PhoneFactory.getImsResolver();
4338 if (resolver == null) {
4339 // may happen if the device does not support IMS.
4340 return "";
4341 }
4342 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004346 }
4347
Wink Saville36469e72014-06-11 15:17:00 -07004348 public void setImsRegistrationState(boolean registered) {
4349 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350
4351 final long identity = Binder.clearCallingIdentity();
4352 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004353 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354 } finally {
4355 Binder.restoreCallingIdentity(identity);
4356 }
Wink Saville36469e72014-06-11 15:17:00 -07004357 }
4358
4359 /**
Stuart Scott54788802015-03-30 13:18:01 -07004360 * Set the network selection mode to automatic.
4361 *
4362 */
4363 @Override
4364 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4366 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367
Pengquan Menge92a50d2018-09-21 15:54:48 -07004368 if (!isActiveSubscription(subId)) {
4369 return;
4370 }
4371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4375 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
Stuart Scott54788802015-03-30 13:18:01 -07004379 }
4380
Pengquan Mengea84e042018-09-20 14:57:26 -07004381 /**
4382 * Ask the radio to connect to the input network and change selection mode to manual.
4383 *
4384 * @param subId the id of the subscription.
4385 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4386 * the operator to attach to.
4387 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4388 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4389 * normal network selection next time.
4390 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004391 */
4392 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004393 public boolean setNetworkSelectionModeManual(
4394 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4396 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004397
4398 if (!isActiveSubscription(subId)) {
4399 return false;
4400 }
4401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004404 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004406 if (DBG) {
4407 log("setNetworkSelectionModeManual: subId: " + subId
4408 + " operator: " + operatorInfo);
4409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004414 }
4415
4416 /**
4417 * Scans for available networks.
4418 */
4419 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004420 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4422 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004423 LocationAccessPolicy.LocationPermissionResult locationResult =
4424 LocationAccessPolicy.checkLocationPermission(mApp,
4425 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4426 .setCallingPackage(callingPackage)
4427 .setCallingPid(Binder.getCallingPid())
4428 .setCallingUid(Binder.getCallingUid())
4429 .setMethod("getCellNetworkScanResults")
4430 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4431 .build());
4432 switch (locationResult) {
4433 case DENIED_HARD:
4434 throw new SecurityException("Not allowed to access scan results -- location");
4435 case DENIED_SOFT:
4436 return null;
4437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004438
Pengquan Menga1bb6272018-09-06 09:59:22 -07004439 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 try {
4441 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004442 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004447 }
4448
4449 /**
yinxub1bed742017-04-17 11:45:04 -07004450 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004451 *
yinxub1bed742017-04-17 11:45:04 -07004452 * @param subId id of the subscription
4453 * @param request contains the radio access networks with bands/channels to scan
4454 * @param messenger callback messenger for scan results or errors
4455 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004456 * @return the id of the requested scan which can be used to stop the scan.
4457 */
4458 @Override
4459 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004460 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4462 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004463 LocationAccessPolicy.LocationPermissionResult locationResult =
4464 LocationAccessPolicy.checkLocationPermission(mApp,
4465 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4466 .setCallingPackage(callingPackage)
4467 .setCallingPid(Binder.getCallingPid())
4468 .setCallingUid(Binder.getCallingUid())
4469 .setMethod("requestNetworkScan")
4470 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4471 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004472 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004473 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004474 if (e != null) {
4475 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4476 throw e;
4477 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004478 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004479 return TelephonyScanManager.INVALID_SCAN_ID;
4480 }
4481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 }
Hall Liu912dfd32019-04-25 14:02:26 -07004483 int callingUid = Binder.getCallingUid();
4484 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 return mNetworkScanRequestTracker.startNetworkScan(
4488 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004489 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
yinxu504e1392017-04-12 16:03:22 -07004493 }
4494
Hall Liub2ac8ef2019-02-28 15:56:23 -08004495 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004496 NetworkScanRequest request, int subId) {
4497 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4498 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4499 boolean hasNetworkScanPermission =
4500 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4501 == PERMISSION_GRANTED;
4502
4503 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4504 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4505 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004506 }
4507
4508 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4509 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004510 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4511 return new SecurityException("Specific channels must not be"
4512 + " scanned without location access.");
4513 }
4514 }
4515 }
4516
Hall Liub2ac8ef2019-02-28 15:56:23 -08004517 return null;
4518 }
4519
yinxu504e1392017-04-12 16:03:22 -07004520 /**
4521 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004522 *
4523 * @param subId id of the subscription
4524 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004525 */
4526 @Override
4527 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4529 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530
Hall Liu912dfd32019-04-25 14:02:26 -07004531 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532 final long identity = Binder.clearCallingIdentity();
4533 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004534 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
yinxu504e1392017-04-12 16:03:22 -07004538 }
4539
4540 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004541 * Get the calculated preferred network type.
4542 * Used for debugging incorrect network type.
4543 *
4544 * @return the preferred network type, defined in RILConstants.java.
4545 */
4546 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004547 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004548 final Phone defaultPhone = getDefaultPhone();
4549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4550 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004551 return RILConstants.PREFERRED_NETWORK_MODE;
4552 }
4553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004557 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
Junda Liu84d15a22014-07-02 11:21:04 -07004561 }
4562
4563 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004564 * Get the preferred network type.
4565 * Used for device configuration by some CDMA operators.
4566 *
4567 * @return the preferred network type, defined in RILConstants.java.
4568 */
4569 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004570 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004571 TelephonyPermissions
4572 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4573 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574
4575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 if (DBG) log("getPreferredNetworkType");
4578 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4579 int networkType = (result != null ? result[0] : -1);
4580 if (DBG) log("getPreferredNetworkType: " + networkType);
4581 return networkType;
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004585 }
4586
4587 /**
4588 * Set the preferred network type.
4589 * Used for device configuration by some CDMA operators.
4590 *
4591 * @param networkType the preferred network type, defined in RILConstants.java.
4592 * @return true on success; false on any failure.
4593 */
4594 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004595 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4597 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598
4599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4602 Boolean success = (Boolean) sendRequest(
4603 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4604 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4605 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004606 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4608 }
4609 return success;
4610 } finally {
4611 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004612 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004613 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004614
4615 /**
Miaoa84611c2019-03-15 09:21:10 +08004616 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004617 *
Miaoa84611c2019-03-15 09:21:10 +08004618 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004619 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004620 * @hide
4621 */
4622 @Override
Miaoa84611c2019-03-15 09:21:10 +08004623 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004626 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 try {
Miaoa84611c2019-03-15 09:21:10 +08004628 if (phone != null) {
4629 return phone.hasMatchedTetherApnSetting();
4630 } else {
4631 return false;
4632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004635 }
Junda Liu475951f2014-11-07 16:45:03 -08004636 }
4637
4638 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004639 * Set mobile data enabled
4640 * Used by the user through settings etc to turn on/off mobile data
4641 *
4642 * @param enable {@code true} turn turn data on, else {@code false}
4643 */
4644 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004645 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4647 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648
4649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 int phoneId = mSubscriptionController.getPhoneId(subId);
4652 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4653 Phone phone = PhoneFactory.getPhone(phoneId);
4654 if (phone != null) {
4655 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004656 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004658 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 }
4660 } finally {
4661 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004662 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004663 }
4664
4665 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004666 * Get the user enabled state of Mobile Data.
4667 *
4668 * TODO: remove and use isUserDataEnabled.
4669 * This can't be removed now because some vendor codes
4670 * calls through ITelephony directly while they should
4671 * use TelephonyManager.
4672 *
4673 * @return true on enabled
4674 */
4675 @Override
4676 public boolean getDataEnabled(int subId) {
4677 return isUserDataEnabled(subId);
4678 }
4679
4680 /**
4681 * Get whether mobile data is enabled per user setting.
4682 *
4683 * There are other factors deciding whether mobile data is actually enabled, but they are
4684 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004685 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004686 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004687 *
4688 * @return {@code true} if data is enabled else {@code false}
4689 */
4690 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004691 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004692 try {
4693 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4694 null);
4695 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4697 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004699
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 int phoneId = mSubscriptionController.getPhoneId(subId);
4703 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4704 Phone phone = PhoneFactory.getPhone(phoneId);
4705 if (phone != null) {
4706 boolean retVal = phone.isUserDataEnabled();
4707 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4708 return retVal;
4709 } else {
4710 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4711 return false;
4712 }
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004715 }
4716 }
4717
4718 /**
4719 * Get whether mobile data is enabled.
4720 *
4721 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4722 * whether mobile data is actually enabled.
4723 *
4724 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4725 *
4726 * @return {@code true} if data is enabled else {@code false}
4727 */
4728 @Override
4729 public boolean isDataEnabled(int subId) {
4730 try {
4731 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4732 null);
4733 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4735 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 int phoneId = mSubscriptionController.getPhoneId(subId);
4741 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4742 Phone phone = PhoneFactory.getPhone(phoneId);
4743 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004744 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4746 return retVal;
4747 } else {
4748 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4749 return false;
4750 }
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004753 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004754 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004755
4756 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004757 public int getCarrierPrivilegeStatus(int subId) {
4758 final Phone phone = getPhone(subId);
4759 if (phone == null) {
4760 loge("getCarrierPrivilegeStatus: Invalid subId");
4761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4762 }
4763 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004764 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004765 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4767 }
4768 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004769 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004770 }
Junda Liu29340342014-07-10 15:23:27 -07004771
4772 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4774 final Phone phone = getPhone(subId);
4775 if (phone == null) {
4776 loge("getCarrierPrivilegeStatus: Invalid subId");
4777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4778 }
4779 UiccProfile profile =
4780 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4781 if (profile == null) {
4782 loge("getCarrierPrivilegeStatus: No UICC");
4783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4784 }
4785 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4786 }
4787
4788 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004789 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4790 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004792 }
4793
4794 int phoneId = SubscriptionManager.getPhoneId(subId);
4795 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004796 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004797 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004798 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4799 }
chen xuf7e9fe82019-05-09 19:31:02 -07004800
4801 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004802 }
4803
4804 @Override
4805 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004806 if (TextUtils.isEmpty(pkgName))
4807 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004808 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4809 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4810 UiccCard card = UiccController.getInstance().getUiccCard(i);
4811 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004812 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004813 continue;
4814 }
4815
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004816 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004817 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4818 break;
4819 }
4820 }
4821
4822 return result;
Junda Liu29340342014-07-10 15:23:27 -07004823 }
Derek Tan89e89d42014-07-08 17:00:10 -07004824
4825 @Override
Junda Liue64de782015-04-16 17:19:16 -07004826 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4827 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4828 loge("phoneId " + phoneId + " is not valid.");
4829 return null;
4830 }
4831 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004832 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004833 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004834 return null ;
4835 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004836 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004837 }
4838
Amith Yamasani6e118872016-02-19 12:53:51 -08004839 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004840 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004841 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004842 List<String> privilegedPackages = new ArrayList<>();
4843 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004844 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4845 // has UICC in that slot.
4846 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004847 if (card.hasCarrierPrivilegeRules()) {
4848 if (packages == null) {
4849 // Only check packages in user 0 for now
4850 packages = pm.getInstalledPackagesAsUser(
4851 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004852 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4853 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004854 }
4855 for (int p = packages.size() - 1; p >= 0; p--) {
4856 PackageInfo pkgInfo = packages.get(p);
4857 if (pkgInfo != null && pkgInfo.packageName != null
4858 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004859 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004860 privilegedPackages.add(pkgInfo.packageName);
4861 }
4862 }
4863 }
4864 }
4865 return privilegedPackages;
4866 }
4867
chen xuf7e9fe82019-05-09 19:31:02 -07004868 @Override
4869 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4870 List<String> privilegedPackages = new ArrayList<>();
4871 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4872 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4873 }
4874 return privilegedPackages;
4875 }
4876
Wink Savilleb564aae2014-10-23 10:18:09 -07004877 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004878 final Phone phone = getPhone(subId);
4879 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004880 if (card == null) {
4881 loge("getIccId: No UICC");
4882 return null;
4883 }
4884 String iccId = card.getIccId();
4885 if (TextUtils.isEmpty(iccId)) {
4886 loge("getIccId: ICC ID is null or empty.");
4887 return null;
4888 }
4889 return iccId;
4890 }
4891
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004892 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004893 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4894 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004895 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4896 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 final long identity = Binder.clearCallingIdentity();
4899 try {
4900 final String iccId = getIccId(subId);
4901 final Phone phone = getPhone(subId);
4902 if (phone == null) {
4903 return false;
4904 }
4905 final String subscriberId = phone.getSubscriberId();
4906
4907 if (DBG_MERGE) {
4908 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4909 + subscriberId + " to " + number);
4910 }
4911
4912 if (TextUtils.isEmpty(iccId)) {
4913 return false;
4914 }
4915
4916 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4917
4918 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4919 if (alphaTag == null) {
4920 editor.remove(alphaTagPrefKey);
4921 } else {
4922 editor.putString(alphaTagPrefKey, alphaTag);
4923 }
4924
4925 // Record both the line number and IMSI for this ICCID, since we need to
4926 // track all merged IMSIs based on line number
4927 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4928 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4929 if (number == null) {
4930 editor.remove(numberPrefKey);
4931 editor.remove(subscriberPrefKey);
4932 } else {
4933 editor.putString(numberPrefKey, number);
4934 editor.putString(subscriberPrefKey, subscriberId);
4935 }
4936
4937 editor.commit();
4938 return true;
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004941 }
Derek Tan7226c842014-07-02 17:42:23 -07004942 }
4943
4944 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004945 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004946 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004948 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004949 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004950 return null;
4951 }
Derek Tan97ebb422014-09-05 16:55:38 -07004952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 final long identity = Binder.clearCallingIdentity();
4954 try {
4955 String iccId = getIccId(subId);
4956 if (iccId != null) {
4957 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4958 if (DBG_MERGE) {
4959 log("getLine1NumberForDisplay returning "
4960 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4961 }
4962 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4965 return null;
4966 } finally {
4967 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004968 }
Derek Tan7226c842014-07-02 17:42:23 -07004969 }
4970
4971 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004972 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004974 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004975 return null;
4976 }
Derek Tan97ebb422014-09-05 16:55:38 -07004977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 final long identity = Binder.clearCallingIdentity();
4979 try {
4980 String iccId = getIccId(subId);
4981 if (iccId != null) {
4982 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4983 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4984 }
4985 return null;
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004988 }
Derek Tan7226c842014-07-02 17:42:23 -07004989 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004990
4991 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004992 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004993 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4994 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004996 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4997 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004998 return null;
4999 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005000
Jordan Liub49b04b2019-05-06 14:45:15 -07005001 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5002 // the process, where TelephonyManager was instantiated.
5003 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005004 final long identity = Binder.clearCallingIdentity();
5005 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005006 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 final TelephonyManager tele = TelephonyManager.from(context);
5008 final SubscriptionManager sub = SubscriptionManager.from(context);
5009
5010 // Figure out what subscribers are currently active
5011 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012
Jordan Liub49b04b2019-05-06 14:45:15 -07005013 // Only consider subs which match the current subId
5014 // This logic can be simplified. See b/131189269 for progress.
5015 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005016 activeSubscriberIds.add(tele.getSubscriberId(subId));
5017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018
5019 // First pass, find a number override for an active subscriber
5020 String mergeNumber = null;
5021 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5022 for (String key : prefs.keySet()) {
5023 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5024 final String subscriberId = (String) prefs.get(key);
5025 if (activeSubscriberIds.contains(subscriberId)) {
5026 final String iccId = key.substring(
5027 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5028 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5029 mergeNumber = (String) prefs.get(numberKey);
5030 if (DBG_MERGE) {
5031 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5032 + " for active subscriber " + subscriberId);
5033 }
5034 if (!TextUtils.isEmpty(mergeNumber)) {
5035 break;
5036 }
5037 }
5038 }
5039 }
5040
5041 // Shortcut when no active merged subscribers
5042 if (TextUtils.isEmpty(mergeNumber)) {
5043 return null;
5044 }
5045
5046 // Second pass, find all subscribers under that line override
5047 final ArraySet<String> result = new ArraySet<>();
5048 for (String key : prefs.keySet()) {
5049 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5050 final String number = (String) prefs.get(key);
5051 if (mergeNumber.equals(number)) {
5052 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5053 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5054 final String subscriberId = (String) prefs.get(subscriberKey);
5055 if (!TextUtils.isEmpty(subscriberId)) {
5056 result.add(subscriberId);
5057 }
5058 }
5059 }
5060 }
5061
5062 final String[] resultArray = result.toArray(new String[result.size()]);
5063 Arrays.sort(resultArray);
5064 if (DBG_MERGE) {
5065 Slog.d(LOG_TAG,
5066 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5067 }
5068 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005071 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005072 }
5073
5074 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005075 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5076 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5077
5078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 final TelephonyManager telephonyManager = mApp.getSystemService(
5081 TelephonyManager.class);
5082 String subscriberId = telephonyManager.getSubscriberId(subId);
5083 if (subscriberId == null) {
5084 if (DBG) {
5085 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5086 + subId);
5087 }
5088 return null;
5089 }
5090
5091 final SubscriptionInfo info = SubscriptionController.getInstance()
5092 .getSubscriptionInfo(subId);
5093 final ParcelUuid groupUuid = info.getGroupUuid();
5094 // If it doesn't belong to any group, return just subscriberId of itself.
5095 if (groupUuid == null) {
5096 return new String[]{subscriberId};
5097 }
5098
5099 // Get all subscriberIds from the group.
5100 final List<String> mergedSubscriberIds = new ArrayList<>();
5101 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5102 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5103 for (SubscriptionInfo subInfo : groupInfos) {
5104 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5105 if (subscriberId != null) {
5106 mergedSubscriberIds.add(subscriberId);
5107 }
5108 }
5109
5110 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5111 } finally {
5112 Binder.restoreCallingIdentity(identity);
5113
5114 }
5115 }
5116
5117 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005118 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005119 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5120 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121
5122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 final Phone phone = getPhone(subId);
5125 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
5128 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005129 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005130
5131 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005132 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005133 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5134 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005135 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136
5137 final long identity = Binder.clearCallingIdentity();
5138 try {
5139 final Phone phone = getPhone(subId);
5140 if (phone == null) {
5141 return false;
5142 }
5143 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5144 cdmaNonRoamingList);
5145 } finally {
5146 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005147 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005148 }
5149
5150 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005151 @Deprecated
5152 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5153 enforceModifyPermission();
5154
5155 int returnValue = 0;
5156 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005157 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005158 if(result.exception == null) {
5159 if (result.result != null) {
5160 byte[] responseData = (byte[])(result.result);
5161 if(responseData.length > oemResp.length) {
5162 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5163 responseData.length + "bytes. Buffer Size is " +
5164 oemResp.length + "bytes.");
5165 }
5166 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5167 returnValue = responseData.length;
5168 }
5169 } else {
5170 CommandException ex = (CommandException) result.exception;
5171 returnValue = ex.getCommandError().ordinal();
5172 if(returnValue > 0) returnValue *= -1;
5173 }
5174 } catch (RuntimeException e) {
5175 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5176 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5177 if(returnValue > 0) returnValue *= -1;
5178 }
5179
5180 return returnValue;
5181 }
5182
5183 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005184 public void setRadioCapability(RadioAccessFamily[] rafs) {
5185 try {
5186 ProxyController.getInstance().setRadioCapability(rafs);
5187 } catch (RuntimeException e) {
5188 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5189 }
5190 }
5191
5192 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005193 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005194 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005195 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005196 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005197 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 final long identity = Binder.clearCallingIdentity();
5200 try {
chen xub97461a2018-10-26 14:17:57 -07005201 TelephonyPermissions
5202 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5203 mApp, phone.getSubId(), "getRadioAccessFamily");
5204 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
chen xub97461a2018-10-26 14:17:57 -07005208 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005209 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005210
5211 @Override
5212 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005213 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005214 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215
5216 final long identity = Binder.clearCallingIdentity();
5217 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005218 ImsManager.getInstance(defaultPhone.getContext(),
5219 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005223 }
5224
5225 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005226 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005229 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005230 return false;
5231 }
Svet Ganovb320e182015-04-16 12:30:10 -07005232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 final long identity = Binder.clearCallingIdentity();
5234 try {
5235 // Check the user preference and the system-level IMS setting. Even if the user has
5236 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5237 // In the long run, we may instead need to check if there exists a connection service
5238 // which can support video calling.
5239 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005240 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 return imsManager.isVtEnabledByPlatform()
5242 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5243 && imsManager.isVtEnabledByUser();
5244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005247 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005248
Andrew Leea1239f22015-03-02 17:44:07 -08005249 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5252 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5253 return false;
5254 }
5255
5256 final long identity = Binder.clearCallingIdentity();
5257 try {
5258 CarrierConfigManager configManager =
5259 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005260 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5262 } finally {
5263 Binder.restoreCallingIdentity(identity);
5264 }
Andrew Leea1239f22015-03-02 17:44:07 -08005265 }
5266
5267 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 public boolean isWorldPhone(int subId, String callingPackage) {
5269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5270 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5271 return false;
5272 }
5273
5274 final long identity = Binder.clearCallingIdentity();
5275 try {
5276 CarrierConfigManager configManager =
5277 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005278 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Andrew Leea1239f22015-03-02 17:44:07 -08005283 }
5284
Andrew Lee9431b832015-03-09 18:46:45 -07005285 @Override
5286 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005287 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005288 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005289 }
5290
5291 @Override
5292 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 final long identity = Binder.clearCallingIdentity();
5294 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005295 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 } finally {
5297 Binder.restoreCallingIdentity(identity);
5298 }
Andrew Lee9431b832015-03-09 18:46:45 -07005299 }
5300
Hall Liuf6668912018-10-31 17:05:23 -07005301 /**
5302 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5303 * support for the feature and device firmware support.
5304 *
5305 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5306 */
5307 @Override
5308 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005310 final Phone phone = getPhone(subscriptionId);
5311 if (phone == null) {
5312 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5313 return false;
5314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005316 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5318 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005319 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 return isCarrierSupported && isDeviceSupported;
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
Hall Liu98187582018-01-22 19:15:32 -08005324 }
5325
Hall Liuf6668912018-10-31 17:05:23 -07005326 /**
5327 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5328 * both also support RTT.
5329 */
5330 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 final long identity = Binder.clearCallingIdentity();
5332 try {
Hall Liuf6668912018-10-31 17:05:23 -07005333 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005334 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005338 }
5339
Sanket Padawe7310cc72015-01-14 09:53:20 -08005340 /**
5341 * Returns the unique device ID of phone, for example, the IMEI for
5342 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5343 *
5344 * <p>Requires Permission:
5345 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5346 */
5347 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005348 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005349 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005350 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005351 return null;
5352 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005353 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005354 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5355 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005356 return null;
5357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358
5359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 return phone.getDeviceId();
5362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005365 }
5366
Ping Sunc67b7c22016-03-02 19:16:45 +08005367 /**
5368 * {@hide}
5369 * Returns the IMS Registration Status on a particular subid
5370 *
5371 * @param subId
5372 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005373 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005374 Phone phone = getPhone(subId);
5375 if (phone != null) {
5376 return phone.isImsRegistered();
5377 } else {
5378 return false;
5379 }
5380 }
5381
Santos Cordon7a1885b2015-02-03 11:15:19 -08005382 @Override
5383 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
5386 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005390 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005391
Tyler Gunnf70ed162019-04-03 15:28:53 -07005392 @Override
5393 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 Phone phone = getPhone(subscriptionId);
5397 if (phone == null) {
5398 return null;
5399 }
5400 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
5404 }
5405
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005406 /**
5407 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005408 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005409 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 Phone phone = getPhone(subId);
5413 if (phone != null) {
5414 return phone.isWifiCallingEnabled();
5415 } else {
5416 return false;
5417 }
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005420 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005421 }
5422
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005423 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005424 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005425 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005426 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 final long identity = Binder.clearCallingIdentity();
5428 try {
5429 Phone phone = getPhone(subId);
5430 if (phone != null) {
5431 return phone.isVideoEnabled();
5432 } else {
5433 return false;
5434 }
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005437 }
5438 }
5439
5440 /**
5441 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5442 * defined in {@link ImsRegistrationImplBase}.
5443 */
5444 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 final long identity = Binder.clearCallingIdentity();
5446 try {
5447 Phone phone = getPhone(subId);
5448 if (phone != null) {
5449 return phone.getImsRegistrationTech();
5450 } else {
5451 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5452 }
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005455 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005456 }
5457
Stuart Scott8eef64f2015-04-08 15:13:54 -07005458 @Override
5459 public void factoryReset(int subId) {
5460 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005461 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5462 return;
5463 }
5464
Svet Ganovcc087f82015-05-12 20:35:54 -07005465 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005466
Svet Ganovcc087f82015-05-12 20:35:54 -07005467 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005468 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5469 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005470 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005471 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005472 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005473 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5474 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005475 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005476 // There has been issues when Sms raw table somehow stores orphan
5477 // fragments. They lead to garbled message when new fragments come
5478 // in and combined with those stale ones. In case this happens again,
5479 // user can reset all network settings which will clean up this table.
5480 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005483 }
5484 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005485
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005486 private void cleanUpSmsRawTable(Context context) {
5487 ContentResolver resolver = context.getContentResolver();
5488 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5489 resolver.delete(uri, null, null);
5490 }
5491
Narayan Kamath1c496c22015-04-16 14:40:19 +01005492 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005493 public String getSimLocaleForSubscriber(int subId) {
5494 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5495 final Phone phone = getPhone(subId);
5496 if (phone == null) {
5497 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005498 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 final long identity = Binder.clearCallingIdentity();
5501 try {
chen xu5d3637b2019-01-21 23:31:38 -08005502 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5503 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005504 if (info == null) {
5505 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5506 return null;
5507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 // Try and fetch the locale from the carrier properties or from the SIM language
5509 // preferences (EF-PL and EF-LI)...
5510 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005512 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5513 if (localeFromDefaultSim != null) {
5514 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5515 if (DBG) log("Using locale from subId: " + subId + " locale: "
5516 + localeFromDefaultSim);
5517 return localeFromDefaultSim.toLanguageTag();
5518 } else {
5519 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 }
5521 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 // The SIM language preferences only store a language (e.g. fr = French), not an
5524 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5525 // the SIM and carrier preferences does not include a country we add the country
5526 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005527 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005529 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 return mccLocale.toLanguageTag();
5531 }
5532
5533 if (DBG) log("No locale found - returning null");
5534 return null;
5535 } finally {
5536 Binder.restoreCallingIdentity(identity);
5537 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005538 }
5539
5540 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005541 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005542 }
5543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 /**
5545 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5546 */
5547 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005548 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005549 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005550
Chenjie Yu1ba97252018-01-11 18:16:20 -08005551 private final ModemActivityInfo mLastModemActivityInfo =
5552 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5553
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005554 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005555 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5556 * representing the state of the modem.
5557 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005558 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5559 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005560 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005561 */
5562 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005563 public void requestModemActivityInfo(ResultReceiver result) {
5564 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005565 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566
5567 final long identity = Binder.clearCallingIdentity();
5568 try {
5569 ModemActivityInfo ret = null;
5570 synchronized (mLastModemActivityInfo) {
5571 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5572 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005573 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005574 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5576 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005577 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5578 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 }
5580 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005581 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5582 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 mLastModemActivityInfo.setIdleTimeMillis(
5584 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5585 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5586 mLastModemActivityInfo.setRxTimeMillis(
5587 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5588 mLastModemActivityInfo.setEnergyUsed(
5589 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5592 mLastModemActivityInfo.getSleepTimeMillis(),
5593 mLastModemActivityInfo.getIdleTimeMillis(),
5594 mLastModemActivityInfo.getTxTimeMillis(),
5595 mLastModemActivityInfo.getRxTimeMillis(),
5596 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 Bundle bundle = new Bundle();
5599 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5600 result.send(0, bundle);
5601 } finally {
5602 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005603 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005604 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005605
Siddharth Rayb8114062018-06-17 15:02:38 -07005606 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5607 // less than total activity duration.
5608 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5609 if (info == null) {
5610 return false;
5611 }
5612 int activityDurationMs =
5613 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5614 int totalTxTimeMs = 0;
5615 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5616 totalTxTimeMs += info.getTxTimeMillis()[i];
5617 }
5618 return (info.isValid()
5619 && (info.getSleepTimeMillis() <= activityDurationMs)
5620 && (info.getIdleTimeMillis() <= activityDurationMs)
5621 && (info.getRxTimeMillis() <= activityDurationMs)
5622 && (totalTxTimeMs <= activityDurationMs));
5623 }
5624
Jack Yu85bd38a2015-11-09 11:34:32 -08005625 /**
5626 * {@hide}
5627 * Returns the service state information on specified subscription.
5628 */
5629 @Override
5630 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005632 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005633 return null;
5634 }
5635
Hall Liuf19c44f2018-11-27 14:38:17 -08005636 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5637 LocationAccessPolicy.checkLocationPermission(mApp,
5638 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5639 .setCallingPackage(callingPackage)
5640 .setCallingPid(Binder.getCallingPid())
5641 .setCallingUid(Binder.getCallingUid())
5642 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005643 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005644 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5645 .build());
5646
5647 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5648 LocationAccessPolicy.checkLocationPermission(mApp,
5649 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5650 .setCallingPackage(callingPackage)
5651 .setCallingPid(Binder.getCallingPid())
5652 .setCallingUid(Binder.getCallingUid())
5653 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005654 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005655 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5656 .build());
5657 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5658 boolean hasFinePermission =
5659 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5660 boolean hasCoarsePermission =
5661 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 final Phone phone = getPhone(subId);
5666 if (phone == null) {
5667 return null;
5668 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005669
Hall Liuf19c44f2018-11-27 14:38:17 -08005670 ServiceState ss = phone.getServiceState();
5671
5672 // Scrub out the location info in ServiceState depending on what level of access
5673 // the caller has.
5674 if (hasFinePermission) return ss;
5675 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5676 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005680 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005681
5682 /**
5683 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5684 *
5685 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5686 * voicemail ringtone.
5687 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5688 * PhoneAccount.
5689 */
5690 @Override
5691 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5695 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005696 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005703 }
5704
5705 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005706 * Sets the per-account voicemail ringtone.
5707 *
5708 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5709 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5710 *
5711 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5712 * voicemail ringtone.
5713 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5714 * PhoneAccount.
5715 */
5716 @Override
5717 public void setVoicemailRingtoneUri(String callingPackage,
5718 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005719 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5721 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005722 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5724 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5725 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727
5728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5731 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005732 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 }
5734 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005737 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005738 }
5739
5740 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005741 * Returns whether vibration is set for voicemail notification in Phone settings.
5742 *
5743 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5744 * voicemail vibration setting.
5745 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5746 */
5747 @Override
5748 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 final long identity = Binder.clearCallingIdentity();
5750 try {
5751 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5752 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005753 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005760 }
5761
Youhan Wange64578a2016-05-02 15:32:42 -07005762 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005763 * Sets the per-account voicemail vibration.
5764 *
5765 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5766 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5767 *
5768 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5769 * voicemail vibration setting.
5770 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5771 * specific PhoneAccount.
5772 */
5773 @Override
5774 public void setVoicemailVibrationEnabled(String callingPackage,
5775 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005776 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5778 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005779 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5781 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5782 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005783 }
5784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 final long identity = Binder.clearCallingIdentity();
5786 try {
5787 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5788 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005789 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 }
5791 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5792 } finally {
5793 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005794 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005795 }
5796
5797 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005798 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5799 *
5800 * @throws SecurityException if the caller does not have the required permission
5801 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005802 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005803 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005804 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005805 }
5806
5807 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005808 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5809 * permission.
5810 *
5811 * @throws SecurityException if the caller does not have the required permission
5812 */
5813 private void enforceSendSmsPermission() {
5814 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5815 }
5816
5817 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005818 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005819 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005820 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005821 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005822 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 final long identity = Binder.clearCallingIdentity();
5824 try {
5825 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005826 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 if (componentName == null) {
5828 throw new SecurityException(
5829 "Caller not current active visual voicemail package[null]");
5830 }
5831 String vvmPackage = componentName.getPackageName();
5832 if (!callingPackage.equals(vvmPackage)) {
5833 throw new SecurityException("Caller not current active visual voicemail package["
5834 + vvmPackage + "]");
5835 }
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005838 }
5839 }
5840
5841 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005842 * Return the application ID for the app type.
5843 *
5844 * @param subId the subscription ID that this request applies to.
5845 * @param appType the uicc app type.
5846 * @return Application ID for specificied app type, or null if no uicc.
5847 */
5848 @Override
5849 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005850 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005851 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852
5853 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005854 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 if (phone == null) {
5856 return null;
5857 }
5858 String aid = null;
5859 try {
5860 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5861 .getApplicationByType(appType).getAid();
5862 } catch (Exception e) {
5863 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5864 }
5865 return aid;
5866 } finally {
5867 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005868 }
Youhan Wange64578a2016-05-02 15:32:42 -07005869 }
5870
Youhan Wang4001d252016-05-11 10:29:41 -07005871 /**
5872 * Return the Electronic Serial Number.
5873 *
5874 * @param subId the subscription ID that this request applies to.
5875 * @return ESN or null if error.
5876 */
5877 @Override
5878 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005879 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005880 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881
5882 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005883 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 if (phone == null) {
5885 return null;
5886 }
5887 String esn = null;
5888 try {
5889 esn = phone.getEsn();
5890 } catch (Exception e) {
5891 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5892 }
5893 return esn;
5894 } finally {
5895 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005896 }
Youhan Wang4001d252016-05-11 10:29:41 -07005897 }
5898
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005899 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005900 * Return the Preferred Roaming List Version.
5901 *
5902 * @param subId the subscription ID that this request applies to.
5903 * @return PRLVersion or null if error.
5904 */
5905 @Override
5906 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005907 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005908 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909
5910 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005911 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 if (phone == null) {
5913 return null;
5914 }
5915 String cdmaPrlVersion = null;
5916 try {
5917 cdmaPrlVersion = phone.getCdmaPrlVersion();
5918 } catch (Exception e) {
5919 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5920 }
5921 return cdmaPrlVersion;
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005924 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005925 }
5926
5927 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005928 * Get snapshot of Telephony histograms
5929 * @return List of Telephony histograms
5930 * @hide
5931 */
5932 @Override
5933 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5935 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936
5937 final long identity = Binder.clearCallingIdentity();
5938 try {
5939 return RIL.getTelephonyRILTimingHistograms();
5940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005943 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005944
5945 /**
5946 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005947 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5948 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005949 * Require system privileges. In the future we may add this to carrier APIs.
5950 *
Michele Berionne482f8202018-11-27 18:57:59 -08005951 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005952 */
5953 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005954 @TelephonyManager.SetCarrierRestrictionResult
5955 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005956 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005957 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005958
Michele Berionne482f8202018-11-27 18:57:59 -08005959 if (carrierRestrictionRules == null) {
5960 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005961 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 final long identity = Binder.clearCallingIdentity();
5964 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005965 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005966 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005970 }
5971
5972 /**
5973 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005974 * Get the allowed carrier list and the excluded carrier list, including the priority between
5975 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005976 * Require system privileges. In the future we may add this to carrier APIs.
5977 *
Michele Berionne482f8202018-11-27 18:57:59 -08005978 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005979 */
5980 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005981 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005982 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984
5985 final long identity = Binder.clearCallingIdentity();
5986 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005987 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5988 if (response instanceof CarrierRestrictionRules) {
5989 return (CarrierRestrictionRules) response;
5990 }
5991 // Response is an Exception of some kind,
5992 // which is signalled to the user as a NULL retval
5993 return null;
5994 } catch (Exception e) {
5995 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5996 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006000 }
6001
fionaxu59545b42016-05-25 15:53:37 -07006002 /**
6003 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6004 * @param subId the subscription ID that this action applies to.
6005 * @param enabled control enable or disable metered apns.
6006 * {@hide}
6007 */
6008 @Override
6009 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6010 enforceModifyPermission();
6011 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012
6013 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006014 if (phone == null) {
6015 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6016 return;
6017 }
6018 try {
6019 phone.carrierActionSetMeteredApnsEnabled(enabled);
6020 } catch (Exception e) {
6021 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006024 }
6025 }
6026
6027 /**
6028 * Action set from carrier signalling broadcast receivers to enable/disable radio
6029 * @param subId the subscription ID that this action applies to.
6030 * @param enabled control enable or disable radio.
6031 * {@hide}
6032 */
6033 @Override
6034 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6035 enforceModifyPermission();
6036 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037
6038 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006039 if (phone == null) {
6040 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6041 return;
6042 }
6043 try {
6044 phone.carrierActionSetRadioEnabled(enabled);
6045 } catch (Exception e) {
6046 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 } finally {
6048 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006049 }
6050 }
6051
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006052 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006053 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6054 * network status based on which carrier apps could apply actions accordingly,
6055 * enable/disable default url handler for example.
6056 *
6057 * @param subId the subscription ID that this action applies to.
6058 * @param report control start/stop reporting the default network status.
6059 * {@hide}
6060 */
6061 @Override
6062 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6063 enforceModifyPermission();
6064 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065
6066 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006067 if (phone == null) {
6068 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6069 return;
6070 }
6071 try {
6072 phone.carrierActionReportDefaultNetworkStatus(report);
6073 } catch (Exception e) {
6074 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 } finally {
6076 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006077 }
6078 }
6079
6080 /**
fionaxud9622282017-07-17 17:51:30 -07006081 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6082 * @param subId the subscription ID that this action applies to.
6083 * {@hide}
6084 */
6085 @Override
6086 public void carrierActionResetAll(int subId) {
6087 enforceModifyPermission();
6088 final Phone phone = getPhone(subId);
6089 if (phone == null) {
6090 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6091 return;
6092 }
6093 try {
6094 phone.carrierActionResetAll();
6095 } catch (Exception e) {
6096 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6097 }
6098 }
6099
6100 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006101 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6102 * bug report is being generated.
6103 */
6104 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006105 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006106 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6107 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006108 writer.println("Permission Denial: can't dump Phone from pid="
6109 + Binder.getCallingPid()
6110 + ", uid=" + Binder.getCallingUid()
6111 + "without permission "
6112 + android.Manifest.permission.DUMP);
6113 return;
6114 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006115 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006116 }
Jack Yueb89b242016-06-22 13:27:47 -07006117
Brad Ebingerdac2f002018-04-03 15:17:52 -07006118 @Override
6119 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6120 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6121 throws RemoteException {
6122 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6123 }
6124
Jack Yueb89b242016-06-22 13:27:47 -07006125 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006126 * Get aggregated video call data usage since boot.
6127 *
6128 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6129 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006130 * {@hide}
6131 */
6132 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006133 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006134 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6135 null);
6136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 final long identity = Binder.clearCallingIdentity();
6138 try {
6139 // NetworkStatsService keeps tracking the active network interface and identity. It
6140 // records the delta with the corresponding network identity.
6141 // We just return the total video call data usage snapshot since boot.
6142 Phone phone = getPhone(subId);
6143 if (phone != null) {
6144 return phone.getVtDataUsage(perUidStats);
6145 }
6146 return null;
6147 } finally {
6148 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006149 }
Jack Yueb89b242016-06-22 13:27:47 -07006150 }
Jack Yu75ab2952016-07-08 14:29:33 -07006151
6152 /**
6153 * Policy control of data connection. Usually used when data limit is passed.
6154 * @param enabled True if enabling the data, otherwise disabling.
6155 * @param subId Subscription index
6156 * {@hide}
6157 */
6158 @Override
6159 public void setPolicyDataEnabled(boolean enabled, int subId) {
6160 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161
6162 final long identity = Binder.clearCallingIdentity();
6163 try {
6164 Phone phone = getPhone(subId);
6165 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006166 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 }
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006170 }
6171 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006172
6173 /**
6174 * Get Client request stats
6175 * @return List of Client Request Stats
6176 * @hide
6177 */
6178 @Override
6179 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006181 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006182 return null;
6183 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006184 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 if (phone != null) {
6189 return phone.getClientRequestStats();
6190 }
6191
6192 return null;
6193 } finally {
6194 Binder.restoreCallingIdentity(identity);
6195 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006196 }
6197
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006198 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006199 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006200 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006201 }
Jack Yueb4124c2017-02-16 15:32:43 -08006202
6203 /**
Grace Chen70990072017-03-24 17:21:30 -07006204 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006205 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006206 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006207 * @param state State of SIM (power down, power up, pass through)
6208 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6209 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6210 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006211 *
6212 **/
6213 @Override
Grace Chen70990072017-03-24 17:21:30 -07006214 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006215 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006216 Phone phone = PhoneFactory.getPhone(slotIndex);
6217
vagdeviaf9a5b92018-08-15 16:01:53 -07006218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006223 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 }
6225 } finally {
6226 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006227 }
6228 }
Shuo Qiandd210312017-04-12 22:11:33 +00006229
Tyler Gunn65d45c22017-06-05 11:22:26 -07006230 private boolean isUssdApiAllowed(int subId) {
6231 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006232 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006233 if (configManager == null) {
6234 return false;
6235 }
6236 PersistableBundle pb = configManager.getConfigForSubId(subId);
6237 if (pb == null) {
6238 return false;
6239 }
6240 return pb.getBoolean(
6241 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6242 }
6243
Shuo Qiandd210312017-04-12 22:11:33 +00006244 /**
6245 * Check if phone is in emergency callback mode
6246 * @return true if phone is in emergency callback mode
6247 * @param subId sub id
6248 */
goneil9c5f4872017-12-05 14:07:56 -08006249 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006250 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006251 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006252 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253
6254 final long identity = Binder.clearCallingIdentity();
6255 try {
6256 if (phone != null) {
6257 return phone.isInEcm();
6258 } else {
6259 return false;
6260 }
6261 } finally {
6262 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006263 }
6264 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006265
6266 /**
6267 * Get the current signal strength information for the given subscription.
6268 * Because this information is not updated when the device is in a low power state
6269 * it should not be relied-upon to be current.
6270 * @param subId Subscription index
6271 * @return the most recent cached signal strength info from the modem
6272 */
6273 @Override
6274 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 Phone p = getPhone(subId);
6278 if (p == null) {
6279 return null;
6280 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 return p.getSignalStrength();
6283 } finally {
6284 Binder.restoreCallingIdentity(identity);
6285 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006286 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006287
Pengquan Meng77b7f132018-08-22 14:49:57 -07006288 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006289 * Get the current modem radio state for the given slot.
6290 * @param slotIndex slot index.
6291 * @param callingPackage the name of the package making the call.
6292 * @return the current radio power state from the modem
6293 */
6294 @Override
6295 public int getRadioPowerState(int slotIndex, String callingPackage) {
6296 Phone phone = PhoneFactory.getPhone(slotIndex);
6297 if (phone != null) {
6298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6299 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6300 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6301 }
6302
6303 final long identity = Binder.clearCallingIdentity();
6304 try {
6305 return phone.getRadioPowerState();
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
6309 }
6310 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6311 }
6312
6313 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006314 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6315 *
6316 * <p>Requires one of the following permissions:
6317 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6318 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6319 * privileges.
6320 *
6321 * @param subId subscription id
6322 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6323 * {@code false}.
6324 */
6325 @Override
6326 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006327 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6328 null /* message */);
6329
Pengquan Menga1bb6272018-09-06 09:59:22 -07006330 boolean isEnabled = false;
6331 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006332 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006333 Phone phone = getPhone(subId);
6334 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006335 } catch (Exception e) {
6336 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6337 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006338 } finally {
6339 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006340 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006341 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006342 }
6343
6344
6345 /**
6346 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6347 *
6348 * <p> Requires permission:
6349 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6350 * privileges.
6351 *
6352 * @param subId subscription id
6353 * @param isEnabled {@code true} means enable, {@code false} means disable.
6354 */
6355 @Override
6356 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6358 mApp, subId, "setDataRoamingEnabled");
6359
Pengquan Menga1bb6272018-09-06 09:59:22 -07006360 final long identity = Binder.clearCallingIdentity();
6361 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006362 Phone phone = getPhone(subId);
6363 if (phone != null) {
6364 phone.setDataRoamingEnabled(isEnabled);
6365 }
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006368 }
6369 }
6370
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006371 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006372 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006373 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6374 mApp, subId, "isManualNetworkSelectionAllowed");
6375
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006376 boolean isAllowed = true;
6377 final long identity = Binder.clearCallingIdentity();
6378 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006379 Phone phone = getPhone(subId);
6380 if (phone != null) {
6381 isAllowed = phone.isCspPlmnEnabled();
6382 }
6383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
6386 return isAllowed;
6387 }
6388
6389 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006390 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006391 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006392 try {
6393 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006394 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006395 } catch (SecurityException e) {
6396 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6397 // has carrier privileges on an active UICC
6398 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6399 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006400 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006401 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006402 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006403
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006406 UiccController uiccController = UiccController.getInstance();
6407 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006408 if (hasReadPermission) {
6409 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006410 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006411
6412 // Remove private info if the caller doesn't have access
6413 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6414 for (UiccCardInfo cardInfo : cardInfos) {
6415 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6416 // is available
6417 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6418 if (card == null || card.getUiccProfile() == null) {
6419 // assume no access if the card or profile is unavailable
6420 filteredInfos.add(cardInfo.getUnprivileged());
6421 continue;
6422 }
6423 UiccProfile profile = card.getUiccProfile();
6424 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6425 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6426 filteredInfos.add(cardInfo);
6427 } else {
6428 filteredInfos.add(cardInfo.getUnprivileged());
6429 }
6430 }
6431 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
6435 }
6436
6437 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006438 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006439 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6444 if (slots == null) {
6445 Rlog.i(LOG_TAG, "slots is null.");
6446 return null;
6447 }
6448
6449 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6450 for (int i = 0; i < slots.length; i++) {
6451 UiccSlot slot = slots[i];
6452 if (slot == null) {
6453 continue;
6454 }
6455
Jordan Liu7be7e652019-05-06 18:55:02 +00006456 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 UiccCard card = slot.getUiccCard();
6458 if (card != null) {
6459 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006460 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 cardId = slot.getIccId();
6462 }
6463
6464 int cardState = 0;
6465 switch (slot.getCardState()) {
6466 case CARDSTATE_ABSENT:
6467 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6468 break;
6469 case CARDSTATE_PRESENT:
6470 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6471 break;
6472 case CARDSTATE_ERROR:
6473 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6474 break;
6475 case CARDSTATE_RESTRICTED:
6476 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6477 break;
6478 default:
6479 break;
6480
6481 }
6482
6483 infos[i] = new UiccSlotInfo(
6484 slot.isActive(),
6485 slot.isEuicc(),
6486 cardId,
6487 cardState,
6488 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006489 slot.isExtendedApduSupported(),
6490 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 }
6492 return infos;
6493 } finally {
6494 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006495 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006496 }
6497
6498 @Override
6499 public boolean switchSlots(int[] physicalSlots) {
6500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501
6502 final long identity = Binder.clearCallingIdentity();
6503 try {
6504 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6505 } finally {
6506 Binder.restoreCallingIdentity(identity);
6507 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006508 }
Jack Yu4c988042018-02-27 15:30:01 -08006509
6510 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006511 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006512 final long identity = Binder.clearCallingIdentity();
6513 try {
6514 return UiccController.getInstance().getCardIdForDefaultEuicc();
6515 } finally {
6516 Binder.restoreCallingIdentity(identity);
6517 }
6518 }
6519
6520 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006521 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6522 enforceModifyPermission();
6523 final Phone phone = getPhone(subId);
6524 if (phone == null) {
6525 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6526 return;
6527 }
6528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 final long identity = Binder.clearCallingIdentity();
6530 try {
6531 phone.setRadioIndicationUpdateMode(filters, mode);
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
Jack Yu4c988042018-02-27 15:30:01 -08006535 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006536
6537 /**
goneil47ffb6e2018-04-06 15:40:58 -07006538 * A test API to reload the UICC profile.
6539 *
6540 * <p>Requires that the calling app has permission
6541 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6542 * @hide
6543 */
6544 @Override
6545 public void refreshUiccProfile(int subId) {
6546 enforceModifyPermission();
6547
6548 final long identity = Binder.clearCallingIdentity();
6549 try {
6550 Phone phone = getPhone(subId);
6551 if (phone == null) {
6552 return;
6553 }
6554 UiccCard uiccCard = phone.getUiccCard();
6555 if (uiccCard == null) {
6556 return;
6557 }
6558 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6559 if (uiccProfile == null) {
6560 return;
6561 }
6562 uiccProfile.refresh();
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
6566 }
6567
6568 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006569 * Returns false if the mobile data is disabled by default, otherwise return true.
6570 */
6571 private boolean getDefaultDataEnabled() {
6572 return "true".equalsIgnoreCase(
6573 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6574 }
6575
6576 /**
6577 * Returns true if the data roaming is enabled by default, i.e the system property
6578 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6579 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6580 */
6581 private boolean getDefaultDataRoamingEnabled(int subId) {
6582 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006583 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006584 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6585 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6586 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6587 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6588 return isDataRoamingEnabled;
6589 }
6590
6591 /**
6592 * Returns the default network type for the given {@code subId}, if the default network type is
6593 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6594 */
6595 private int getDefaultNetworkType(int subId) {
6596 return Integer.parseInt(
6597 TelephonyManager.getTelephonyProperty(
6598 mSubscriptionController.getPhoneId(subId),
6599 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6600 String.valueOf(Phone.PREFERRED_NT_MODE)));
6601 }
fionaxua13278b2018-03-21 00:08:13 -07006602
6603 @Override
6604 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006605 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607
6608 final long identity = Binder.clearCallingIdentity();
6609 try {
6610 final Phone phone = getPhone(subId);
6611 if (phone == null) {
6612 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6613 return;
6614 }
chen xueaba88a2019-03-15 13:15:10 -07006615 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6616 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 } finally {
6618 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006619 }
fionaxua13278b2018-03-21 00:08:13 -07006620 }
6621
6622 @Override
6623 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006624 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625
6626 final long identity = Binder.clearCallingIdentity();
6627 try {
6628 final Phone phone = getPhone(subId);
6629 if (phone == null) {
6630 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6631 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6632 }
6633 return phone.getCarrierIdListVersion();
6634 } finally {
6635 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006636 }
fionaxua13278b2018-03-21 00:08:13 -07006637 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006638
6639 @Override
6640 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6642 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6643 return -1;
6644 }
6645
6646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6649 } finally {
6650 Binder.restoreCallingIdentity(identity);
6651 }
6652 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006653
6654 @Override
6655 public int getCdmaRoamingMode(int subId) {
6656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6657 mApp, subId, "getCdmaRoamingMode");
6658
6659 final long identity = Binder.clearCallingIdentity();
6660 try {
6661 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6662 } finally {
6663 Binder.restoreCallingIdentity(identity);
6664 }
6665 }
6666
6667 @Override
6668 public boolean setCdmaRoamingMode(int subId, int mode) {
6669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6670 mApp, subId, "setCdmaRoamingMode");
6671
6672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6675 } finally {
6676 Binder.restoreCallingIdentity(identity);
6677 }
6678 }
6679
6680 @Override
6681 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6683 mApp, subId, "setCdmaSubscriptionMode");
6684
6685 final long identity = Binder.clearCallingIdentity();
6686 try {
6687 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
6690 }
6691 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006692
6693 private void ensureUserRunning(int userId) {
6694 if (!mUserManager.isUserRunning(userId)) {
6695 throw new IllegalStateException("User " + userId + " does not exist or not running");
6696 }
6697 }
6698
6699 /**
6700 * Returns a list of SMS apps on a given user.
6701 *
6702 * Only the shell user (UID 2000 or 0) can call it.
6703 * Target user must be running.
6704 */
6705 @Override
6706 public String[] getSmsApps(int userId) {
6707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6708 ensureUserRunning(userId);
6709
6710 final Collection<SmsApplicationData> apps =
6711 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6712
6713 String[] ret = new String[apps.size()];
6714 int i = 0;
6715 for (SmsApplicationData app : apps) {
6716 ret[i++] = app.mPackageName;
6717 }
6718 return ret;
6719 }
6720
6721 /**
6722 * Returns the default SMS app package name on a given user.
6723 *
6724 * Only the shell user (UID 2000 or 0) can call it.
6725 * Target user must be running.
6726 */
6727 @Override
6728 public String getDefaultSmsApp(int userId) {
6729 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6730 ensureUserRunning(userId);
6731
6732 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6733 /* updateIfNeeded= */ true, userId);
6734 return cn == null ? null : cn.getPackageName();
6735 }
6736
6737 /**
6738 * Set a package as the default SMS app on a given user.
6739 *
6740 * Only the shell user (UID 2000 or 0) can call it.
6741 * Target user must be running.
6742 */
6743 @Override
6744 public void setDefaultSmsApp(int userId, String packageName) {
6745 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6746 ensureUserRunning(userId);
6747
6748 boolean found = false;
6749 for (String pkg : getSmsApps(userId)) {
6750 if (TextUtils.equals(packageName, pkg)) {
6751 found = true;
6752 break;
6753 }
6754 }
6755 if (!found) {
6756 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6757 }
6758
6759 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6760 }
sqianc5eccab2018-10-19 18:46:41 -07006761
6762 @Override
sqian8c685422019-02-22 15:55:18 -08006763 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006764 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006766 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006767 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6768 }
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
sqian854d44b2018-12-12 16:48:18 -08006771 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6772 for (Phone phone: PhoneFactory.getPhones()) {
6773 if (phone.getEmergencyNumberTracker() != null
6774 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6775 emergencyNumberListInternal.put(
6776 phone.getSubId(),
6777 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6778 }
sqian11b7a0e2018-12-05 18:48:28 -08006779 }
sqian854d44b2018-12-12 16:48:18 -08006780 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
sqianc5eccab2018-10-19 18:46:41 -07006784 }
6785
6786 @Override
sqian8c685422019-02-22 15:55:18 -08006787 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006788 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006789 if (!exactMatch) {
6790 TelephonyPermissions
6791 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006792 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006793 }
6794 final long identity = Binder.clearCallingIdentity();
6795 try {
sqian854d44b2018-12-12 16:48:18 -08006796 for (Phone phone: PhoneFactory.getPhones()) {
6797 if (phone.getEmergencyNumberTracker() != null
6798 && phone.getEmergencyNumberTracker() != null) {
6799 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6800 number, exactMatch)) {
6801 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006802 }
6803 }
sqian11b7a0e2018-12-05 18:48:28 -08006804 }
6805 return false;
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
6809 }
6810
sqianf4ca7ed2019-01-15 18:32:07 -08006811 /**
6812 * Update emergency number list for test mode.
6813 */
6814 @Override
6815 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6816 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6817 "updateEmergencyNumberListTestMode");
6818
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 for (Phone phone: PhoneFactory.getPhones()) {
6822 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6823 if (tracker != null) {
6824 tracker.executeEmergencyNumberTestModeCommand(action, num);
6825 }
6826 }
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
6829 }
6830 }
6831
6832 /**
6833 * Get the full emergency number list for test mode.
6834 */
6835 @Override
6836 public List<String> getEmergencyNumberListTestMode() {
6837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6838 "getEmergencyNumberListTestMode");
6839
6840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 Set<String> emergencyNumbers = new HashSet<>();
6843 for (Phone phone: PhoneFactory.getPhones()) {
6844 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6845 if (tracker != null) {
6846 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6847 emergencyNumbers.add(num.getNumber());
6848 }
6849 }
6850 }
6851 return new ArrayList<>(emergencyNumbers);
6852 } finally {
6853 Binder.restoreCallingIdentity(identity);
6854 }
6855 }
6856
chen xud6b45bd2018-10-30 22:27:10 -07006857 @Override
6858 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6859 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6860 Phone phone = getPhone(subId);
6861 if (phone == null) {
6862 return null;
6863 }
6864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 UiccProfile profile = UiccController.getInstance()
6867 .getUiccProfileForPhone(phone.getPhoneId());
6868 if (profile != null) {
6869 return profile.getCertsFromCarrierPrivilegeAccessRules();
6870 }
6871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
6874 return null;
6875 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006876
6877 /**
6878 * Enable or disable a modem stack.
6879 */
6880 @Override
6881 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6882 enforceModifyPermission();
6883
6884 final long identity = Binder.clearCallingIdentity();
6885 try {
6886 Phone phone = PhoneFactory.getPhone(slotIndex);
6887 if (phone == null) {
6888 return false;
6889 } else {
6890 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6891 }
6892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
6895 }
Michelecea4cf22018-12-21 15:00:11 -08006896
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006897 /**
6898 * Whether a modem stack is enabled or not.
6899 */
6900 @Override
6901 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6902 Phone phone = PhoneFactory.getPhone(slotIndex);
6903 if (phone == null) return false;
6904
6905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6906 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6907 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6908 }
6909
6910 final long identity = Binder.clearCallingIdentity();
6911 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006912 try {
6913 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6914 } catch (NoSuchElementException ex) {
6915 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6916 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919 }
6920 }
6921
Michelecea4cf22018-12-21 15:00:11 -08006922 @Override
Michele0ea7d782019-03-19 14:58:42 -07006923 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006924 enforceModifyPermission();
6925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006929 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006930 .commit();
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
6933 }
6934 }
6935
6936 @Override
Michele0ea7d782019-03-19 14:58:42 -07006937 @TelephonyManager.IsMultiSimSupportedResult
6938 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006940 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6941 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006942 }
Michelecea4cf22018-12-21 15:00:11 -08006943
6944 final long identity = Binder.clearCallingIdentity();
6945 try {
Michele0ea7d782019-03-19 14:58:42 -07006946 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
6950 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006951
Michele0ea7d782019-03-19 14:58:42 -07006952 @TelephonyManager.IsMultiSimSupportedResult
6953 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006954 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6955 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6956 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006957 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6958 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006959 }
6960 // Check if the hardware supports multisim functionality. If usage of multisim is not
6961 // supported by the modem, indicate that it is restricted.
6962 PhoneCapability staticCapability =
6963 mPhoneConfigurationManager.getStaticPhoneCapability();
6964 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006965 loge("isMultiSimSupportedInternal: no static configuration available");
6966 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006967 }
6968 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006969 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6970 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006971 }
6972 // Check if support of multiple SIMs is restricted by carrier
6973 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006974 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006975 }
6976
Michele0ea7d782019-03-19 14:58:42 -07006977 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006978 }
6979
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006980 /**
6981 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006982 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6983 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6984 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006985 * @param numOfSims number of active sims we want to switch to
6986 */
6987 @Override
6988 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006989 if (numOfSims == 1) {
6990 enforceModifyPermission();
6991 } else {
6992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6993 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6994 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006995 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006996
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006997 try {
Michele30b57b22019-03-01 12:01:14 -08006998 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006999 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007000 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7001 return;
7002 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007003 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
7007 }
7008
7009 /**
chen xub4baa772019-04-03 10:23:41 -07007010 * Get whether making changes to modem configurations will trigger reboot.
7011 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007012 */
7013 @Override
chen xub4baa772019-04-03 10:23:41 -07007014 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7016 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7017 return false;
7018 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007019 final long identity = Binder.clearCallingIdentity();
7020 try {
7021 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7022 } finally {
7023 Binder.restoreCallingIdentity(identity);
7024 }
7025 }
7026
Nathan Harold29f5f052019-02-15 13:41:57 -08007027 private void updateModemStateMetrics() {
7028 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7029 // TODO: check the state for each modem if the api is ready.
7030 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7031 }
7032
Pengquan Meng3889a572019-01-23 11:16:29 -08007033 @Override
7034 public int[] getSlotsMapping() {
7035 enforceReadPrivilegedPermission("getSlotsMapping");
7036
7037 final long identity = Binder.clearCallingIdentity();
7038 try {
7039 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7040 // All logical slots should have a mapping to a physical slot.
7041 int[] logicalSlotsMapping = new int[phoneCount];
7042 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7043 for (int i = 0; i < slotInfos.length; i++) {
7044 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7045 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7046 }
7047 }
7048 return logicalSlotsMapping;
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
7051 }
7052 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007053
7054 /**
7055 * Get the IRadio HAL Version
7056 */
7057 @Override
7058 public int getRadioHalVersion() {
7059 Phone phone = getDefaultPhone();
7060 if (phone == null) return -1;
7061 HalVersion hv = phone.getHalVersion();
7062 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7063 return hv.major * 100 + hv.minor;
7064 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007065
7066 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007067 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7068 * corresponding network requests on a subId.
7069 *
7070 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007071 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007072 * 2) APN is un-metered for this subscription, or
7073 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7074 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7075 *
7076 * @return whether data is allowed for a apn type.
7077 *
7078 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007079 */
7080 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007081 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007083 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7084 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007085 }
7086
7087 // Now that all security checks passes, perform the operation as ourselves.
7088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 Phone phone = getPhone(subId);
7091 if (phone == null) return false;
7092
Jack Yu41407ee2019-05-13 16:54:09 -07007093 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007094 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
7098 }
7099
7100 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007101 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007102 enforceReadPrivilegedPermission("isApnMetered");
7103
7104 // Now that all security checks passes, perform the operation as ourselves.
7105 final long identity = Binder.clearCallingIdentity();
7106 try {
7107 Phone phone = getPhone(subId);
7108 if (phone == null) return true; // By default return true.
7109
Jack Yu41407ee2019-05-13 16:54:09 -07007110 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007111 } finally {
7112 Binder.restoreCallingIdentity(identity);
7113 }
7114 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007115
7116 @Override
7117 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7118 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7119 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7120 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7121 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7122 }
7123 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7124 Intent intent = new Intent();
7125 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7126 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7127 // Bring up choose default SMS subscription dialog right now
7128 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7129 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7130 mApp.startActivity(intent);
7131 }
chen xud5ca2d52019-05-28 15:20:57 -07007132
7133 @Override
7134 public String getMmsUAProfUrl(int subId) {
7135 //TODO investigate if this API should require proper permission check in R b/133791609
7136 final long identity = Binder.clearCallingIdentity();
7137 try {
7138 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7139 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
7143 }
7144
7145 @Override
7146 public String getMmsUserAgent(int subId) {
7147 //TODO investigate if this API should require proper permission check in R b/133791609
7148 final long identity = Binder.clearCallingIdentity();
7149 try {
7150 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7151 .getString(com.android.internal.R.string.config_mms_user_agent);
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154 }
7155 }
Jack Yub07d4972019-05-28 16:12:25 -07007156
7157 @Override
7158 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7159 enforceModifyPermission();
7160
7161 // Now that all security checks passes, perform the operation as ourselves.
7162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 Phone phone = getPhone(subId);
7165 if (phone == null) return false;
7166
7167 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
7171 }
7172
7173 @Override
7174 public boolean isDataAllowedInVoiceCall(int subId) {
7175 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7176
7177 // Now that all security checks passes, perform the operation as ourselves.
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 Phone phone = getPhone(subId);
7181 if (phone == null) return false;
7182
7183 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
7187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007188}