blob: 140bed275cef145e162647f9a50a34a7c7a85bc7 [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070065import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080066import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070067import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070069import android.telephony.CellInfoGsm;
70import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070071import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070073import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070074import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080075import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070076import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080077import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070078import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080079import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080080import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070081import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080082import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080085import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080086import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070088import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070089import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080091import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000092import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070093import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070097import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700102import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700104import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsMmTelFeature;
106import android.telephony.ims.aidl.IImsRcsFeature;
107import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700109import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.feature.MmTelFeature;
111import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800112import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800116import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800118
Andrew Lee312e8172014-10-23 17:01:36 -0700119import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800120import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700122import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700123import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800124import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700125import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700126import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800128import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700129import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800130import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800132import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700133import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100134import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700135import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700136import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700138import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800139import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700140import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700141import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700142import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700143import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700144import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700145import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700146import com.android.internal.telephony.SmsApplication;
147import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700180import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800181import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800182import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800183import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100184import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700186import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
189/**
190 * Implementation of the ITelephony interface.
191 */
Santos Cordon117fee72014-05-16 17:56:12 -0700192public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private static final String LOG_TAG = "PhoneInterfaceManager";
194 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
195 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
198 // Message codes used with mMainThreadHandler
199 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700200 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
201 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202 private static final int CMD_OPEN_CHANNEL = 9;
203 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
204 private static final int CMD_CLOSE_CHANNEL = 11;
205 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800206 private static final int CMD_NV_READ_ITEM = 13;
207 private static final int EVENT_NV_READ_ITEM_DONE = 14;
208 private static final int CMD_NV_WRITE_ITEM = 15;
209 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
210 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
211 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700212 private static final int CMD_RESET_MODEM_CONFIG = 19;
213 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800214 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
215 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
216 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
217 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800218 private static final int CMD_SEND_ENVELOPE = 25;
219 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000220 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
221 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700222 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
223 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
224 private static final int CMD_EXCHANGE_SIM_IO = 31;
225 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800226 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
227 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700228 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
229 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700230 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
231 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700232 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
233 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
234 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700236 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
237 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
238 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
239 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700240 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
242 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000243 private static final int CMD_SWITCH_SLOTS = 50;
244 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700245 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
246 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
247 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
248 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
249 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
250 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
251 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
252 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700253 private static final int CMD_GET_ALL_CELL_INFO = 60;
254 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
255 private static final int CMD_GET_CELL_LOCATION = 62;
256 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700257 private static final int CMD_MODEM_REBOOT = 64;
258 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700259 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
260 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800261 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
262 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700263 private static final int CMD_GET_MODEM_STATUS = 70;
264 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700265 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
266 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800268 // Parameters of select command.
269 private static final int SELECT_COMMAND = 0xA4;
270 private static final int SELECT_P1 = 0x04;
271 private static final int SELECT_P2 = 0;
272 private static final int SELECT_P3 = 0x10;
273
Pengquan Meng85728fb2018-03-12 16:31:21 -0700274 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
275 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
276 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
277
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 /** The singleton instance. */
279 private static PhoneInterfaceManager sInstance;
280
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700283 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private AppOpsManager mAppOps;
285 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800286 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800287 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700288 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
Derek Tan97ebb422014-09-05 16:55:38 -0700290 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
291 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800292 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800293 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700294
Michelecea4cf22018-12-21 15:00:11 -0800295 // String to store multi SIM allowed
296 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
297
Derek Tan740e1672017-06-27 14:56:27 -0700298 // The AID of ISD-R.
299 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
300
yinxub1bed742017-04-17 11:45:04 -0700301 private NetworkScanRequestTracker mNetworkScanRequestTracker;
302
David Kelly5e06a7f2018-03-12 14:10:59 +0000303 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
304 private static final int MANUFACTURER_CODE_LENGTH = 8;
305
Derek Tan89e89d42014-07-08 17:00:10 -0700306 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700307 * A request object to use for transmitting data to an ICC.
308 */
309 private static final class IccAPDUArgument {
310 public int channel, cla, command, p1, p2, p3;
311 public String data;
312
313 public IccAPDUArgument(int channel, int cla, int command,
314 int p1, int p2, int p3, String data) {
315 this.channel = channel;
316 this.cla = cla;
317 this.command = command;
318 this.p1 = p1;
319 this.p2 = p2;
320 this.p3 = p3;
321 this.data = data;
322 }
323 }
324
325 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700326 * A request object to use for transmitting data to an ICC.
327 */
328 private static final class ManualNetworkSelectionArgument {
329 public OperatorInfo operatorInfo;
330 public boolean persistSelection;
331
332 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
333 this.operatorInfo = operatorInfo;
334 this.persistSelection = persistSelection;
335 }
336 }
337
338 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
340 * request after sending. The main thread will notify the request when it is complete.
341 */
342 private static final class MainThreadRequest {
343 /** The argument to use for the request */
344 public Object argument;
345 /** The result of the request that is run on the main thread */
346 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800347 // The subscriber id that this request applies to. Defaults to
348 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
349 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
Nathan Harold92bed182018-10-12 18:16:49 -0700351 // In cases where subId is unavailable, the caller needs to specify the phone.
352 public Phone phone;
353
vagdeviaf9a5b92018-08-15 16:01:53 -0700354 public WorkSource workSource;
355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 public MainThreadRequest(Object argument) {
357 this.argument = argument;
358 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800359
Nathan Harold92bed182018-10-12 18:16:49 -0700360 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
361 this.argument = argument;
362 if (phone != null) {
363 this.phone = phone;
364 }
365 this.workSource = workSource;
366 }
367
vagdeviaf9a5b92018-08-15 16:01:53 -0700368 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800369 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800370 if (subId != null) {
371 this.subId = subId;
372 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700373 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 }
376
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800377 private static final class IncomingThirdPartyCallArgs {
378 public final ComponentName component;
379 public final String callId;
380 public final String callerDisplayName;
381
382 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
383 String callerDisplayName) {
384 this.component = component;
385 this.callId = callId;
386 this.callerDisplayName = callerDisplayName;
387 }
388 }
389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 /**
391 * A handler that processes messages on the main thread in the phone process. Since many
392 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
393 * inbound binder threads to the main thread in the phone process. The Binder thread
394 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
395 * on, which will be notified when the operation completes and will contain the result of the
396 * request.
397 *
398 * <p>If a MainThreadRequest object is provided in the msg.obj field,
399 * note that request.result must be set to something non-null for the calling thread to
400 * unblock.
401 */
402 private final class MainThreadHandler extends Handler {
403 @Override
404 public void handleMessage(Message msg) {
405 MainThreadRequest request;
406 Message onCompleted;
407 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800408 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700409 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800410 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411
412 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700413 case CMD_HANDLE_USSD_REQUEST: {
414 request = (MainThreadRequest) msg.obj;
415 final Phone phone = getPhoneFromRequest(request);
416 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
417 String ussdRequest = ussdObject.first;
418 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700419
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 if (!isUssdApiAllowed(request.subId)) {
421 // Carrier does not support use of this API, return failure.
422 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
423 UssdResponse response = new UssdResponse(ussdRequest, null);
424 Bundle returnData = new Bundle();
425 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
426 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700427
Pengquan Menga1bb6272018-09-06 09:59:22 -0700428 request.result = true;
429 notifyRequester(request);
430 return;
431 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700432
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 try {
434 request.result = phone != null
435 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
436 } catch (CallStateException cse) {
437 request.result = false;
438 }
439 // Wake up the requesting thread
440 notifyRequester(request);
441 break;
pkanwar32d516d2016-10-14 19:37:38 -0700442 }
443
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700446 final Phone phone = getPhoneFromRequest(request);
447 request.result = phone != null ?
448 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
449 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800458 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700459 if (uiccCard == null) {
460 loge("iccTransmitApduLogicalChannel: No UICC");
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
465 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 iccArgument.channel, iccArgument.cla, iccArgument.command,
468 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700471 break;
472
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 ar = (AsyncResult) msg.obj;
475 request = (MainThreadRequest) ar.userObj;
476 if (ar.exception == null && ar.result != null) {
477 request.result = ar.result;
478 } else {
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
480 if (ar.result == null) {
481 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800482 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800484 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700485 } else {
486 loge("iccTransmitApduLogicalChannel: Unknown exception");
487 }
488 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 break;
491
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
493 request = (MainThreadRequest) msg.obj;
494 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800495 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 if (uiccCard == null) {
497 loge("iccTransmitApduBasicChannel: No UICC");
498 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 } else {
501 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
502 request);
503 uiccCard.iccTransmitApduBasicChannel(
504 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
505 iccArgument.p3, iccArgument.data, onCompleted);
506 }
507 break;
508
509 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
510 ar = (AsyncResult) msg.obj;
511 request = (MainThreadRequest) ar.userObj;
512 if (ar.exception == null && ar.result != null) {
513 request.result = ar.result;
514 } else {
515 request.result = new IccIoResult(0x6F, 0, (byte[])null);
516 if (ar.result == null) {
517 loge("iccTransmitApduBasicChannel: Empty response");
518 } else if (ar.exception instanceof CommandException) {
519 loge("iccTransmitApduBasicChannel: CommandException: " +
520 ar.exception);
521 } else {
522 loge("iccTransmitApduBasicChannel: Unknown exception");
523 }
524 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 break;
527
528 case CMD_EXCHANGE_SIM_IO:
529 request = (MainThreadRequest) msg.obj;
530 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800531 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 if (uiccCard == null) {
533 loge("iccExchangeSimIO: No UICC");
534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 } else {
537 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
538 request);
539 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
540 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
541 iccArgument.data, onCompleted);
542 }
543 break;
544
545 case EVENT_EXCHANGE_SIM_IO_DONE:
546 ar = (AsyncResult) msg.obj;
547 request = (MainThreadRequest) ar.userObj;
548 if (ar.exception == null && ar.result != null) {
549 request.result = ar.result;
550 } else {
551 request.result = new IccIoResult(0x6f, 0, (byte[])null);
552 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 break;
555
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 case CMD_SEND_ENVELOPE:
557 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800558 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 if (uiccCard == null) {
560 loge("sendEnvelopeWithStatus: No UICC");
561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 } else {
564 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
565 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
566 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 break;
568
569 case EVENT_SEND_ENVELOPE_DONE:
570 ar = (AsyncResult) msg.obj;
571 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700572 if (ar.exception == null && ar.result != null) {
573 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700575 request.result = new IccIoResult(0x6F, 0, (byte[])null);
576 if (ar.result == null) {
577 loge("sendEnvelopeWithStatus: Empty response");
578 } else if (ar.exception instanceof CommandException) {
579 loge("sendEnvelopeWithStatus: CommandException: " +
580 ar.exception);
581 } else {
582 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
583 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800586 break;
587
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 case CMD_OPEN_CHANNEL:
589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800591 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 if (uiccCard == null) {
593 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800594 request.result = new IccOpenLogicalChannelResponse(-1,
595 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800599 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
600 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
604 case EVENT_OPEN_CHANNEL_DONE:
605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 int[] result = (int[]) ar.result;
610 int channelId = result[0];
611 byte[] selectResponse = null;
612 if (result.length > 1) {
613 selectResponse = new byte[result.length - 1];
614 for (int i = 1; i < result.length; ++i) {
615 selectResponse[i - 1] = (byte) result[i];
616 }
617 }
618 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 if (ar.result == null) {
622 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 if (ar.exception != null) {
625 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
626 }
627
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700628 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700629 if (ar.exception instanceof CommandException) {
630 CommandException.Error error =
631 ((CommandException) (ar.exception)).getCommandError();
632 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700634 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700635 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 }
637 }
638 openChannelResp = new IccOpenLogicalChannelResponse(
639 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700641 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 break;
644
645 case CMD_CLOSE_CHANNEL:
646 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800647 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 if (uiccCard == null) {
649 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900650 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 } else {
653 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
654 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
655 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 break;
657
658 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800659 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
660 break;
661
662 case CMD_NV_READ_ITEM:
663 request = (MainThreadRequest) msg.obj;
664 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800665 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
666 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
669 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800675 request.result = "";
676 if (ar.result == null) {
677 loge("nvReadItem: Empty response");
678 } else if (ar.exception instanceof CommandException) {
679 loge("nvReadItem: CommandException: " +
680 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 }
684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 break;
687
Jake Hambye994d462014-02-03 13:10:13 -0800688 case CMD_NV_WRITE_ITEM:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
691 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800692 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700693 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800694 break;
695
696 case EVENT_NV_WRITE_ITEM_DONE:
697 handleNullReturnEvent(msg, "nvWriteItem");
698 break;
699
700 case CMD_NV_WRITE_CDMA_PRL:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800703 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800704 break;
705
706 case EVENT_NV_WRITE_CDMA_PRL_DONE:
707 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
708 break;
709
chen xu6dac5ab2018-10-26 17:39:23 -0700710 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800711 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700712 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800713 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800714 break;
715
chen xu6dac5ab2018-10-26 17:39:23 -0700716 case EVENT_RESET_MODEM_CONFIG_DONE:
717 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800718 break;
719
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 case CMD_GET_PREFERRED_NETWORK_TYPE:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700723 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 break;
725
726 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
729 if (ar.exception == null && ar.result != null) {
730 request.result = ar.result; // Integer
731 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800732 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 if (ar.result == null) {
734 loge("getPreferredNetworkType: Empty response");
735 } else if (ar.exception instanceof CommandException) {
736 loge("getPreferredNetworkType: CommandException: " +
737 ar.exception);
738 } else {
739 loge("getPreferredNetworkType: Unknown exception");
740 }
741 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 break;
744
745 case CMD_SET_PREFERRED_NETWORK_TYPE:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
748 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700749 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
753 handleNullReturnEvent(msg, "setPreferredNetworkType");
754 break;
755
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000756 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
757 request = (MainThreadRequest)msg.obj;
758 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000760 break;
761
762 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
763 ar = (AsyncResult)msg.obj;
764 request = (MainThreadRequest)ar.userObj;
765 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000767 break;
768
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800769 case CMD_SET_VOICEMAIL_NUMBER:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
772 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800773 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
774 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800775 break;
776
777 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
778 handleNullReturnEvent(msg, "setVoicemailNumber");
779 break;
780
Stuart Scott54788802015-03-30 13:18:01 -0700781 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
784 request);
785 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
786 break;
787
788 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
789 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
790 break;
791
Shishir Agrawal302c8692015-06-19 13:49:39 -0700792 case CMD_PERFORM_NETWORK_SCAN:
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
795 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
796 break;
797
798 case EVENT_PERFORM_NETWORK_SCAN_DONE:
799 ar = (AsyncResult) msg.obj;
800 request = (MainThreadRequest) ar.userObj;
801 CellNetworkScanResult cellScanResult;
802 if (ar.exception == null && ar.result != null) {
803 cellScanResult = new CellNetworkScanResult(
804 CellNetworkScanResult.STATUS_SUCCESS,
805 (List<OperatorInfo>) ar.result);
806 } else {
807 if (ar.result == null) {
808 loge("getCellNetworkScanResults: Empty response");
809 }
810 if (ar.exception != null) {
811 loge("getCellNetworkScanResults: Exception: " + ar.exception);
812 }
813 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
814 if (ar.exception instanceof CommandException) {
815 CommandException.Error error =
816 ((CommandException) (ar.exception)).getCommandError();
817 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
818 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
819 } else if (error == CommandException.Error.GENERIC_FAILURE) {
820 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
821 }
822 }
823 cellScanResult = new CellNetworkScanResult(errorCode, null);
824 }
825 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700826 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 break;
828
829 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
830 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700831 ManualNetworkSelectionArgument selArg =
832 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
834 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
836 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 break;
838
839 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 if (ar.exception == null) {
843 request.result = true;
844 } else {
845 request.result = false;
846 loge("setNetworkSelectionModeManual " + ar.exception);
847 }
848 notifyRequester(request);
849 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700850 break;
851
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700852 case CMD_GET_MODEM_ACTIVITY_INFO:
853 request = (MainThreadRequest) msg.obj;
854 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700855 if (defaultPhone != null) {
856 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
857 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 break;
859
860 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
861 ar = (AsyncResult) msg.obj;
862 request = (MainThreadRequest) ar.userObj;
863 if (ar.exception == null && ar.result != null) {
864 request.result = ar.result;
865 } else {
866 if (ar.result == null) {
867 loge("queryModemActivityInfo: Empty response");
868 } else if (ar.exception instanceof CommandException) {
869 loge("queryModemActivityInfo: CommandException: " +
870 ar.exception);
871 } else {
872 loge("queryModemActivityInfo: Unknown exception");
873 }
874 }
Amit Mahajand4766222016-01-28 15:28:28 -0800875 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
876 if (request.result == null) {
877 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
878 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700879 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700880 break;
881
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 case CMD_SET_ALLOWED_CARRIERS:
883 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800884 CarrierRestrictionRules argument =
885 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800887 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 break;
889
890 case EVENT_SET_ALLOWED_CARRIERS_DONE:
891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
893 if (ar.exception == null && ar.result != null) {
894 request.result = ar.result;
895 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800896 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
897 if (ar.exception instanceof CommandException) {
898 loge("setAllowedCarriers: CommandException: " + ar.exception);
899 CommandException.Error error =
900 ((CommandException) (ar.exception)).getCommandError();
901 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
902 request.result =
903 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
904 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700905 } else {
906 loge("setAllowedCarriers: Unknown exception");
907 }
908 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700909 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 break;
911
912 case CMD_GET_ALLOWED_CARRIERS:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
918 case EVENT_GET_ALLOWED_CARRIERS_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result;
923 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800924 request.result = new IllegalStateException(
925 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700926 if (ar.result == null) {
927 loge("getAllowedCarriers: Empty response");
928 } else if (ar.exception instanceof CommandException) {
929 loge("getAllowedCarriers: CommandException: " +
930 ar.exception);
931 } else {
932 loge("getAllowedCarriers: Unknown exception");
933 }
934 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700936 break;
937
Nathan Haroldb3014052017-01-25 15:57:32 -0800938 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
939 ar = (AsyncResult) msg.obj;
940 request = (MainThreadRequest) ar.userObj;
941 if (ar.exception == null && ar.result != null) {
942 request.result = ar.result;
943 } else {
944 request.result = new IllegalArgumentException(
945 "Failed to retrieve Forbidden Plmns");
946 if (ar.result == null) {
947 loge("getForbiddenPlmns: Empty response");
948 } else {
949 loge("getForbiddenPlmns: Unknown exception");
950 }
951 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700952 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800953 break;
954
955 case CMD_GET_FORBIDDEN_PLMNS:
956 request = (MainThreadRequest) msg.obj;
957 uiccCard = getUiccCardFromRequest(request);
958 if (uiccCard == null) {
959 loge("getForbiddenPlmns() UiccCard is null");
960 request.result = new IllegalArgumentException(
961 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800963 break;
964 }
965 Integer appType = (Integer) request.argument;
966 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
967 if (uiccApp == null) {
968 loge("getForbiddenPlmns() no app with specified type -- "
969 + appType);
970 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700971 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800972 break;
973 } else {
974 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
975 + " specified type -- " + appType);
976 }
977 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
978 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
979 onCompleted);
980 break;
981
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000982 case CMD_SWITCH_SLOTS:
983 request = (MainThreadRequest) msg.obj;
984 int[] physicalSlots = (int[]) request.argument;
985 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
986 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
987 break;
988
989 case EVENT_SWITCH_SLOTS_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700993 notifyRequester(request);
994 break;
995 case CMD_GET_NETWORK_SELECTION_MODE:
996 request = (MainThreadRequest) msg.obj;
997 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
998 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
999 break;
1000
1001 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception != null) {
1005 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1006 } else {
1007 int mode = ((int[]) ar.result)[0];
1008 if (mode == 0) {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1010 } else {
1011 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1012 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001013 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001014 notifyRequester(request);
1015 break;
1016 case CMD_GET_CDMA_ROAMING_MODE:
1017 request = (MainThreadRequest) msg.obj;
1018 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1019 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1020 break;
1021 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1022 ar = (AsyncResult) msg.obj;
1023 request = (MainThreadRequest) ar.userObj;
1024 if (ar.exception != null) {
1025 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1026 } else {
1027 request.result = ((int[]) ar.result)[0];
1028 }
1029 notifyRequester(request);
1030 break;
1031 case CMD_SET_CDMA_ROAMING_MODE:
1032 request = (MainThreadRequest) msg.obj;
1033 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1034 int mode = (int) request.argument;
1035 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1036 break;
1037 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 request.result = ar.exception == null;
1041 notifyRequester(request);
1042 break;
1043 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1044 request = (MainThreadRequest) msg.obj;
1045 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1046 int subscriptionMode = (int) request.argument;
1047 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1048 break;
1049 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1050 ar = (AsyncResult) msg.obj;
1051 request = (MainThreadRequest) ar.userObj;
1052 request.result = ar.exception == null;
1053 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001054 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 case CMD_GET_ALL_CELL_INFO:
1056 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001058 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 case EVENT_GET_ALL_CELL_INFO_DONE:
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001063 // If a timeout occurs, the response will be null
1064 request.result = (ar.exception == null && ar.result != null)
1065 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 synchronized (request) {
1067 request.notifyAll();
1068 }
1069 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001070 case CMD_REQUEST_CELL_INFO_UPDATE:
1071 request = (MainThreadRequest) msg.obj;
1072 request.phone.requestCellInfoUpdate(request.workSource,
1073 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1074 break;
1075 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
1078 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1079 try {
1080 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001082 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1083 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001086 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 } else {
1088 // use the result as returned
1089 cb.onCellInfo((List<CellInfo>) ar.result);
1090 }
1091 } catch (RemoteException re) {
1092 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1093 }
1094 break;
1095 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001096 request = (MainThreadRequest) msg.obj;
1097 WorkSource ws = (WorkSource) request.argument;
1098 Phone phone = getPhoneFromRequest(request);
1099 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1100 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001101 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
1104 if (ar.exception == null) {
1105 request.result = ar.result;
1106 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1109 ? new CdmaCellLocation() : new GsmCellLocation();
1110 }
1111
1112 synchronized (request) {
1113 request.notifyAll();
1114 }
1115 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001116 case CMD_MODEM_REBOOT:
1117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001119 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case EVENT_CMD_MODEM_REBOOT_DONE:
1122 handleNullReturnEvent(msg, "rebootModem");
1123 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001124 case CMD_REQUEST_ENABLE_MODEM:
1125 request = (MainThreadRequest) msg.obj;
1126 boolean enable = (boolean) request.argument;
1127 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 PhoneConfigurationManager.getInstance()
1130 .enablePhone(request.phone, enable, onCompleted);
1131 break;
1132 case EVENT_ENABLE_MODEM_DONE:
1133 ar = (AsyncResult) msg.obj;
1134 request = (MainThreadRequest) ar.userObj;
1135 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001136 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001138 if ((boolean) request.result) {
1139 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1140 updateModemStateMetrics();
1141 } else {
1142 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1143 + ar.exception);
1144 }
1145 notifyRequester(request);
1146 break;
1147 case CMD_GET_MODEM_STATUS:
1148 request = (MainThreadRequest) msg.obj;
1149 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1150 PhoneConfigurationManager.getInstance()
1151 .getPhoneStatusFromModem(request.phone, onCompleted);
1152 break;
1153 case EVENT_GET_MODEM_STATUS_DONE:
1154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 int id = request.phone.getPhoneId();
1157 if (ar.exception == null && ar.result != null) {
1158 request.result = ar.result;
1159 //update the cache as modem status has changed
1160 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1161 (boolean) request.result);
1162 } else {
1163 // Return true if modem status cannot be retrieved. For most cases,
1164 // modem status is on. And for older version modems, GET_MODEM_STATUS
1165 // and disable modem are not supported. Modem is always on.
1166 // TODO: this should be fixed in R to support a third
1167 // status UNKNOWN b/131631629
1168 request.result = true;
1169 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1170 + ar.exception);
1171 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001172 notifyRequester(request);
1173 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001174 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception == null && ar.result != null) {
1178 request.result = ar.result;
1179 } else {
1180 request.result = -1;
1181 loge("Failed to set Forbidden Plmns");
1182 if (ar.result == null) {
1183 loge("setForbidenPlmns: Empty response");
1184 } else if (ar.exception != null) {
1185 loge("setForbiddenPlmns: Exception: " + ar.exception);
1186 request.result = -1;
1187 } else {
1188 loge("setForbiddenPlmns: Unknown exception");
1189 }
1190 }
1191 notifyRequester(request);
1192 break;
1193 case CMD_SET_FORBIDDEN_PLMNS:
1194 request = (MainThreadRequest) msg.obj;
1195 uiccCard = getUiccCardFromRequest(request);
1196 if (uiccCard == null) {
1197 loge("setForbiddenPlmns: UiccCard is null");
1198 request.result = -1;
1199 notifyRequester(request);
1200 break;
1201 }
1202 Pair<Integer, List<String>> setFplmnsArgs =
1203 (Pair<Integer, List<String>>) request.argument;
1204 appType = setFplmnsArgs.first;
1205 List<String> fplmns = setFplmnsArgs.second;
1206 uiccApp = uiccCard.getApplicationByType(appType);
1207 if (uiccApp == null) {
1208 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1209 request.result = -1;
1210 loge("Failed to get UICC App");
1211 notifyRequester(request);
1212 } else {
1213 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1214 ((SIMRecords) uiccApp.getIccRecords())
1215 .setForbiddenPlmns(onCompleted, fplmns);
1216 }
1217 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 default:
1219 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1220 break;
1221 }
1222 }
Jake Hambye994d462014-02-03 13:10:13 -08001223
Pengquan Menga1bb6272018-09-06 09:59:22 -07001224 private void notifyRequester(MainThreadRequest request) {
1225 synchronized (request) {
1226 request.notifyAll();
1227 }
1228 }
1229
Jake Hambye994d462014-02-03 13:10:13 -08001230 private void handleNullReturnEvent(Message msg, String command) {
1231 AsyncResult ar = (AsyncResult) msg.obj;
1232 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1233 if (ar.exception == null) {
1234 request.result = true;
1235 } else {
1236 request.result = false;
1237 if (ar.exception instanceof CommandException) {
1238 loge(command + ": CommandException: " + ar.exception);
1239 } else {
1240 loge(command + ": Unknown exception");
1241 }
1242 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001243 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 }
1246
1247 /**
1248 * Posts the specified command to be executed on the main thread,
1249 * waits for the request to complete, and returns the result.
1250 * @see #sendRequestAsync
1251 */
1252 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001253 return sendRequest(
1254 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001255 }
1256
1257 /**
1258 * Posts the specified command to be executed on the main thread,
1259 * waits for the request to complete, and returns the result.
1260 * @see #sendRequestAsync
1261 */
1262 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1263 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001264 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001265 }
1266
1267 /**
1268 * Posts the specified command to be executed on the main thread,
1269 * waits for the request to complete, and returns the result.
1270 * @see #sendRequestAsync
1271 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001272 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001273 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001274 }
1275
1276 /**
1277 * Posts the specified command to be executed on the main thread,
1278 * waits for the request to complete, and returns the result.
1279 * @see #sendRequestAsync
1280 */
Nathan Harold92bed182018-10-12 18:16:49 -07001281 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1282 return sendRequest(command, argument, subId, null, workSource);
1283 }
1284
1285 /**
1286 * Posts the specified command to be executed on the main thread,
1287 * waits for the request to complete, and returns the result.
1288 * @see #sendRequestAsync
1289 */
1290 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1291 return sendRequest(
1292 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1293 }
1294
1295 /**
1296 * Posts the specified command to be executed on the main thread,
1297 * waits for the request to complete, and returns the result.
1298 * @see #sendRequestAsync
1299 */
1300 private Object sendRequest(
1301 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1303 throw new RuntimeException("This method will deadlock if called from the main thread.");
1304 }
1305
Nathan Harold92bed182018-10-12 18:16:49 -07001306 MainThreadRequest request = null;
1307 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1308 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1309 } else if (phone != null) {
1310 request = new MainThreadRequest(argument, phone, workSource);
1311 } else {
1312 request = new MainThreadRequest(argument, subId, workSource);
1313 }
1314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 Message msg = mMainThreadHandler.obtainMessage(command, request);
1316 msg.sendToTarget();
1317
1318 // Wait for the request to complete
1319 synchronized (request) {
1320 while (request.result == null) {
1321 try {
1322 request.wait();
1323 } catch (InterruptedException e) {
1324 // Do nothing, go back and wait until the request is complete
1325 }
1326 }
1327 }
1328 return request.result;
1329 }
1330
1331 /**
1332 * Asynchronous ("fire and forget") version of sendRequest():
1333 * Posts the specified command to be executed on the main thread, and
1334 * returns immediately.
1335 * @see #sendRequest
1336 */
1337 private void sendRequestAsync(int command) {
1338 mMainThreadHandler.sendEmptyMessage(command);
1339 }
1340
1341 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001342 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001343 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001344 */
1345 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001346 sendRequestAsync(command, argument, null, null);
1347 }
1348
1349 /**
1350 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1351 * @see {@link #sendRequest(int,Object)}
1352 */
1353 private void sendRequestAsync(
1354 int command, Object argument, Phone phone, WorkSource workSource) {
1355 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 Message msg = mMainThreadHandler.obtainMessage(command, request);
1357 msg.sendToTarget();
1358 }
1359
1360 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 * Initialize the singleton PhoneInterfaceManager instance.
1362 * This is only done once, at startup, from PhoneApp.onCreate().
1363 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001364 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 synchronized (PhoneInterfaceManager.class) {
1366 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001367 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 } else {
1369 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1370 }
1371 return sInstance;
1372 }
1373 }
1374
1375 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001376 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001379 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1381 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001382 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 mTelephonySharedPreferences =
1384 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001385 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001386 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 publish();
1389 }
1390
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001391 private Phone getDefaultPhone() {
1392 Phone thePhone = getPhone(getDefaultSubscription());
1393 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1394 }
1395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 private void publish() {
1397 if (DBG) log("publish: " + this);
1398
1399 ServiceManager.addService("phone", this);
1400 }
1401
Stuart Scott584921c2015-01-15 17:10:34 -08001402 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001403 if (request.phone != null) {
1404 return request.phone;
1405 } else {
1406 return getPhoneFromSubId(request.subId);
1407 }
1408 }
1409
1410 private Phone getPhoneFromSubId(int subId) {
1411 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1412 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001413 }
1414
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001415 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1416 Phone phone = getPhoneFromRequest(request);
1417 return phone == null ? null :
1418 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1419 }
1420
Wink Saville36469e72014-06-11 15:17:00 -07001421 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001422 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001423 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
1426 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001427 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001428 }
1429
Wink Savilleb564aae2014-10-23 10:18:09 -07001430 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 if (DBG) log("dial: " + number);
1432 // No permission check needed here: This is just a wrapper around the
1433 // ACTION_DIAL intent, which is available to any app since it puts up
1434 // the UI before it does anything.
1435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 final long identity = Binder.clearCallingIdentity();
1437 try {
1438 String url = createTelUrl(number);
1439 if (url == null) {
1440 return;
1441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001443 // PENDING: should we just silently fail if phone is offhook or ringing?
1444 PhoneConstants.State state = mCM.getState(subId);
1445 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1446 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1447 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1448 mApp.startActivity(intent);
1449 }
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 }
1453 }
1454
1455 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("call: " + number);
1461
1462 // This is just a wrapper around the ACTION_CALL intent, but we still
1463 // need to do a permission check since we're calling startActivity()
1464 // from the context of the phone app.
1465 enforceCallPermission();
1466
Jordan Liu1617b712019-07-10 15:06:26 -07001467 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 != AppOpsManager.MODE_ALLOWED) {
1469 return;
1470 }
1471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 final long identity = Binder.clearCallingIdentity();
1473 try {
1474 String url = createTelUrl(number);
1475 if (url == null) {
1476 return;
1477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001479 boolean isValid = false;
1480 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1481 if (slist != null) {
1482 for (SubscriptionInfo subInfoRecord : slist) {
1483 if (subInfoRecord.getSubscriptionId() == subId) {
1484 isValid = true;
1485 break;
1486 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001487 }
Wink Saville08874612014-08-31 19:19:58 -07001488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001489 if (!isValid) {
1490 return;
1491 }
Wink Saville08874612014-08-31 19:19:58 -07001492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001493 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1494 intent.putExtra(SUBSCRIPTION_KEY, subId);
1495 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1496 mApp.startActivity(intent);
1497 } finally {
1498 Binder.restoreCallingIdentity(identity);
1499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001504 }
1505
Wink Savilleb564aae2014-10-23 10:18:09 -07001506 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001507 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001508 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1509 }
1510
1511 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001513 }
1514
Wink Savilleb564aae2014-10-23 10:18:09 -07001515 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001517 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1518 }
1519
1520 /** {@hide} */
1521 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001522 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001523 }
1524
Wink Savilleb564aae2014-10-23 10:18:09 -07001525 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001527
1528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1531 checkSimPin.start();
1532 return checkSimPin.unlockSim(null, pin);
1533 } finally {
1534 Binder.restoreCallingIdentity(identity);
1535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537
Wink Saville9de0f752013-10-22 19:04:03 -07001538 /** {@hide} */
1539 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1549 checkSimPuk.start();
1550 return checkSimPuk.unlockSim(puk, pin);
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
1553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
1556 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001557 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 * a synchronous one.
1559 */
1560 private static class UnlockSim extends Thread {
1561
1562 private final IccCard mSimCard;
1563
1564 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001565 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1566 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567
1568 // For replies from SimCard interface
1569 private Handler mHandler;
1570
1571 // For async handler to identify request type
1572 private static final int SUPPLY_PIN_COMPLETE = 100;
1573
1574 public UnlockSim(IccCard simCard) {
1575 mSimCard = simCard;
1576 }
1577
1578 @Override
1579 public void run() {
1580 Looper.prepare();
1581 synchronized (UnlockSim.this) {
1582 mHandler = new Handler() {
1583 @Override
1584 public void handleMessage(Message msg) {
1585 AsyncResult ar = (AsyncResult) msg.obj;
1586 switch (msg.what) {
1587 case SUPPLY_PIN_COMPLETE:
1588 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1589 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001590 mRetryCount = msg.arg1;
1591 if (ar.exception != null) {
1592 if (ar.exception instanceof CommandException &&
1593 ((CommandException)(ar.exception)).getCommandError()
1594 == CommandException.Error.PASSWORD_INCORRECT) {
1595 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1596 } else {
1597 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1598 }
1599 } else {
1600 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 mDone = true;
1603 UnlockSim.this.notifyAll();
1604 }
1605 break;
1606 }
1607 }
1608 };
1609 UnlockSim.this.notifyAll();
1610 }
1611 Looper.loop();
1612 }
1613
1614 /*
1615 * Use PIN or PUK to unlock SIM card
1616 *
1617 * If PUK is null, unlock SIM card with PIN
1618 *
1619 * If PUK is not null, unlock SIM card with PUK and set PIN code
1620 */
Wink Saville9de0f752013-10-22 19:04:03 -07001621 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622
1623 while (mHandler == null) {
1624 try {
1625 wait();
1626 } catch (InterruptedException e) {
1627 Thread.currentThread().interrupt();
1628 }
1629 }
1630 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1631
1632 if (puk == null) {
1633 mSimCard.supplyPin(pin, callback);
1634 } else {
1635 mSimCard.supplyPuk(puk, pin, callback);
1636 }
1637
1638 while (!mDone) {
1639 try {
1640 Log.d(LOG_TAG, "wait for done");
1641 wait();
1642 } catch (InterruptedException e) {
1643 // Restore the interrupted status
1644 Thread.currentThread().interrupt();
1645 }
1646 }
1647 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001648 int[] resultArray = new int[2];
1649 resultArray[0] = mResult;
1650 resultArray[1] = mRetryCount;
1651 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653 }
1654
1655 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001656 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001657
1658 }
1659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 // No permission check needed here: this call is harmless, and it's
1662 // needed for the ServiceState.requestStateUpdate() call (which is
1663 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.updateServiceLocation();
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 }
1674
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001675 @Override
1676 public boolean isRadioOn(String callingPackage) {
1677 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001680 @Override
1681 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001683 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001684 return false;
1685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001686
1687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 return isRadioOnForSubscriber(subId);
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
1692 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001693 }
1694
1695 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1701 } else {
1702 return false;
1703 }
1704 } finally {
1705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
1709 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001710 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
Wink Saville36469e72014-06-11 15:17:00 -07001712
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
1727 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001728 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001729 }
1730
Wink Savilleb564aae2014-10-23 10:18:09 -07001731 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 final Phone phone = getPhone(subId);
1737 if (phone == null) {
1738 return false;
1739 }
1740 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1741 toggleRadioOnOffForSubscriber(subId);
1742 }
1743 return true;
1744 } finally {
1745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
Wink Saville36469e72014-06-11 15:17:00 -07001748
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001749 public boolean needMobileRadioShutdown() {
1750 /*
1751 * If any of the Radios are available, it will need to be
1752 * shutdown. So return true if any Radio is available.
1753 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1757 Phone phone = PhoneFactory.getPhone(i);
1758 if (phone != null && phone.isRadioAvailable()) return true;
1759 }
1760 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1761 return false;
1762 } finally {
1763 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001765 }
1766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001768 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001769 enforceModifyPermission();
1770
1771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1774 logv("Shutting down Phone " + i);
1775 shutdownRadioUsingPhoneId(i);
1776 }
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 }
1780 }
1781
1782 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001783 Phone phone = PhoneFactory.getPhone(phoneId);
1784 if (phone != null && phone.isRadioAvailable()) {
1785 phone.shutdownRadio();
1786 }
1787 }
1788
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1795 if (defaultPhone != null) {
1796 defaultPhone.setRadioPower(turnOn);
1797 return true;
1798 } else {
1799 loge("There's no default phone.");
1800 return false;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001804 }
Wink Saville36469e72014-06-11 15:17:00 -07001805 }
1806
Wink Savilleb564aae2014-10-23 10:18:09 -07001807 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809
1810 final long identity = Binder.clearCallingIdentity();
1811 try {
1812 final Phone phone = getPhone(subId);
1813 if (phone != null) {
1814 phone.setRadioPower(turnOn);
1815 return true;
1816 } else {
1817 return false;
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
Wink Saville36469e72014-06-11 15:17:00 -07001824 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 public boolean enableDataConnectivity() {
1827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828
1829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 int subId = mSubscriptionController.getDefaultDataSubId();
1832 final Phone phone = getPhone(subId);
1833 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001834 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 return true;
1836 } else {
1837 return false;
1838 }
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
Wink Saville36469e72014-06-11 15:17:00 -07001844 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 public boolean disableDataConnectivity() {
1847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 int subId = mSubscriptionController.getDefaultDataSubId();
1852 final Phone phone = getPhone(subId);
1853 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001854 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001855 return true;
1856 } else {
1857 return false;
1858 }
1859 } finally {
1860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 }
1863
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001865 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 final long identity = Binder.clearCallingIdentity();
1867 try {
1868 final Phone phone = getPhone(subId);
1869 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001870 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871 } else {
1872 return false;
1873 }
1874 } finally {
1875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 }
1878
1879 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001880 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001881 }
1882
pkanwarae03a6b2016-11-06 20:37:09 -08001883 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001884 enforceCallPermission();
1885
1886 final long identity = Binder.clearCallingIdentity();
1887 try {
1888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1889 return;
1890 }
1891 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1892 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
1895 }
pkanwar32d516d2016-10-14 19:37:38 -07001896 };
1897
Wink Savilleb564aae2014-10-23 10:18:09 -07001898 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001900
1901 final long identity = Binder.clearCallingIdentity();
1902 try {
1903 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1904 return false;
1905 }
1906 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1907 } finally {
1908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001913 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001914 }
1915
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001916 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 Phone phone = PhoneFactory.getPhone(slotIndex);
1920 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1921 PhoneConstantConversions.convertCallState(phone.getState());
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
1924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001928 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001929 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1930 }
1931
1932 @Override
1933 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 final long identity = Binder.clearCallingIdentity();
1935 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001936 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937 if (phone != null) {
1938 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1939 } else {
1940 return PhoneConstantConversions.convertDataState(
1941 PhoneConstants.DataState.DISCONNECTED);
1942 }
1943 } finally {
1944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001949 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001950 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1951 }
1952
1953 @Override
1954 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 final long identity = Binder.clearCallingIdentity();
1956 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958 if (phone != null) {
1959 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1960 } else {
1961 return TelephonyManager.DATA_ACTIVITY_NONE;
1962 }
1963 } finally {
1964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
1968 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001969 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001970 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001971 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001972
1973 LocationAccessPolicy.LocationPermissionResult locationResult =
1974 LocationAccessPolicy.checkLocationPermission(mApp,
1975 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1976 .setCallingPackage(callingPackage)
1977 .setCallingPid(Binder.getCallingPid())
1978 .setCallingUid(Binder.getCallingUid())
1979 .setMethod("getCellLocation")
1980 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1981 .build());
1982 switch (locationResult) {
1983 case DENIED_HARD:
1984 throw new SecurityException("Not allowed to access cell location");
1985 case DENIED_SOFT:
1986 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001989 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990 final long identity = Binder.clearCallingIdentity();
1991 try {
1992 if (DBG_LOC) log("getCellLocation: is active user");
1993 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001994 int subId = mSubscriptionController.getDefaultDataSubId();
1995 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1996 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997 return data;
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
2000 }
Svetoslav64fad262015-04-14 14:35:21 -07002001 }
2002
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002004 public String getNetworkCountryIsoForPhone(int phoneId) {
2005 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2006 // registered cell info, so return a NULL country instead.
2007 final long identity = Binder.clearCallingIdentity();
2008 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002009 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2010 // Get default phone in this case.
2011 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2012 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002013 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002014 // Todo: fix this when we can get the actual cellular network info when the device
2015 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002016 if (TelephonyManager.NETWORK_TYPE_IWLAN
2017 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2018 return "";
2019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 Phone phone = PhoneFactory.getPhone(phoneId);
2021 if (phone != null) {
2022 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002023 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024 if (sst != null) {
2025 LocaleTracker lt = sst.getLocaleTracker();
2026 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002027 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2028 return lt.getCurrentCountry();
2029 } else if (emergencyNumberTracker != null) {
2030 return emergencyNumberTracker.getEmergencyCountryIso();
2031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002032 }
2033 }
2034 }
2035 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002036 } finally {
2037 Binder.restoreCallingIdentity(identity);
2038 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002039 }
2040
2041 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002043 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002044 }
2045
Sanket Padawe356d7632015-06-22 14:03:32 -07002046 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002047 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 mApp.enforceCallingOrSelfPermission(
2049 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002050
2051 final long identity = Binder.clearCallingIdentity();
2052 try {
2053 final Phone phone = getPhone(subId);
2054 if (phone != null) {
2055 phone.enableLocationUpdates();
2056 }
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 }
2061
2062 @Override
2063 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002064 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002065 }
2066
Sanket Padawe356d7632015-06-22 14:03:32 -07002067 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002068 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 mApp.enforceCallingOrSelfPermission(
2070 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071
2072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 final Phone phone = getPhone(subId);
2075 if (phone != null) {
2076 phone.disableLocationUpdates();
2077 }
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 }
2082
Nathan Harold31d7ff32018-10-15 20:20:30 -07002083 /**
2084 * Returns the target SDK version number for a given package name.
2085 *
Nathan Haroldec184742019-07-10 17:04:16 -07002086 * This call MUST be invoked before clearing the calling UID.
2087 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002088 * @return target SDK if the package is found or INT_MAX.
2089 */
2090 private int getTargetSdk(String packageName) {
2091 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002092 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002093 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002094 if (ai != null) return ai.targetSdkVersion;
2095 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002096 loge("Failed to get package info for pkg="
2097 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002098 }
2099 return Integer.MAX_VALUE;
2100 }
2101
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 @Override
2103 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002104 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2105 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002106 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2107 throw new SecurityException(
2108 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2109 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002110
Jordan Liu1617b712019-07-10 15:06:26 -07002111 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2113 return null;
2114 }
Svetoslav64fad262015-04-14 14:35:21 -07002115
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002116 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117
Nathan Haroldf180aac2018-06-01 18:43:55 -07002118 List<CellInfo> info = getAllCellInfo(callingPackage);
2119 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120
Nathan Haroldf180aac2018-06-01 18:43:55 -07002121 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2122 for (CellInfo ci : info) {
2123 if (ci instanceof CellInfoGsm) {
2124 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2125 } else if (ci instanceof CellInfoWcdma) {
2126 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002129 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 }
2131
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 private List<CellInfo> getCachedCellInfo() {
2133 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2134 for (Phone phone : PhoneFactory.getPhones()) {
2135 List<CellInfo> info = phone.getAllCellInfo();
2136 if (info != null) cellInfos.addAll(info);
2137 }
2138 return cellInfos;
2139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140
2141 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002142 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002143 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002144 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002145
2146 LocationAccessPolicy.LocationPermissionResult locationResult =
2147 LocationAccessPolicy.checkLocationPermission(mApp,
2148 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2149 .setCallingPackage(callingPackage)
2150 .setCallingPid(Binder.getCallingPid())
2151 .setCallingUid(Binder.getCallingUid())
2152 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002153 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002154 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2155 .build());
2156 switch (locationResult) {
2157 case DENIED_HARD:
2158 throw new SecurityException("Not allowed to access cell info");
2159 case DENIED_SOFT:
2160 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 }
2162
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002163 final int targetSdk = getTargetSdk(callingPackage);
2164 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2165 return getCachedCellInfo();
2166 }
2167
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002168 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002169 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2173 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002174 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002175 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 if (info != null) cellInfos.addAll(info);
2177 }
2178 return cellInfos;
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182 }
2183
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002184 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002185 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2186 requestCellInfoUpdateInternal(
2187 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2188 }
2189
2190 @Override
2191 public void requestCellInfoUpdateWithWorkSource(
2192 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2193 enforceModifyPermission();
2194 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2195 }
2196
2197 private void requestCellInfoUpdateInternal(
2198 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002199 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002200 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002201
2202 LocationAccessPolicy.LocationPermissionResult locationResult =
2203 LocationAccessPolicy.checkLocationPermission(mApp,
2204 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2205 .setCallingPackage(callingPackage)
2206 .setCallingPid(Binder.getCallingPid())
2207 .setCallingUid(Binder.getCallingUid())
2208 .setMethod("requestCellInfoUpdate")
2209 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2210 .build());
2211 switch (locationResult) {
2212 case DENIED_HARD:
2213 throw new SecurityException("Not allowed to access cell info");
2214 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002215 try {
2216 cb.onCellInfo(new ArrayList<CellInfo>());
2217 } catch (RemoteException re) {
2218 // Drop without consequences
2219 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002220 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002221 }
2222
Nathan Harolda939a962019-05-09 10:13:47 -07002223
2224 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2226
2227 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2228 }
2229
2230 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002232 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002233 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002234
2235 final long identity = Binder.clearCallingIdentity();
2236 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002237 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 } finally {
2239 Binder.restoreCallingIdentity(identity);
2240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
Shishir Agrawala9f32182016-04-12 12:00:16 -07002243 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002244 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002245 Phone phone = PhoneFactory.getPhone(slotIndex);
2246 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002247 return null;
2248 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002249 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002250 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2251 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002252 return null;
2253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254
2255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 return phone.getImei();
2258 } finally {
2259 Binder.restoreCallingIdentity(identity);
2260 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002261 }
2262
2263 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002264 public String getTypeAllocationCodeForSlot(int slotIndex) {
2265 Phone phone = PhoneFactory.getPhone(slotIndex);
2266 String tac = null;
2267 if (phone != null) {
2268 String imei = phone.getImei();
2269 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2270 }
2271 return tac;
2272 }
2273
2274 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002275 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002276 Phone phone = PhoneFactory.getPhone(slotIndex);
2277 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002278 return null;
2279 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002280
Jeff Davidson913390f2018-02-23 17:11:49 -08002281 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002282 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2283 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 return null;
2285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 return phone.getMeid();
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
Jack Yu2af8d712017-03-15 17:14:14 -07002293 }
2294
2295 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002296 public String getManufacturerCodeForSlot(int slotIndex) {
2297 Phone phone = PhoneFactory.getPhone(slotIndex);
2298 String manufacturerCode = null;
2299 if (phone != null) {
2300 String meid = phone.getMeid();
2301 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2302 }
2303 return manufacturerCode;
2304 }
2305
2306 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002307 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 Phone phone = PhoneFactory.getPhone(slotIndex);
2309 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002310 return null;
2311 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002312 int subId = phone.getSubId();
2313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2314 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2315 return null;
2316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
2320 return phone.getDeviceSvn();
2321 } finally {
2322 Binder.restoreCallingIdentity(identity);
2323 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002324 }
2325
fionaxu43304da2017-11-27 22:51:16 -08002326 @Override
2327 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 final Phone phone = getPhone(subId);
2331 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
2334 }
fionaxu43304da2017-11-27 22:51:16 -08002335 }
2336
2337 @Override
2338 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 final Phone phone = getPhone(subId);
2342 return phone == null ? null : phone.getCarrierName();
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
2345 }
fionaxu43304da2017-11-27 22:51:16 -08002346 }
2347
calvinpanffe225e2018-11-01 19:43:06 +08002348 @Override
chen xu0026ca62019-03-06 15:28:50 -08002349 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 final Phone phone = getPhone(subId);
2353 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002354 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002355 } finally {
2356 Binder.restoreCallingIdentity(identity);
2357 }
2358 }
2359
2360 @Override
chen xu0026ca62019-03-06 15:28:50 -08002361 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002365 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002366 } finally {
2367 Binder.restoreCallingIdentity(identity);
2368 }
2369 }
2370
chen xu651eec72018-11-11 19:03:44 -08002371 @Override
chen xu864e11c2018-12-06 22:10:03 -08002372 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2373 if (!isSubscriptionMccMnc) {
2374 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2375 }
chen xu651eec72018-11-11 19:03:44 -08002376 final Phone phone = PhoneFactory.getPhone(slotIndex);
2377 if (phone == null) {
2378 return TelephonyManager.UNKNOWN_CARRIER_ID;
2379 }
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
2386 }
2387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 //
2389 // Internal helper methods.
2390 //
2391
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002392 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2394 *
2395 * @throws SecurityException if the caller does not have the required permission
2396 */
2397 private void enforceModifyPermission() {
2398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2399 }
2400
2401 /**
2402 * Make sure the caller has the CALL_PHONE permission.
2403 *
2404 * @throws SecurityException if the caller does not have the required permission
2405 */
2406 private void enforceCallPermission() {
2407 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2408 }
2409
Stuart Scott8eef64f2015-04-08 15:13:54 -07002410 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002412 "ConnectivityService");
2413 }
2414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 private String createTelUrl(String number) {
2416 if (TextUtils.isEmpty(number)) {
2417 return null;
2418 }
2419
Jake Hambye994d462014-02-03 13:10:13 -08002420 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422
Ihab Awadf9e92732013-12-05 18:02:52 -08002423 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2425 }
2426
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002427 private static void logv(String msg) {
2428 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2429 }
2430
Ihab Awadf9e92732013-12-05 18:02:52 -08002431 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2433 }
2434
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002435 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002437 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002438 }
2439
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002441 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 final Phone phone = PhoneFactory.getPhone(slotIndex);
2445 if (phone == null) {
2446 return PhoneConstants.PHONE_TYPE_NONE;
2447 } else {
2448 return phone.getPhoneType();
2449 }
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
2455 /**
2456 * Returns the CDMA ERI icon index to display
2457 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002458 @Override
2459 public int getCdmaEriIconIndex(String callingPackage) {
2460 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002461 }
2462
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002464 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002466 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002467 return -1;
2468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469
2470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = getPhone(subId);
2473 if (phone != null) {
2474 return phone.getCdmaEriIconIndex();
2475 } else {
2476 return -1;
2477 }
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
2483 /**
2484 * Returns the CDMA ERI icon mode,
2485 * 0 - ON
2486 * 1 - FLASHING
2487 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002488 @Override
2489 public int getCdmaEriIconMode(String callingPackage) {
2490 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002491 }
2492
Sanket Padawe356d7632015-06-22 14:03:32 -07002493 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002494 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002496 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002497 return -1;
2498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = getPhone(subId);
2503 if (phone != null) {
2504 return phone.getCdmaEriIconMode();
2505 } else {
2506 return -1;
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
2513 /**
2514 * Returns the CDMA ERI text,
2515 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002516 @Override
2517 public String getCdmaEriText(String callingPackage) {
2518 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002519 }
2520
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002524 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002525 return null;
2526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(subId);
2531 if (phone != null) {
2532 return phone.getCdmaEriText();
2533 } else {
2534 return null;
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539 }
2540
2541 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002542 * Returns the CDMA MDN.
2543 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002545 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2547 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548
2549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002552 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 return phone.getLine1Number();
2554 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002555 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556 return null;
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002560 }
2561 }
2562
2563 /**
2564 * Returns the CDMA MIN.
2565 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002567 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2569 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2575 return phone.getCdmaMin();
2576 } else {
2577 return null;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002581 }
2582 }
2583
Hall Liud892bec2018-11-30 14:51:45 -08002584 @Override
2585 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2586 INumberVerificationCallback callback, String callingPackage) {
2587 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2588 != PERMISSION_GRANTED) {
2589 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2590 }
2591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2592
2593 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2594 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2595 throw new SecurityException("Calling package must be configured in the device config");
2596 }
2597
2598 if (range == null) {
2599 throw new NullPointerException("Range must be non-null");
2600 }
2601
2602 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002603 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002604
2605 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2606 }
2607
Junda Liuca05d5d2014-08-14 22:36:34 -07002608 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 * Returns true if CDMA provisioning needs to run.
2610 */
2611 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002614 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 } finally {
2616 Binder.restoreCallingIdentity(identity);
2617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
2620 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002621 * Sets the voice mail number of a given subId.
2622 */
2623 @Override
2624 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002625 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2630 new Pair<String, String>(alphaTag, number), new Integer(subId));
2631 return success;
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002635 }
2636
Ta-wei Yen87c49842016-05-13 21:19:52 -07002637 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002638 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2639 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002640 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002641 if (!TextUtils.equals(callingPackage, systemDialer)) {
2642 throw new SecurityException("caller must be system dialer");
2643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2648 if (phoneAccountHandle == null) {
2649 return null;
2650 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002651 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002654 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002655 }
2656
2657 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002658 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002661 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002662 return null;
2663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002665 final long identity = Binder.clearCallingIdentity();
2666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002667 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002671 }
2672
2673 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002674 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2675 VisualVoicemailSmsFilterSettings settings) {
2676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677
2678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002681 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002685 }
2686
2687 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002688 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690
2691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002694 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002698 }
2699
2700 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002701 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2702 String callingPackage, int subId) {
2703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
2705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002708 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 } finally {
2710 Binder.restoreCallingIdentity(identity);
2711 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002712 }
2713
2714 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002715 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002716 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002721 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002725 }
2726
2727 @Override
2728 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2729 String number, int port, String text, PendingIntent sentIntent) {
2730 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002731 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002732 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002733 SmsController smsController = PhoneFactory.getSmsController();
2734 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2735 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002736 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002737
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002738 /**
fionaxu0152e512016-11-14 13:36:14 -08002739 * Sets the voice activation state of a given subId.
2740 */
2741 @Override
2742 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2744 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745
2746 final long identity = Binder.clearCallingIdentity();
2747 try {
2748 final Phone phone = getPhone(subId);
2749 if (phone != null) {
2750 phone.setVoiceActivationState(activationState);
2751 } else {
2752 loge("setVoiceActivationState fails with invalid subId: " + subId);
2753 }
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002756 }
2757 }
2758
2759 /**
2760 * Sets the data activation state of a given subId.
2761 */
2762 @Override
2763 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2765 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(subId);
2770 if (phone != null) {
2771 phone.setDataActivationState(activationState);
2772 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002773 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002777 }
2778 }
2779
2780 /**
2781 * Returns the voice activation state of a given subId.
2782 */
2783 @Override
2784 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002785 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786
fionaxu0152e512016-11-14 13:36:14 -08002787 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 if (phone != null) {
2791 return phone.getVoiceActivationState();
2792 } else {
2793 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2794 }
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002797 }
2798 }
2799
2800 /**
2801 * Returns the data activation state of a given subId.
2802 */
2803 @Override
2804 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002805 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806
fionaxu0152e512016-11-14 13:36:14 -08002807 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 if (phone != null) {
2811 return phone.getDataActivationState();
2812 } else {
2813 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002817 }
2818 }
2819
2820 /**
Wink Saville36469e72014-06-11 15:17:00 -07002821 * Returns the unread count of voicemails for a subId
2822 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002823 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002824 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2826 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2827 return 0;
2828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 final Phone phone = getPhone(subId);
2832 if (phone != null) {
2833 return phone.getVoiceMessageCount();
2834 } else {
2835 return 0;
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 }
2841
2842 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002843 * returns true, if the device is in a state where both voice and data
2844 * are supported simultaneously. This can change based on location or network condition.
2845 */
2846 @Override
2847 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 final Phone phone = getPhone(subId);
2851 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002855 }
2856
2857 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002858 * Send the dialer code if called from the current default dialer or the caller has
2859 * carrier privilege.
2860 * @param inputCode The dialer code to send
2861 */
2862 @Override
2863 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002865 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2867 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002868 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002869 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2870 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 } finally {
2877 Binder.restoreCallingIdentity(identity);
2878 }
fionaxu235cc5e2017-03-06 22:25:57 -08002879 }
2880
Pengquan Menga1bb6272018-09-06 09:59:22 -07002881 @Override
2882 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002883 if (!isActiveSubscription(subId)) {
2884 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2885 }
2886
Pengquan Menga1bb6272018-09-06 09:59:22 -07002887 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2888 }
2889
Brad Ebinger35c841c2018-10-01 10:40:55 -07002890 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002891 public boolean isInEmergencySmsMode() {
2892 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 for (Phone phone : PhoneFactory.getPhones()) {
2896 if (phone.isInEmergencySmsMode()) {
2897 return true;
2898 }
2899 }
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
2902 }
2903 return false;
2904 }
2905
2906 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002907 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2908 throws RemoteException {
2909 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002910 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2911 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2912 "IMS not available on device.");
2913 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002914 final long token = Binder.clearCallingIdentity();
2915 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002917 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002918 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002919 } catch (ImsException e) {
2920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002921 } finally {
2922 Binder.restoreCallingIdentity(token);
2923 }
2924 }
2925
2926 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002927 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2928 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2930 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2931 }
2932 Binder.withCleanCallingIdentity(() -> {
2933 try {
2934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002935 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002936 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002937 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002938 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2939 + "is inactive, ignoring unregister.");
2940 // If the subscription is no longer active, just return, since the callback
2941 // will already have been removed internally.
2942 }
2943 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002944 }
2945
2946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002947 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2948 throws RemoteException {
2949 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002950 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2951 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2952 "IMS not available on device.");
2953 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2955 final long token = Binder.clearCallingIdentity();
2956 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002957 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002959 } catch (ImsException e) {
2960 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 } finally {
2962 Binder.restoreCallingIdentity(token);
2963 }
2964 }
2965
2966 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002967 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2968 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002969
2970 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2971 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2972 }
2973 Binder.withCleanCallingIdentity(() -> {
2974 try {
2975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002976 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002977 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002978 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002979 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2980 + "is inactive, ignoring unregister.");
2981 // If the subscription is no longer active, just return, since the callback
2982 // will already have been removed internally.
2983 }
2984 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 }
2986
2987 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002988 public boolean isCapable(int subId, int capability, int regTech) {
2989 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2991 final long token = Binder.clearCallingIdentity();
2992 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002993 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002995 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2997 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002998 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002999 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3000 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003001 } finally {
3002 Binder.restoreCallingIdentity(token);
3003 }
3004 }
3005
3006 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003007 public boolean isAvailable(int subId, int capability, int regTech) {
3008 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 final long token = Binder.clearCallingIdentity();
3010 try {
3011 Phone phone = getPhone(subId);
3012 if (phone == null) return false;
3013 return phone.isImsCapabilityAvailable(capability, regTech);
3014 } finally {
3015 Binder.restoreCallingIdentity(token);
3016 }
3017 }
3018
Brad Ebinger77b832e2019-10-17 17:03:22 -07003019 /**
3020 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3021 * subscription.
3022 * @param subId The subscription to use to check the configuration.
3023 * @param callback The callback that will be used to send the result.
3024 * @param capability The MmTelFeature capability that will be used to send the result.
3025 * @param transportType The transport type of the MmTelFeature capability.
3026 */
3027 @Override
3028 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3029 int transportType) {
3030 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3031 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3033 "IMS not available on device.");
3034 }
3035 final long token = Binder.clearCallingIdentity();
3036 try {
3037 int slotId = getSlotIndex(subId);
3038 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3039 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3040 + subId + "'");
3041 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3042 }
3043 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3044 transportType, aBoolean -> {
3045 try {
3046 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3047 } catch (RemoteException e) {
3048 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3049 + "running. Ignore");
3050 }
3051 });
3052 } finally {
3053 Binder.restoreCallingIdentity(token);
3054 }
3055 }
3056
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 @Override
3058 public boolean isAdvancedCallingSettingEnabled(int subId) {
3059 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3061 final long token = Binder.clearCallingIdentity();
3062 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003065 } catch (ImsException e) {
3066 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 } finally {
3068 Binder.restoreCallingIdentity(token);
3069 }
3070 }
3071
3072 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003073 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003075 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003079 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003080 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003081 } catch (ImsException e) {
3082 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
3086 }
3087
3088 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003089 public boolean isVtSettingEnabled(int subId) {
3090 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003094 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3095 } catch (ImsException e) {
3096 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
3100 }
3101
3102 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003103 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003105 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003109 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003110 } catch (ImsException e) {
3111 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 } finally {
3113 Binder.restoreCallingIdentity(identity);
3114 }
3115 }
3116
3117 @Override
3118 public boolean isVoWiFiSettingEnabled(int subId) {
3119 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3120 final long identity = Binder.clearCallingIdentity();
3121 try {
3122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003123 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003125 } catch (ImsException e) {
3126 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
3132 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003133 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003135 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003140 } catch (ImsException e) {
3141 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 } finally {
3143 Binder.restoreCallingIdentity(identity);
3144 }
3145 }
3146
3147 @Override
3148 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3149 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003153 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003155 } catch (ImsException e) {
3156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
3160 }
3161
3162 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003163 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003165 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003169 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003171 } catch (ImsException e) {
3172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003173 } finally {
3174 Binder.restoreCallingIdentity(identity);
3175 }
3176 }
3177
3178 @Override
3179 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3181 "setVoWiFiNonPersistent");
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003185 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003186 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003187 } catch (ImsException e) {
3188 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
3192 }
3193
3194 @Override
3195 public int getVoWiFiModeSetting(int subId) {
3196 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003200 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003201 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003202 } catch (ImsException e) {
3203 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
3207 }
3208
3209 @Override
3210 public void setVoWiFiModeSetting(int subId, int mode) {
3211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3212 "setVoWiFiModeSetting");
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003216 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003217 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003218 } catch (ImsException e) {
3219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
3223 }
3224
3225 @Override
3226 public int getVoWiFiRoamingModeSetting(int subId) {
3227 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003231 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003233 } catch (ImsException e) {
3234 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
3238 }
3239
3240 @Override
3241 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3243 "setVoWiFiRoamingModeSetting");
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003247 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003249 } catch (ImsException e) {
3250 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
3254 }
3255
3256 @Override
3257 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3259 "setRttCapabilityEnabled");
3260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003263 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3264 } catch (ImsException e) {
3265 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 } finally {
3267 Binder.restoreCallingIdentity(identity);
3268 }
3269 }
3270
3271 @Override
3272 public boolean isTtyOverVolteEnabled(int subId) {
3273 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003279 } catch (ImsException e) {
3280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
3284 }
3285
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003286 @Override
3287 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3288 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003292 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003293 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003294 } catch (ImsException e) {
3295 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
3299 }
3300
3301 @Override
3302 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3303 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3304 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003305 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3306 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3307 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003308 try {
3309 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003310 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003311 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003312 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003313 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3314 + "is inactive, ignoring unregister.");
3315 // If the subscription is no longer active, just return, since the callback will already
3316 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
3320 }
3321
3322 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003323 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3324 boolean isProvisioned) {
3325 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3326 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3327 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3328 }
3329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3330 "setProvisioningStatusForCapability");
3331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3334 Phone phone = getPhone(subId);
3335 if (phone == null) {
3336 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3337 + subId);
3338 return;
3339 }
3340 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3341 return;
3342 }
3343
3344 // this capability requires provisioning, route to the correct API.
3345 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3346 switch (capability) {
3347 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3348 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3349 ims.setVolteProvisioned(isProvisioned);
3350 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3351 ims.setWfcProvisioned(isProvisioned);
3352 }
3353 break;
3354 }
3355 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3356 // There is currently no difference in VT provisioning type.
3357 ims.setVtProvisioned(isProvisioned);
3358 break;
3359 }
3360 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3361 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3362 // change the capability of the feature instead if needed.
3363 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3364 == isProvisioned) {
3365 // No change in provisioning.
3366 return;
3367 }
3368 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3369 try {
3370 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003371 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003372 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3373 + ", Exception" + e.getMessage());
3374 }
3375 break;
3376 }
3377 default: {
3378 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3379 + capability + "', which does not require provisioning.");
3380 }
3381 }
3382
3383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
3389 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3390 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3391 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3392 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3393 }
3394 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3398 Phone phone = getPhone(subId);
3399 if (phone == null) {
3400 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3401 + subId);
3402 // We will fail with "true" as the provisioning status because this is the default
3403 // if we do not require provisioning.
3404 return true;
3405 }
3406
3407 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3408 return true;
3409 }
3410
3411 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3412 switch (capability) {
3413 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3414 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3415 return ims.isVolteProvisionedOnDevice();
3416 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3417 return ims.isWfcProvisionedOnDevice();
3418 }
3419 // This should never happen, since we are checking tech above to make sure it
3420 // is either LTE or IWLAN.
3421 throw new IllegalArgumentException("Invalid radio technology for voice "
3422 + "capability.");
3423 }
3424 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3425 // There is currently no difference in VT provisioning type.
3426 return ims.isVtProvisionedOnDevice();
3427 }
3428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3429 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3430 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3431 }
3432 default: {
3433 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3434 + capability + "', which does not require provisioning.");
3435 }
3436 }
3437
3438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
3441 }
3442
3443 @Override
3444 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3445 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3446 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3447 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3448 }
3449 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3450 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3451 return (provisionedBits & capability) > 0;
3452 }
3453
3454 @Override
3455 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3456 boolean isProvisioned) {
3457 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3458 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3459 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3460 }
3461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3462 "setProvisioningStatusForCapability");
3463 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3464 // If the current provisioning status for capability already matches isProvisioned,
3465 // do nothing.
3466 if (((provisionedBits & capability) > 0) == isProvisioned) {
3467 return;
3468 }
3469 if (isProvisioned) {
3470 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3471 } else {
3472 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3473 }
3474 }
3475
3476 /**
3477 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3478 * technology. The bitfield should mirror the bitfield defined by
3479 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3480 */
3481 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3482 String key = getMmTelProvisioningKey(subId, tech);
3483 // Default is no capabilities are provisioned.
3484 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3485 }
3486
3487 /**
3488 * Sets the MmTel capability provisioning bitfield (defined by
3489 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3490 * technology specified.
3491 *
3492 * Note: This is a synchronous command and should not be called on UI thread.
3493 */
3494 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3495 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3496 String key = getMmTelProvisioningKey(subId, tech);
3497 editor.putInt(key, newField);
3498 editor.commit();
3499 }
3500
3501 private static String getMmTelProvisioningKey(int subId, int tech) {
3502 // resulting key is provision_ims_mmtel_{subId}_{tech}
3503 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3504 }
3505
3506 /**
3507 * Query CarrierConfig to see if the specified capability requires provisioning for the
3508 * carrier associated with the subscription id.
3509 */
3510 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3511 int capability) {
3512 CarrierConfigManager configManager = new CarrierConfigManager(context);
3513 PersistableBundle c = configManager.getConfigForSubId(subId);
3514 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003515 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003516 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3517 false);
3518 boolean requireVoiceVtProvisioning = c.getBoolean(
3519 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3520
3521 // First check to make sure that the capability requires provisioning.
3522 switch (capability) {
3523 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3524 // intentional fallthrough
3525 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3526 if (requireVoiceVtProvisioning) {
3527 // Voice and Video requires provisioning
3528 return true;
3529 }
3530 break;
3531 }
3532 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3533 if (requireUtProvisioning) {
3534 // UT requires provisioning
3535 return true;
3536 }
3537 break;
3538 }
3539 }
3540 return false;
3541 }
3542
3543 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003544 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3546 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3547 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003548 enforceReadPrivilegedPermission("getImsProvisioningInt");
3549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003552 int slotId = getSlotIndex(subId);
3553 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3554 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3555 + subId + "' for key:" + key);
3556 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3557 }
3558 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003559 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003560 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3561 + subId + "' for key:" + key);
3562 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
3566 }
3567
3568 @Override
3569 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003570 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3571 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3572 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003573 enforceReadPrivilegedPermission("getImsProvisioningString");
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003577 int slotId = getSlotIndex(subId);
3578 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3579 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3580 + subId + "' for key:" + key);
3581 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3582 }
3583 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003584 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003585 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3586 + subId + "' for key:" + key);
3587 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
3591 }
3592
3593 @Override
3594 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003595 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3596 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3597 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3599 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003603 int slotId = getSlotIndex(subId);
3604 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3605 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3606 + subId + "' for key:" + key);
3607 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3608 }
3609 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003610 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003611 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3612 + "' for key:" + key);
3613 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
3619 @Override
3620 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003621 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3622 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3623 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3625 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003629 int slotId = getSlotIndex(subId);
3630 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3631 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3632 + subId + "' for key:" + key);
3633 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3634 }
3635 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003636 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003637 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3638 + "' for key:" + key);
3639 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
3643 }
3644
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003645 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 int slotId = SubscriptionManager.getSlotIndex(subId);
3647 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003648 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3649 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003650 }
3651 return slotId;
3652 }
3653
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003654 private int getSlotIndex(int subId) {
3655 int slotId = SubscriptionManager.getSlotIndex(subId);
3656 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3657 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3658 }
3659 return slotId;
3660 }
3661
Wink Saville36469e72014-06-11 15:17:00 -07003662 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003663 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003664 */
3665 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003666 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003667 final int targetSdk = getTargetSdk(callingPackage);
3668 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3669 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3670 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003671 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3672 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003673 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3674 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 final Phone phone = getPhone(subId);
3679 if (phone != null) {
3680 return phone.getServiceState().getDataNetworkType();
3681 } else {
3682 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3683 }
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003687 }
3688
3689 /**
3690 * Returns the data network type
3691 */
3692 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003693 public int getDataNetworkType(String callingPackage) {
3694 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003695 }
3696
3697 /**
3698 * Returns the data network type for a subId
3699 */
3700 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003701 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003703 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003704 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3705 }
3706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 final Phone phone = getPhone(subId);
3710 if (phone != null) {
3711 return phone.getServiceState().getDataNetworkType();
3712 } else {
3713 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3714 }
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 }
3719
3720 /**
Wink Saville36469e72014-06-11 15:17:00 -07003721 * Returns the Voice network type for a subId
3722 */
3723 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003724 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003726 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003727 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3728 }
3729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 final Phone phone = getPhone(subId);
3733 if (phone != null) {
3734 return phone.getServiceState().getVoiceNetworkType();
3735 } else {
3736 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3737 }
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003741 }
3742
3743 /**
3744 * @return true if a ICC card is present
3745 */
3746 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003747 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003748 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3749 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003750 }
3751
3752 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003753 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003754 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003755 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003756 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 final Phone phone = PhoneFactory.getPhone(slotIndex);
3760 if (phone != null) {
3761 return phone.getIccCard().hasIccCard();
3762 } else {
3763 return false;
3764 }
3765 } finally {
3766 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003768 }
3769
3770 /**
3771 * Return if the current radio is LTE on CDMA. This
3772 * is a tri-state return value as for a period of time
3773 * the mode may be unknown.
3774 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003775 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003776 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003777 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003778 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003779 @Override
3780 public int getLteOnCdmaMode(String callingPackage) {
3781 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003782 }
3783
Sanket Padawe356d7632015-06-22 14:03:32 -07003784 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003785 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003787 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003788 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3789 }
3790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 final Phone phone = getPhone(subId);
3794 if (phone == null) {
3795 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3796 } else {
3797 return phone.getLteOnCdmaMode();
3798 }
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003801 }
Wink Saville36469e72014-06-11 15:17:00 -07003802 }
3803
Wink Saville36469e72014-06-11 15:17:00 -07003804 /**
3805 * {@hide}
3806 * Returns Default subId, 0 in the case of single standby.
3807 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003808 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003809 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003810 }
3811
Shishir Agrawala9f32182016-04-12 12:00:16 -07003812 private int getSlotForDefaultSubscription() {
3813 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3814 }
3815
Wink Savilleb564aae2014-10-23 10:18:09 -07003816 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003817 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003818 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003819
Pengquan Menge92a50d2018-09-21 15:54:48 -07003820 private boolean isActiveSubscription(int subId) {
3821 return mSubscriptionController.isActiveSubId(subId);
3822 }
3823
Ihab Awadf2177b72013-11-25 13:33:23 -08003824 /**
3825 * @see android.telephony.TelephonyManager.WifiCallingChoices
3826 */
3827 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003830 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3832 getWhenToMakeWifiCallsDefaultPreference());
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
3835 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003836 }
3837
3838 /**
3839 * @see android.telephony.TelephonyManager.WifiCallingChoices
3840 */
3841 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003842 final long identity = Binder.clearCallingIdentity();
3843 try {
3844 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003845 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
3849 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003850 }
3851
Sailesh Nepald1e68152013-12-12 19:08:02 -08003852 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003853 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003854 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003855 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003856
Jordan Liu4c733742019-02-28 12:03:40 -08003857 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3858 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3859 if (phoneId == -1) {
3860 throw new IllegalArgumentException("Given slot index: " + slotIndex
3861 + " does not correspond to an active phone");
3862 }
3863 return PhoneFactory.getPhone(phoneId);
3864 }
3865
Shishir Agrawal566b7612013-10-28 14:41:00 -07003866 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003867 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3868 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3870 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003872 if (DBG) {
3873 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3874 }
3875 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3876 p2);
3877 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003878
Jordan Liu4c733742019-02-28 12:03:40 -08003879
3880 @Override
3881 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3882 int slotIndex, String callingPackage, String aid, int p2) {
3883 enforceModifyPermission();
3884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3885 if (DBG) {
3886 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3887 }
3888 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3889 callingPackage, aid, p2);
3890 }
3891
3892 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3893 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894 final long identity = Binder.clearCallingIdentity();
3895 try {
3896 if (TextUtils.equals(ISDR_AID, aid)) {
3897 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3899 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900 if (bestComponent == null
3901 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3902 loge("The calling package is not allowed to access ISD-R.");
3903 throw new SecurityException(
3904 "The calling package is not allowed to access ISD-R.");
3905 }
Derek Tan740e1672017-06-27 14:56:27 -07003906 }
Derek Tan740e1672017-06-27 14:56:27 -07003907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003909 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3910 null /* workSource */);
3911 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 return response;
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003916 }
3917
3918 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003919 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3921 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003922 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3923 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3924 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003925
Jordan Liu4c733742019-02-28 12:03:40 -08003926 @Override
3927 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3928 enforceModifyPermission();
3929 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3930 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3931 channel);
3932 }
3933
3934 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 final long identity = Binder.clearCallingIdentity();
3936 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 if (channel < 0) {
3938 return false;
3939 }
Jordan Liu4c733742019-02-28 12:03:40 -08003940 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3941 null /* workSource */);
3942 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 return success;
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003946 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003947 }
3948
3949 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003950 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003951 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3953 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003954 if (DBG) {
3955 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3956 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3957 + p3 + " data=" + data);
3958 }
3959 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3960 command, p1, p2, p3, data);
3961 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003962
Jordan Liu4c733742019-02-28 12:03:40 -08003963 @Override
3964 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3965 int command, int p1, int p2, int p3, String data) {
3966 enforceModifyPermission();
3967 if (DBG) {
3968 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3969 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3970 + p3 + " data=" + data);
3971 }
3972 return iccTransmitApduLogicalChannelWithPermission(
3973 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3974 data);
3975 }
3976
3977 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3978 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 final long identity = Binder.clearCallingIdentity();
3980 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003981 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982 return "";
3983 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003985 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003986 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3987 null /* workSource */);
3988 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 // Append the returned status code to the end of the response payload.
3991 String s = Integer.toHexString(
3992 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3993 if (response.payload != null) {
3994 s = IccUtils.bytesToHexString(response.payload) + s;
3995 }
3996 return s;
3997 } finally {
3998 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003999 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004000 }
Jake Hambye994d462014-02-03 13:10:13 -08004001
Evan Charltonc66da362014-05-16 14:06:40 -07004002 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004003 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4004 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4006 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004008 if (DBG) {
4009 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4010 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4011 }
4012 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4013 cla, command, p1, p2, p3, data);
4014 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004015
Jordan Liu4c733742019-02-28 12:03:40 -08004016 @Override
4017 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4018 int command, int p1, int p2, int p3, String data) {
4019 enforceModifyPermission();
4020 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4021 if (DBG) {
4022 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4023 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4024 + " data=" + data);
4025 }
4026
4027 return iccTransmitApduBasicChannelWithPermission(
4028 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4029 p2, p3, data);
4030 }
4031
4032 // open APDU basic channel assuming the caller has sufficient permissions
4033 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4034 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4038 && TextUtils.equals(ISDR_AID, data)) {
4039 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4041 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 if (bestComponent == null
4043 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4044 loge("The calling package is not allowed to select ISD-R.");
4045 throw new SecurityException(
4046 "The calling package is not allowed to select ISD-R.");
4047 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004048 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004051 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4052 null /* workSource */);
4053 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055 // Append the returned status code to the end of the response payload.
4056 String s = Integer.toHexString(
4057 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4058 if (response.payload != null) {
4059 s = IccUtils.bytesToHexString(response.payload) + s;
4060 }
4061 return s;
4062 } finally {
4063 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004064 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004065 }
4066
4067 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004068 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004069 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4071 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 if (DBG) {
4076 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4077 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4078 }
4079
4080 IccIoResult response =
4081 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4082 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4083 subId);
4084
4085 if (DBG) {
4086 log("Exchange SIM_IO [R]" + response);
4087 }
4088
4089 byte[] result = null;
4090 int length = 2;
4091 if (response.payload != null) {
4092 length = 2 + response.payload.length;
4093 result = new byte[length];
4094 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4095 } else {
4096 result = new byte[length];
4097 }
4098
4099 result[length - 1] = (byte) response.sw2;
4100 result[length - 2] = (byte) response.sw1;
4101 return result;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004104 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004105 }
4106
Nathan Haroldb3014052017-01-25 15:57:32 -08004107 /**
4108 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4109 * on a particular subscription
4110 */
sqianb6e41952018-03-12 14:54:01 -07004111 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4113 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4114 return null;
4115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116
4117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 if (appType != TelephonyManager.APPTYPE_USIM
4120 && appType != TelephonyManager.APPTYPE_SIM) {
4121 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4122 return null;
4123 }
4124 Object response = sendRequest(
4125 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4126 if (response instanceof String[]) {
4127 return (String[]) response;
4128 }
yincheng zhaod698b842019-09-06 17:06:54 -07004129 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004131 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004134 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004135 }
4136
yincheng zhaod698b842019-09-06 17:06:54 -07004137 /**
4138 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4139 * subscription.
4140 *
4141 * @param subId the id of the subscription.
4142 * @param appType the uicc app type, must be USIM or SIM.
4143 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4144 * @param callingPackage the op Package name.
4145 * @return number of fplmns that is successfully written to the SIM.
4146 */
4147 public int setForbiddenPlmns(
4148 int subId, int appType, List<String> fplmns, String callingPackage) {
4149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4150 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4151 if (DBG) logv("no permissions for setForbiddenplmns");
4152 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4153 }
4154 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4155 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4156 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4157 }
4158 if (fplmns == null) {
4159 throw new IllegalArgumentException("Fplmn List provided is null");
4160 }
4161 for (String fplmn : fplmns) {
4162 if (!CellIdentity.isValidPlmn(fplmn)) {
4163 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4164 }
4165 }
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 Object response = sendRequest(
4169 CMD_SET_FORBIDDEN_PLMNS,
4170 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4171 subId);
4172 return (int) response;
4173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
4176 }
4177
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004178 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004179 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4181 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 final long identity = Binder.clearCallingIdentity();
4184 try {
4185 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4186 if (response.payload == null) {
4187 return "";
4188 }
Evan Charltonc66da362014-05-16 14:06:40 -07004189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 // Append the returned status code to the end of the response payload.
4191 String s = Integer.toHexString(
4192 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4193 s = IccUtils.bytesToHexString(response.payload) + s;
4194 return s;
4195 } finally {
4196 Binder.restoreCallingIdentity(identity);
4197 }
Evan Charltonc66da362014-05-16 14:06:40 -07004198 }
4199
Jake Hambye994d462014-02-03 13:10:13 -08004200 /**
4201 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4202 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4203 *
4204 * @param itemID the ID of the item to read
4205 * @return the NV item as a String, or null on error.
4206 */
4207 @Override
4208 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4211 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212
4213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004216 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4218 return value;
4219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
Jake Hambye994d462014-02-03 13:10:13 -08004222 }
4223
4224 /**
4225 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4226 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4227 *
4228 * @param itemID the ID of the item to read
4229 * @param itemValue the value to write, as a String
4230 * @return true on success; false on any failure
4231 */
4232 @Override
4233 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4236 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237
4238 final long identity = Binder.clearCallingIdentity();
4239 try {
4240 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4241 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004242 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4244 return success;
4245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
Jake Hambye994d462014-02-03 13:10:13 -08004248 }
4249
4250 /**
4251 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4252 * Used for device configuration by some CDMA operators.
4253 *
4254 * @param preferredRoamingList byte array containing the new PRL
4255 * @return true on success; false on any failure
4256 */
4257 @Override
4258 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4260 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261
4262 final long identity = Binder.clearCallingIdentity();
4263 try {
4264 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4265 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4266 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4267 return success;
4268 } finally {
4269 Binder.restoreCallingIdentity(identity);
4270 }
Jake Hambye994d462014-02-03 13:10:13 -08004271 }
4272
4273 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004274 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004275 * Used for device configuration by some CDMA operators.
4276 *
chen xu6dac5ab2018-10-26 17:39:23 -07004277 * @param slotIndex - device slot.
4278 *
Jake Hambye994d462014-02-03 13:10:13 -08004279 * @return true on success; false on any failure
4280 */
4281 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004282 public boolean resetModemConfig(int slotIndex) {
4283 Phone phone = PhoneFactory.getPhone(slotIndex);
4284 if (phone != null) {
4285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4286 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287
chen xu6dac5ab2018-10-26 17:39:23 -07004288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4291 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4292 return success;
4293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 }
chen xu6dac5ab2018-10-26 17:39:23 -07004297 return false;
4298 }
4299
4300 /**
4301 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4302 *
4303 * @param slotIndex - device slot.
4304 *
4305 * @return true on success; false on any failure
4306 */
4307 @Override
4308 public boolean rebootModem(int slotIndex) {
4309 Phone phone = PhoneFactory.getPhone(slotIndex);
4310 if (phone != null) {
4311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4312 mApp, phone.getSubId(), "rebootModem");
4313
4314 final long identity = Binder.clearCallingIdentity();
4315 try {
4316 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4317 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4318 return success;
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004324 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004325
Svet Ganovb320e182015-04-16 12:30:10 -07004326 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004327 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004329 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004330 return new String[0];
4331 }
4332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 final long identity = Binder.clearCallingIdentity();
4334 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004335 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
Wink Saville36469e72014-06-11 15:17:00 -07004339 }
4340
Brad Ebinger51f743a2017-01-23 13:50:20 -08004341 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004342 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4343 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004344 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004345 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004346 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347
4348 final long identity = Binder.clearCallingIdentity();
4349 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004350 ImsResolver resolver = PhoneFactory.getImsResolver();
4351 if (resolver == null) {
4352 // may happen if the device does not support IMS.
4353 return;
4354 }
4355 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004359 }
4360
4361 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004362 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4363 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004364 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004365 public void disableIms(int slotId) {
4366 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367
4368 final long identity = Binder.clearCallingIdentity();
4369 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004370 ImsResolver resolver = PhoneFactory.getImsResolver();
4371 if (resolver == null) {
4372 // may happen if the device does not support IMS.
4373 return;
4374 }
4375 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004379 }
4380
4381 /**
4382 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4383 * feature or {@link null} if the service is not available. If the feature is available, the
4384 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4385 */
4386 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004387 IImsServiceFeatureCallback callback) {
4388 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389
4390 final long identity = Binder.clearCallingIdentity();
4391 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004392 ImsResolver resolver = PhoneFactory.getImsResolver();
4393 if (resolver == null) {
4394 // may happen if the device does not support IMS.
4395 return null;
4396 }
4397 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004401 }
4402
4403 /**
4404 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4405 * feature during emergency calling or {@link null} if the service is not available. If the
4406 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4407 * listener for feature updates.
4408 */
4409 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4410 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411
4412 final long identity = Binder.clearCallingIdentity();
4413 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004414 ImsResolver resolver = PhoneFactory.getImsResolver();
4415 if (resolver == null) {
4416 // may happen if the device does not support IMS.
4417 return null;
4418 }
4419 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004423 }
4424
Brad Ebinger5f64b052017-12-14 14:26:15 -08004425 /**
4426 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004427 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004428 */
4429 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431
4432 final long identity = Binder.clearCallingIdentity();
4433 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004434 ImsResolver resolver = PhoneFactory.getImsResolver();
4435 if (resolver == null) {
4436 // may happen if the device does not support IMS.
4437 return null;
4438 }
4439 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 } finally {
4441 Binder.restoreCallingIdentity(identity);
4442 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004443 }
4444
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004445 /**
4446 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004447 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004448 */
4449 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004451
4452 final long identity = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004454 ImsResolver resolver = PhoneFactory.getImsResolver();
4455 if (resolver == null) {
4456 // may happen if the device does not support IMS.
4457 return null;
4458 }
4459 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004463 }
4464
Brad Ebinger884c07b2018-02-15 16:17:40 -08004465 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004466 * Sets the ImsService Package Name that Telephony will bind to.
4467 *
4468 * @param slotId the slot ID that the ImsService should bind for.
4469 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4470 * ImsService is the device default ImsService.
4471 * @param packageName The package name of the application that contains the ImsService to bind
4472 * to.
4473 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4474 * @hide
4475 */
4476 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004477 int[] subIds = SubscriptionManager.getSubId(slotId);
4478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4479 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4480 "setImsService");
4481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004484 ImsResolver resolver = PhoneFactory.getImsResolver();
4485 if (resolver == null) {
4486 // may happen if the device does not support IMS.
4487 return false;
4488 }
4489 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4490 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004494 }
4495
4496 /**
4497 * Return the ImsService configuration.
4498 *
4499 * @param slotId The slot that the ImsService is associated with.
4500 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4501 * the device default.
4502 * @return the package name of the ImsService configuration.
4503 */
4504 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004505 int[] subIds = SubscriptionManager.getSubId(slotId);
4506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4507 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4508 "getImsService");
4509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004512 ImsResolver resolver = PhoneFactory.getImsResolver();
4513 if (resolver == null) {
4514 // may happen if the device does not support IMS.
4515 return "";
4516 }
4517 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004521 }
4522
Brad Ebinger77b832e2019-10-17 17:03:22 -07004523 /**
4524 * Get the MmTelFeature state associated with the requested subscription id.
4525 * @param subId The subscription that the MmTelFeature is associated with.
4526 * @param callback A callback with an integer containing the
4527 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4528 */
4529 @Override
4530 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4531 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4532 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4533 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4534 "IMS not available on device.");
4535 }
4536 final long token = Binder.clearCallingIdentity();
4537 try {
4538 int slotId = getSlotIndex(subId);
4539 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4540 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4541 + subId + "'");
4542 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4543 }
4544 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4545 try {
4546 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4547 } catch (RemoteException e) {
4548 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4549 + "Ignore");
4550 }
4551 });
4552 } finally {
4553 Binder.restoreCallingIdentity(token);
4554 }
4555 }
4556
Wink Saville36469e72014-06-11 15:17:00 -07004557 public void setImsRegistrationState(boolean registered) {
4558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559
4560 final long identity = Binder.clearCallingIdentity();
4561 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004562 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
Wink Saville36469e72014-06-11 15:17:00 -07004566 }
4567
4568 /**
Stuart Scott54788802015-03-30 13:18:01 -07004569 * Set the network selection mode to automatic.
4570 *
4571 */
4572 @Override
4573 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4575 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576
Pengquan Menge92a50d2018-09-21 15:54:48 -07004577 if (!isActiveSubscription(subId)) {
4578 return;
4579 }
4580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 final long identity = Binder.clearCallingIdentity();
4582 try {
4583 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4584 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
Stuart Scott54788802015-03-30 13:18:01 -07004588 }
4589
Pengquan Mengea84e042018-09-20 14:57:26 -07004590 /**
4591 * Ask the radio to connect to the input network and change selection mode to manual.
4592 *
4593 * @param subId the id of the subscription.
4594 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4595 * the operator to attach to.
4596 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4597 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4598 * normal network selection next time.
4599 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004600 */
4601 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004602 public boolean setNetworkSelectionModeManual(
4603 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4605 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004606
4607 if (!isActiveSubscription(subId)) {
4608 return false;
4609 }
4610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004611 final long identity = Binder.clearCallingIdentity();
4612 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004613 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004615 if (DBG) {
4616 log("setNetworkSelectionModeManual: subId: " + subId
4617 + " operator: " + operatorInfo);
4618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004623 }
4624
4625 /**
4626 * Scans for available networks.
4627 */
4628 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004629 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4631 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004632 LocationAccessPolicy.LocationPermissionResult locationResult =
4633 LocationAccessPolicy.checkLocationPermission(mApp,
4634 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4635 .setCallingPackage(callingPackage)
4636 .setCallingPid(Binder.getCallingPid())
4637 .setCallingUid(Binder.getCallingUid())
4638 .setMethod("getCellNetworkScanResults")
4639 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4640 .build());
4641 switch (locationResult) {
4642 case DENIED_HARD:
4643 throw new SecurityException("Not allowed to access scan results -- location");
4644 case DENIED_SOFT:
4645 return null;
4646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647
Pengquan Menga1bb6272018-09-06 09:59:22 -07004648 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 try {
4650 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004651 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004656 }
4657
4658 /**
yinxub1bed742017-04-17 11:45:04 -07004659 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004660 *
yinxub1bed742017-04-17 11:45:04 -07004661 * @param subId id of the subscription
4662 * @param request contains the radio access networks with bands/channels to scan
4663 * @param messenger callback messenger for scan results or errors
4664 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004665 * @return the id of the requested scan which can be used to stop the scan.
4666 */
4667 @Override
4668 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004669 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4671 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004672 LocationAccessPolicy.LocationPermissionResult locationResult =
4673 LocationAccessPolicy.checkLocationPermission(mApp,
4674 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4675 .setCallingPackage(callingPackage)
4676 .setCallingPid(Binder.getCallingPid())
4677 .setCallingUid(Binder.getCallingUid())
4678 .setMethod("requestNetworkScan")
4679 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4680 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004681 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004682 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004683 if (e != null) {
4684 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4685 throw e;
4686 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004687 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004688 return TelephonyScanManager.INVALID_SCAN_ID;
4689 }
4690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 }
Hall Liu912dfd32019-04-25 14:02:26 -07004692 int callingUid = Binder.getCallingUid();
4693 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 return mNetworkScanRequestTracker.startNetworkScan(
4697 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004698 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004699 } finally {
4700 Binder.restoreCallingIdentity(identity);
4701 }
yinxu504e1392017-04-12 16:03:22 -07004702 }
4703
Hall Liub2ac8ef2019-02-28 15:56:23 -08004704 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004705 NetworkScanRequest request, int subId) {
4706 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4707 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4708 boolean hasNetworkScanPermission =
4709 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4710 == PERMISSION_GRANTED;
4711
4712 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4713 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4714 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004715 }
4716
4717 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4718 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004719 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4720 return new SecurityException("Specific channels must not be"
4721 + " scanned without location access.");
4722 }
4723 }
4724 }
4725
Hall Liub2ac8ef2019-02-28 15:56:23 -08004726 return null;
4727 }
4728
yinxu504e1392017-04-12 16:03:22 -07004729 /**
4730 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004731 *
4732 * @param subId id of the subscription
4733 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004734 */
4735 @Override
4736 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739
Hall Liu912dfd32019-04-25 14:02:26 -07004740 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741 final long identity = Binder.clearCallingIdentity();
4742 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004743 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 } finally {
4745 Binder.restoreCallingIdentity(identity);
4746 }
yinxu504e1392017-04-12 16:03:22 -07004747 }
4748
4749 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004750 * Get the calculated preferred network type.
4751 * Used for debugging incorrect network type.
4752 *
4753 * @return the preferred network type, defined in RILConstants.java.
4754 */
4755 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004756 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004757 final Phone defaultPhone = getDefaultPhone();
4758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4759 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004760 return RILConstants.PREFERRED_NETWORK_MODE;
4761 }
4762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004766 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767 } finally {
4768 Binder.restoreCallingIdentity(identity);
4769 }
Junda Liu84d15a22014-07-02 11:21:04 -07004770 }
4771
4772 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004773 * Get the preferred network type.
4774 * Used for device configuration by some CDMA operators.
4775 *
4776 * @return the preferred network type, defined in RILConstants.java.
4777 */
4778 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004779 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004780 TelephonyPermissions
4781 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4782 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783
4784 final long identity = Binder.clearCallingIdentity();
4785 try {
4786 if (DBG) log("getPreferredNetworkType");
4787 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4788 int networkType = (result != null ? result[0] : -1);
4789 if (DBG) log("getPreferredNetworkType: " + networkType);
4790 return networkType;
4791 } finally {
4792 Binder.restoreCallingIdentity(identity);
4793 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004794 }
4795
4796 /**
4797 * Set the preferred network type.
4798 * Used for device configuration by some CDMA operators.
4799 *
4800 * @param networkType the preferred network type, defined in RILConstants.java.
4801 * @return true on success; false on any failure.
4802 */
4803 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004804 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4806 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807
4808 final long identity = Binder.clearCallingIdentity();
4809 try {
4810 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4811 Boolean success = (Boolean) sendRequest(
4812 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4813 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4814 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004815 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4817 }
4818 return success;
4819 } finally {
4820 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004821 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004822 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004823
4824 /**
Miaoa84611c2019-03-15 09:21:10 +08004825 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004826 *
Miaoa84611c2019-03-15 09:21:10 +08004827 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004828 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004829 * @hide
4830 */
4831 @Override
Miaoa84611c2019-03-15 09:21:10 +08004832 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004835 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836 try {
Miaoa84611c2019-03-15 09:21:10 +08004837 if (phone != null) {
4838 return phone.hasMatchedTetherApnSetting();
4839 } else {
4840 return false;
4841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 } finally {
4843 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004844 }
Junda Liu475951f2014-11-07 16:45:03 -08004845 }
4846
4847 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004848 * Set mobile data enabled
4849 * Used by the user through settings etc to turn on/off mobile data
4850 *
4851 * @param enable {@code true} turn turn data on, else {@code false}
4852 */
4853 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004854 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4856 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857
4858 final long identity = Binder.clearCallingIdentity();
4859 try {
4860 int phoneId = mSubscriptionController.getPhoneId(subId);
4861 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4862 Phone phone = PhoneFactory.getPhone(phoneId);
4863 if (phone != null) {
4864 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004865 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004867 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868 }
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004871 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004872 }
4873
4874 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004875 * Get the user enabled state of Mobile Data.
4876 *
4877 * TODO: remove and use isUserDataEnabled.
4878 * This can't be removed now because some vendor codes
4879 * calls through ITelephony directly while they should
4880 * use TelephonyManager.
4881 *
4882 * @return true on enabled
4883 */
4884 @Override
4885 public boolean getDataEnabled(int subId) {
4886 return isUserDataEnabled(subId);
4887 }
4888
4889 /**
4890 * Get whether mobile data is enabled per user setting.
4891 *
4892 * There are other factors deciding whether mobile data is actually enabled, but they are
4893 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004894 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004895 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004896 *
4897 * @return {@code true} if data is enabled else {@code false}
4898 */
4899 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004900 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004901 try {
4902 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4903 null);
4904 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4906 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908
4909 final long identity = Binder.clearCallingIdentity();
4910 try {
4911 int phoneId = mSubscriptionController.getPhoneId(subId);
4912 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4913 Phone phone = PhoneFactory.getPhone(phoneId);
4914 if (phone != null) {
4915 boolean retVal = phone.isUserDataEnabled();
4916 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4917 return retVal;
4918 } else {
4919 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4920 return false;
4921 }
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004924 }
4925 }
4926
4927 /**
4928 * Get whether mobile data is enabled.
4929 *
4930 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4931 * whether mobile data is actually enabled.
4932 *
4933 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4934 *
4935 * @return {@code true} if data is enabled else {@code false}
4936 */
4937 @Override
4938 public boolean isDataEnabled(int subId) {
4939 try {
4940 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4941 null);
4942 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4944 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946
4947 final long identity = Binder.clearCallingIdentity();
4948 try {
4949 int phoneId = mSubscriptionController.getPhoneId(subId);
4950 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4951 Phone phone = PhoneFactory.getPhone(phoneId);
4952 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004953 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4955 return retVal;
4956 } else {
4957 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4958 return false;
4959 }
4960 } finally {
4961 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004962 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004963 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004964
4965 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004966 public int getCarrierPrivilegeStatus(int subId) {
4967 final Phone phone = getPhone(subId);
4968 if (phone == null) {
4969 loge("getCarrierPrivilegeStatus: Invalid subId");
4970 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4971 }
4972 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004973 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004974 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004975 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4976 }
4977 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004978 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004979 }
Junda Liu29340342014-07-10 15:23:27 -07004980
4981 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004982 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4983 final Phone phone = getPhone(subId);
4984 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004985 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4987 }
4988 UiccProfile profile =
4989 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4990 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004991 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004992 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4993 }
4994 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4995 }
4996
4997 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004998 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4999 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005000 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005001 }
5002
5003 int phoneId = SubscriptionManager.getPhoneId(subId);
5004 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005005 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005006 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005007 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5008 }
chen xuf7e9fe82019-05-09 19:31:02 -07005009
5010 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005011 }
5012
5013 @Override
5014 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005015 if (TextUtils.isEmpty(pkgName))
5016 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005017 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5018 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5019 UiccCard card = UiccController.getInstance().getUiccCard(i);
5020 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005021 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005022 continue;
5023 }
5024
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005025 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005026 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5027 break;
5028 }
5029 }
5030
5031 return result;
Junda Liu29340342014-07-10 15:23:27 -07005032 }
Derek Tan89e89d42014-07-08 17:00:10 -07005033
5034 @Override
Junda Liue64de782015-04-16 17:19:16 -07005035 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5036 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5037 loge("phoneId " + phoneId + " is not valid.");
5038 return null;
5039 }
5040 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005041 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005042 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005043 return null ;
5044 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005045 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005046 }
5047
Amith Yamasani6e118872016-02-19 12:53:51 -08005048 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005049 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005050 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005051 List<String> privilegedPackages = new ArrayList<>();
5052 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005053 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5054 // has UICC in that slot.
5055 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005056 if (card.hasCarrierPrivilegeRules()) {
5057 if (packages == null) {
5058 // Only check packages in user 0 for now
5059 packages = pm.getInstalledPackagesAsUser(
5060 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07005061 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
5062 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005063 }
5064 for (int p = packages.size() - 1; p >= 0; p--) {
5065 PackageInfo pkgInfo = packages.get(p);
5066 if (pkgInfo != null && pkgInfo.packageName != null
5067 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005068 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005069 privilegedPackages.add(pkgInfo.packageName);
5070 }
5071 }
5072 }
5073 }
5074 return privilegedPackages;
5075 }
5076
chen xuf7e9fe82019-05-09 19:31:02 -07005077 @Override
5078 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5079 List<String> privilegedPackages = new ArrayList<>();
5080 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5081 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5082 }
5083 return privilegedPackages;
5084 }
5085
Wink Savilleb564aae2014-10-23 10:18:09 -07005086 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005087 final Phone phone = getPhone(subId);
5088 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005089 if (card == null) {
5090 loge("getIccId: No UICC");
5091 return null;
5092 }
5093 String iccId = card.getIccId();
5094 if (TextUtils.isEmpty(iccId)) {
5095 loge("getIccId: ICC ID is null or empty.");
5096 return null;
5097 }
5098 return iccId;
5099 }
5100
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005101 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005102 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5103 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005104 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5105 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 final String iccId = getIccId(subId);
5110 final Phone phone = getPhone(subId);
5111 if (phone == null) {
5112 return false;
5113 }
5114 final String subscriberId = phone.getSubscriberId();
5115
5116 if (DBG_MERGE) {
5117 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5118 + subscriberId + " to " + number);
5119 }
5120
5121 if (TextUtils.isEmpty(iccId)) {
5122 return false;
5123 }
5124
5125 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5126
5127 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5128 if (alphaTag == null) {
5129 editor.remove(alphaTagPrefKey);
5130 } else {
5131 editor.putString(alphaTagPrefKey, alphaTag);
5132 }
5133
5134 // Record both the line number and IMSI for this ICCID, since we need to
5135 // track all merged IMSIs based on line number
5136 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5137 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5138 if (number == null) {
5139 editor.remove(numberPrefKey);
5140 editor.remove(subscriberPrefKey);
5141 } else {
5142 editor.putString(numberPrefKey, number);
5143 editor.putString(subscriberPrefKey, subscriberId);
5144 }
5145
5146 editor.commit();
5147 return true;
5148 } finally {
5149 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005150 }
Derek Tan7226c842014-07-02 17:42:23 -07005151 }
5152
5153 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005154 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005155 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005157 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005158 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005159 return null;
5160 }
Derek Tan97ebb422014-09-05 16:55:38 -07005161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 final long identity = Binder.clearCallingIdentity();
5163 try {
5164 String iccId = getIccId(subId);
5165 if (iccId != null) {
5166 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5167 if (DBG_MERGE) {
5168 log("getLine1NumberForDisplay returning "
5169 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5170 }
5171 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5174 return null;
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005177 }
Derek Tan7226c842014-07-02 17:42:23 -07005178 }
5179
5180 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005181 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005183 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005184 return null;
5185 }
Derek Tan97ebb422014-09-05 16:55:38 -07005186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 String iccId = getIccId(subId);
5190 if (iccId != null) {
5191 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5192 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5193 }
5194 return null;
5195 } finally {
5196 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005197 }
Derek Tan7226c842014-07-02 17:42:23 -07005198 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005199
5200 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005201 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005202 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5203 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005204 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005205 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5206 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005207 return null;
5208 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005209
Jordan Liub49b04b2019-05-06 14:45:15 -07005210 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5211 // the process, where TelephonyManager was instantiated.
5212 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005213 final long identity = Binder.clearCallingIdentity();
5214 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005215 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 final TelephonyManager tele = TelephonyManager.from(context);
5217 final SubscriptionManager sub = SubscriptionManager.from(context);
5218
5219 // Figure out what subscribers are currently active
5220 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221
Jordan Liub49b04b2019-05-06 14:45:15 -07005222 // Only consider subs which match the current subId
5223 // This logic can be simplified. See b/131189269 for progress.
5224 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005225 activeSubscriberIds.add(tele.getSubscriberId(subId));
5226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227
5228 // First pass, find a number override for an active subscriber
5229 String mergeNumber = null;
5230 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5231 for (String key : prefs.keySet()) {
5232 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5233 final String subscriberId = (String) prefs.get(key);
5234 if (activeSubscriberIds.contains(subscriberId)) {
5235 final String iccId = key.substring(
5236 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5237 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5238 mergeNumber = (String) prefs.get(numberKey);
5239 if (DBG_MERGE) {
5240 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5241 + " for active subscriber " + subscriberId);
5242 }
5243 if (!TextUtils.isEmpty(mergeNumber)) {
5244 break;
5245 }
5246 }
5247 }
5248 }
5249
5250 // Shortcut when no active merged subscribers
5251 if (TextUtils.isEmpty(mergeNumber)) {
5252 return null;
5253 }
5254
5255 // Second pass, find all subscribers under that line override
5256 final ArraySet<String> result = new ArraySet<>();
5257 for (String key : prefs.keySet()) {
5258 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5259 final String number = (String) prefs.get(key);
5260 if (mergeNumber.equals(number)) {
5261 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5262 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5263 final String subscriberId = (String) prefs.get(subscriberKey);
5264 if (!TextUtils.isEmpty(subscriberId)) {
5265 result.add(subscriberId);
5266 }
5267 }
5268 }
5269 }
5270
5271 final String[] resultArray = result.toArray(new String[result.size()]);
5272 Arrays.sort(resultArray);
5273 if (DBG_MERGE) {
5274 Slog.d(LOG_TAG,
5275 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5276 }
5277 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005278 } finally {
5279 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005280 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005281 }
5282
5283 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005284 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5285 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5286
5287 final long identity = Binder.clearCallingIdentity();
5288 try {
5289 final TelephonyManager telephonyManager = mApp.getSystemService(
5290 TelephonyManager.class);
5291 String subscriberId = telephonyManager.getSubscriberId(subId);
5292 if (subscriberId == null) {
5293 if (DBG) {
5294 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5295 + subId);
5296 }
5297 return null;
5298 }
5299
5300 final SubscriptionInfo info = SubscriptionController.getInstance()
5301 .getSubscriptionInfo(subId);
5302 final ParcelUuid groupUuid = info.getGroupUuid();
5303 // If it doesn't belong to any group, return just subscriberId of itself.
5304 if (groupUuid == null) {
5305 return new String[]{subscriberId};
5306 }
5307
5308 // Get all subscriberIds from the group.
5309 final List<String> mergedSubscriberIds = new ArrayList<>();
5310 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5311 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5312 for (SubscriptionInfo subInfo : groupInfos) {
5313 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5314 if (subscriberId != null) {
5315 mergedSubscriberIds.add(subscriberId);
5316 }
5317 }
5318
5319 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322
5323 }
5324 }
5325
5326 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005327 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5329 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330
5331 final long identity = Binder.clearCallingIdentity();
5332 try {
5333 final Phone phone = getPhone(subId);
5334 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005338 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005339
5340 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005341 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005342 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5343 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005344 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345
5346 final long identity = Binder.clearCallingIdentity();
5347 try {
5348 final Phone phone = getPhone(subId);
5349 if (phone == null) {
5350 return false;
5351 }
5352 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5353 cdmaNonRoamingList);
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005356 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005357 }
5358
5359 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005360 @Deprecated
5361 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5362 enforceModifyPermission();
5363
5364 int returnValue = 0;
5365 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005366 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005367 if(result.exception == null) {
5368 if (result.result != null) {
5369 byte[] responseData = (byte[])(result.result);
5370 if(responseData.length > oemResp.length) {
5371 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5372 responseData.length + "bytes. Buffer Size is " +
5373 oemResp.length + "bytes.");
5374 }
5375 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5376 returnValue = responseData.length;
5377 }
5378 } else {
5379 CommandException ex = (CommandException) result.exception;
5380 returnValue = ex.getCommandError().ordinal();
5381 if(returnValue > 0) returnValue *= -1;
5382 }
5383 } catch (RuntimeException e) {
5384 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5385 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5386 if(returnValue > 0) returnValue *= -1;
5387 }
5388
5389 return returnValue;
5390 }
5391
5392 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005393 public void setRadioCapability(RadioAccessFamily[] rafs) {
5394 try {
5395 ProxyController.getInstance().setRadioCapability(rafs);
5396 } catch (RuntimeException e) {
5397 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5398 }
5399 }
5400
5401 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005402 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005403 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005404 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005405 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005406 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
chen xub97461a2018-10-26 14:17:57 -07005410 TelephonyPermissions
5411 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5412 mApp, phone.getSubId(), "getRadioAccessFamily");
5413 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
chen xub97461a2018-10-26 14:17:57 -07005417 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005418 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005419
5420 @Override
5421 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005422 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005423 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424
5425 final long identity = Binder.clearCallingIdentity();
5426 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005427 ImsManager.getInstance(defaultPhone.getContext(),
5428 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005432 }
5433
5434 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005435 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005436 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005438 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005439 return false;
5440 }
Svet Ganovb320e182015-04-16 12:30:10 -07005441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 final long identity = Binder.clearCallingIdentity();
5443 try {
5444 // Check the user preference and the system-level IMS setting. Even if the user has
5445 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5446 // In the long run, we may instead need to check if there exists a connection service
5447 // which can support video calling.
5448 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005449 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 return imsManager.isVtEnabledByPlatform()
5451 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5452 && imsManager.isVtEnabledByUser();
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
5455 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005456 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005457
Andrew Leea1239f22015-03-02 17:44:07 -08005458 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5461 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5462 return false;
5463 }
5464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 CarrierConfigManager configManager =
5468 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005469 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
Andrew Leea1239f22015-03-02 17:44:07 -08005474 }
5475
5476 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 public boolean isWorldPhone(int subId, String callingPackage) {
5478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5479 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5480 return false;
5481 }
5482
5483 final long identity = Binder.clearCallingIdentity();
5484 try {
5485 CarrierConfigManager configManager =
5486 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005487 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
Andrew Leea1239f22015-03-02 17:44:07 -08005492 }
5493
Andrew Lee9431b832015-03-09 18:46:45 -07005494 @Override
5495 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005496 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005497 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005498 }
5499
5500 @Override
5501 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 final long identity = Binder.clearCallingIdentity();
5503 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005504 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Andrew Lee9431b832015-03-09 18:46:45 -07005508 }
5509
Hall Liuf6668912018-10-31 17:05:23 -07005510 /**
5511 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5512 * support for the feature and device firmware support.
5513 *
5514 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5515 */
5516 @Override
5517 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005519 final Phone phone = getPhone(subscriptionId);
5520 if (phone == null) {
5521 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5522 return false;
5523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005525 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5527 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005528 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 return isCarrierSupported && isDeviceSupported;
5530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
Hall Liu98187582018-01-22 19:15:32 -08005533 }
5534
Hall Liuf6668912018-10-31 17:05:23 -07005535 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005536 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5537 * RTT setting, will return true if the device and carrier both support RTT.
5538 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005539 */
5540 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541 final long identity = Binder.clearCallingIdentity();
5542 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005543 boolean isRttSupported = isRttSupported(subscriptionId);
5544 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005545 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005546 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5547 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5548 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005552 }
5553
Sanket Padawe7310cc72015-01-14 09:53:20 -08005554 /**
5555 * Returns the unique device ID of phone, for example, the IMEI for
5556 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5557 *
5558 * <p>Requires Permission:
5559 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5560 */
5561 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005562 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005563 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005564 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005565 return null;
5566 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005567 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005568 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5569 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005570 return null;
5571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572
5573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 return phone.getDeviceId();
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005579 }
5580
Ping Sunc67b7c22016-03-02 19:16:45 +08005581 /**
5582 * {@hide}
5583 * Returns the IMS Registration Status on a particular subid
5584 *
5585 * @param subId
5586 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005587 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005588 Phone phone = getPhone(subId);
5589 if (phone != null) {
5590 return phone.isImsRegistered();
5591 } else {
5592 return false;
5593 }
5594 }
5595
Santos Cordon7a1885b2015-02-03 11:15:19 -08005596 @Override
5597 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5601 } finally {
5602 Binder.restoreCallingIdentity(identity);
5603 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005604 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005605
Tyler Gunnf70ed162019-04-03 15:28:53 -07005606 @Override
5607 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 Phone phone = getPhone(subscriptionId);
5611 if (phone == null) {
5612 return null;
5613 }
5614 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
5618 }
5619
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005620 /**
5621 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005622 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005623 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 Phone phone = getPhone(subId);
5627 if (phone != null) {
5628 return phone.isWifiCallingEnabled();
5629 } else {
5630 return false;
5631 }
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005634 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005635 }
5636
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005637 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005638 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005639 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005640 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 Phone phone = getPhone(subId);
5644 if (phone != null) {
5645 return phone.isVideoEnabled();
5646 } else {
5647 return false;
5648 }
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005651 }
5652 }
5653
5654 /**
5655 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5656 * defined in {@link ImsRegistrationImplBase}.
5657 */
5658 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 Phone phone = getPhone(subId);
5662 if (phone != null) {
5663 return phone.getImsRegistrationTech();
5664 } else {
5665 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5666 }
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005669 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005670 }
5671
Stuart Scott8eef64f2015-04-08 15:13:54 -07005672 @Override
5673 public void factoryReset(int subId) {
5674 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005675 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5676 return;
5677 }
5678
Svet Ganovcc087f82015-05-12 20:35:54 -07005679 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005680
Svet Ganovcc087f82015-05-12 20:35:54 -07005681 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005682 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5683 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005684 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005685 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005686 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005687 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5688 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005689 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005690 // There has been issues when Sms raw table somehow stores orphan
5691 // fragments. They lead to garbled message when new fragments come
5692 // in and combined with those stale ones. In case this happens again,
5693 // user can reset all network settings which will clean up this table.
5694 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005695 // Clean up IMS settings as well here.
5696 int slotId = getSlotIndex(subId);
5697 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5698 ImsManager.getInstance(mApp, slotId).factoryReset();
5699 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005700 } finally {
5701 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005702 }
5703 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005704
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005705 private void cleanUpSmsRawTable(Context context) {
5706 ContentResolver resolver = context.getContentResolver();
5707 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5708 resolver.delete(uri, null, null);
5709 }
5710
Narayan Kamath1c496c22015-04-16 14:40:19 +01005711 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005712 public String getSimLocaleForSubscriber(int subId) {
5713 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5714 final Phone phone = getPhone(subId);
5715 if (phone == null) {
5716 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005717 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 final long identity = Binder.clearCallingIdentity();
5720 try {
chen xu5d3637b2019-01-21 23:31:38 -08005721 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5722 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005723 if (info == null) {
5724 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5725 return null;
5726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 // Try and fetch the locale from the carrier properties or from the SIM language
5728 // preferences (EF-PL and EF-LI)...
5729 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005731 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5732 if (localeFromDefaultSim != null) {
5733 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5734 if (DBG) log("Using locale from subId: " + subId + " locale: "
5735 + localeFromDefaultSim);
5736 return localeFromDefaultSim.toLanguageTag();
5737 } else {
5738 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 }
5740 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 // The SIM language preferences only store a language (e.g. fr = French), not an
5743 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5744 // the SIM and carrier preferences does not include a country we add the country
5745 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005746 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005748 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 return mccLocale.toLanguageTag();
5750 }
5751
5752 if (DBG) log("No locale found - returning null");
5753 return null;
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005757 }
5758
5759 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005760 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005761 }
5762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 /**
5764 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5765 */
5766 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005767 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005768 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005769
Chenjie Yu1ba97252018-01-11 18:16:20 -08005770 private final ModemActivityInfo mLastModemActivityInfo =
5771 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5772
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005773 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005774 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5775 * representing the state of the modem.
5776 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005777 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5778 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005779 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005780 */
5781 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005782 public void requestModemActivityInfo(ResultReceiver result) {
5783 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785
5786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 ModemActivityInfo ret = null;
5789 synchronized (mLastModemActivityInfo) {
5790 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5791 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005792 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005793 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5795 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005796 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5797 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 }
5799 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005800 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5801 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802 mLastModemActivityInfo.setIdleTimeMillis(
5803 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5804 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5805 mLastModemActivityInfo.setRxTimeMillis(
5806 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5807 mLastModemActivityInfo.setEnergyUsed(
5808 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005809 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5811 mLastModemActivityInfo.getSleepTimeMillis(),
5812 mLastModemActivityInfo.getIdleTimeMillis(),
5813 mLastModemActivityInfo.getTxTimeMillis(),
5814 mLastModemActivityInfo.getRxTimeMillis(),
5815 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 Bundle bundle = new Bundle();
5818 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5819 result.send(0, bundle);
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005822 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005823 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005824
Siddharth Rayb8114062018-06-17 15:02:38 -07005825 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5826 // less than total activity duration.
5827 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5828 if (info == null) {
5829 return false;
5830 }
5831 int activityDurationMs =
5832 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5833 int totalTxTimeMs = 0;
5834 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5835 totalTxTimeMs += info.getTxTimeMillis()[i];
5836 }
5837 return (info.isValid()
5838 && (info.getSleepTimeMillis() <= activityDurationMs)
5839 && (info.getIdleTimeMillis() <= activityDurationMs)
5840 && (info.getRxTimeMillis() <= activityDurationMs)
5841 && (totalTxTimeMs <= activityDurationMs));
5842 }
5843
Jack Yu85bd38a2015-11-09 11:34:32 -08005844 /**
5845 * {@hide}
5846 * Returns the service state information on specified subscription.
5847 */
5848 @Override
5849 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005851 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005852 return null;
5853 }
5854
Hall Liuf19c44f2018-11-27 14:38:17 -08005855 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5856 LocationAccessPolicy.checkLocationPermission(mApp,
5857 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5858 .setCallingPackage(callingPackage)
5859 .setCallingPid(Binder.getCallingPid())
5860 .setCallingUid(Binder.getCallingUid())
5861 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005862 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005863 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5864 .build());
5865
5866 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5867 LocationAccessPolicy.checkLocationPermission(mApp,
5868 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5869 .setCallingPackage(callingPackage)
5870 .setCallingPid(Binder.getCallingPid())
5871 .setCallingUid(Binder.getCallingUid())
5872 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005873 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005874 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5875 .build());
5876 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5877 boolean hasFinePermission =
5878 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5879 boolean hasCoarsePermission =
5880 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 final Phone phone = getPhone(subId);
5885 if (phone == null) {
5886 return null;
5887 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005888
Hall Liuf19c44f2018-11-27 14:38:17 -08005889 ServiceState ss = phone.getServiceState();
5890
5891 // Scrub out the location info in ServiceState depending on what level of access
5892 // the caller has.
5893 if (hasFinePermission) return ss;
5894 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5895 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005899 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005900
5901 /**
5902 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5903 *
5904 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5905 * voicemail ringtone.
5906 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5907 * PhoneAccount.
5908 */
5909 @Override
5910 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5914 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005915 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5919 } finally {
5920 Binder.restoreCallingIdentity(identity);
5921 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005922 }
5923
5924 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005925 * Sets the per-account voicemail ringtone.
5926 *
5927 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5928 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5929 *
5930 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5931 * voicemail ringtone.
5932 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5933 * PhoneAccount.
5934 */
5935 @Override
5936 public void setVoicemailRingtoneUri(String callingPackage,
5937 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005938 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005939 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5940 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005941 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5943 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5944 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5950 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005951 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 }
5953 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5954 } finally {
5955 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005956 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005957 }
5958
5959 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005960 * Returns whether vibration is set for voicemail notification in Phone settings.
5961 *
5962 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5963 * voicemail vibration setting.
5964 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5965 */
5966 @Override
5967 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5971 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005972 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5976 } finally {
5977 Binder.restoreCallingIdentity(identity);
5978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005979 }
5980
Youhan Wange64578a2016-05-02 15:32:42 -07005981 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005982 * Sets the per-account voicemail vibration.
5983 *
5984 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5985 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5986 *
5987 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5988 * voicemail vibration setting.
5989 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5990 * specific PhoneAccount.
5991 */
5992 @Override
5993 public void setVoicemailVibrationEnabled(String callingPackage,
5994 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005995 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5997 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005998 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6001 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006002 }
6003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6007 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006008 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 }
6010 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006013 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006014 }
6015
6016 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006017 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6018 *
6019 * @throws SecurityException if the caller does not have the required permission
6020 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006021 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006022 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006023 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006024 }
6025
6026 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006027 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6028 * permission.
6029 *
6030 * @throws SecurityException if the caller does not have the required permission
6031 */
6032 private void enforceSendSmsPermission() {
6033 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6034 }
6035
6036 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006037 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006038 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006039 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006040 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006041 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 final long identity = Binder.clearCallingIdentity();
6043 try {
6044 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006045 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 if (componentName == null) {
6047 throw new SecurityException(
6048 "Caller not current active visual voicemail package[null]");
6049 }
6050 String vvmPackage = componentName.getPackageName();
6051 if (!callingPackage.equals(vvmPackage)) {
6052 throw new SecurityException("Caller not current active visual voicemail package["
6053 + vvmPackage + "]");
6054 }
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006057 }
6058 }
6059
6060 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006061 * Return the application ID for the app type.
6062 *
6063 * @param subId the subscription ID that this request applies to.
6064 * @param appType the uicc app type.
6065 * @return Application ID for specificied app type, or null if no uicc.
6066 */
6067 @Override
6068 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006069 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006070 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071
6072 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006073 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 if (phone == null) {
6075 return null;
6076 }
6077 String aid = null;
6078 try {
6079 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6080 .getApplicationByType(appType).getAid();
6081 } catch (Exception e) {
6082 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6083 }
6084 return aid;
6085 } finally {
6086 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006087 }
Youhan Wange64578a2016-05-02 15:32:42 -07006088 }
6089
Youhan Wang4001d252016-05-11 10:29:41 -07006090 /**
6091 * Return the Electronic Serial Number.
6092 *
6093 * @param subId the subscription ID that this request applies to.
6094 * @return ESN or null if error.
6095 */
6096 @Override
6097 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006098 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006099 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100
6101 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006102 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 if (phone == null) {
6104 return null;
6105 }
6106 String esn = null;
6107 try {
6108 esn = phone.getEsn();
6109 } catch (Exception e) {
6110 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6111 }
6112 return esn;
6113 } finally {
6114 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006115 }
Youhan Wang4001d252016-05-11 10:29:41 -07006116 }
6117
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006118 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006119 * Return the Preferred Roaming List Version.
6120 *
6121 * @param subId the subscription ID that this request applies to.
6122 * @return PRLVersion or null if error.
6123 */
6124 @Override
6125 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006126 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006127 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128
6129 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006130 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 if (phone == null) {
6132 return null;
6133 }
6134 String cdmaPrlVersion = null;
6135 try {
6136 cdmaPrlVersion = phone.getCdmaPrlVersion();
6137 } catch (Exception e) {
6138 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6139 }
6140 return cdmaPrlVersion;
6141 } finally {
6142 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006143 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006144 }
6145
6146 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006147 * Get snapshot of Telephony histograms
6148 * @return List of Telephony histograms
6149 * @hide
6150 */
6151 @Override
6152 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6154 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155
6156 final long identity = Binder.clearCallingIdentity();
6157 try {
6158 return RIL.getTelephonyRILTimingHistograms();
6159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006162 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006163
6164 /**
6165 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006166 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6167 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006168 * Require system privileges. In the future we may add this to carrier APIs.
6169 *
Michele Berionne482f8202018-11-27 18:57:59 -08006170 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006171 */
6172 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006173 @TelephonyManager.SetCarrierRestrictionResult
6174 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006175 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006177
Michele Berionne482f8202018-11-27 18:57:59 -08006178 if (carrierRestrictionRules == null) {
6179 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006180 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 final long identity = Binder.clearCallingIdentity();
6183 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006184 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006185 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006189 }
6190
6191 /**
6192 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006193 * Get the allowed carrier list and the excluded carrier list, including the priority between
6194 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006195 * Require system privileges. In the future we may add this to carrier APIs.
6196 *
Michele Berionne482f8202018-11-27 18:57:59 -08006197 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006198 */
6199 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006200 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006201 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203
6204 final long identity = Binder.clearCallingIdentity();
6205 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006206 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6207 if (response instanceof CarrierRestrictionRules) {
6208 return (CarrierRestrictionRules) response;
6209 }
6210 // Response is an Exception of some kind,
6211 // which is signalled to the user as a NULL retval
6212 return null;
6213 } catch (Exception e) {
6214 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6215 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 } finally {
6217 Binder.restoreCallingIdentity(identity);
6218 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006219 }
6220
fionaxu59545b42016-05-25 15:53:37 -07006221 /**
6222 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6223 * @param subId the subscription ID that this action applies to.
6224 * @param enabled control enable or disable metered apns.
6225 * {@hide}
6226 */
6227 @Override
6228 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6229 enforceModifyPermission();
6230 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231
6232 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006233 if (phone == null) {
6234 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6235 return;
6236 }
6237 try {
6238 phone.carrierActionSetMeteredApnsEnabled(enabled);
6239 } catch (Exception e) {
6240 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 } finally {
6242 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006243 }
6244 }
6245
6246 /**
6247 * Action set from carrier signalling broadcast receivers to enable/disable radio
6248 * @param subId the subscription ID that this action applies to.
6249 * @param enabled control enable or disable radio.
6250 * {@hide}
6251 */
6252 @Override
6253 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6254 enforceModifyPermission();
6255 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256
6257 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006258 if (phone == null) {
6259 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6260 return;
6261 }
6262 try {
6263 phone.carrierActionSetRadioEnabled(enabled);
6264 } catch (Exception e) {
6265 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 } finally {
6267 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006268 }
6269 }
6270
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006271 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006272 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6273 * network status based on which carrier apps could apply actions accordingly,
6274 * enable/disable default url handler for example.
6275 *
6276 * @param subId the subscription ID that this action applies to.
6277 * @param report control start/stop reporting the default network status.
6278 * {@hide}
6279 */
6280 @Override
6281 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6282 enforceModifyPermission();
6283 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284
6285 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006286 if (phone == null) {
6287 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6288 return;
6289 }
6290 try {
6291 phone.carrierActionReportDefaultNetworkStatus(report);
6292 } catch (Exception e) {
6293 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 } finally {
6295 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006296 }
6297 }
6298
6299 /**
fionaxud9622282017-07-17 17:51:30 -07006300 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6301 * @param subId the subscription ID that this action applies to.
6302 * {@hide}
6303 */
6304 @Override
6305 public void carrierActionResetAll(int subId) {
6306 enforceModifyPermission();
6307 final Phone phone = getPhone(subId);
6308 if (phone == null) {
6309 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6310 return;
6311 }
6312 try {
6313 phone.carrierActionResetAll();
6314 } catch (Exception e) {
6315 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6316 }
6317 }
6318
6319 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006320 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6321 * bug report is being generated.
6322 */
6323 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006324 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006325 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6326 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006327 writer.println("Permission Denial: can't dump Phone from pid="
6328 + Binder.getCallingPid()
6329 + ", uid=" + Binder.getCallingUid()
6330 + "without permission "
6331 + android.Manifest.permission.DUMP);
6332 return;
6333 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006334 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006335 }
Jack Yueb89b242016-06-22 13:27:47 -07006336
Brad Ebingerdac2f002018-04-03 15:17:52 -07006337 @Override
6338 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6339 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6340 throws RemoteException {
6341 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6342 }
6343
Jack Yueb89b242016-06-22 13:27:47 -07006344 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006345 * Get aggregated video call data usage since boot.
6346 *
6347 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6348 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006349 * {@hide}
6350 */
6351 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006352 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006353 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6354 null);
6355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 final long identity = Binder.clearCallingIdentity();
6357 try {
6358 // NetworkStatsService keeps tracking the active network interface and identity. It
6359 // records the delta with the corresponding network identity.
6360 // We just return the total video call data usage snapshot since boot.
6361 Phone phone = getPhone(subId);
6362 if (phone != null) {
6363 return phone.getVtDataUsage(perUidStats);
6364 }
6365 return null;
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006368 }
Jack Yueb89b242016-06-22 13:27:47 -07006369 }
Jack Yu75ab2952016-07-08 14:29:33 -07006370
6371 /**
6372 * Policy control of data connection. Usually used when data limit is passed.
6373 * @param enabled True if enabling the data, otherwise disabling.
6374 * @param subId Subscription index
6375 * {@hide}
6376 */
6377 @Override
6378 public void setPolicyDataEnabled(boolean enabled, int subId) {
6379 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380
6381 final long identity = Binder.clearCallingIdentity();
6382 try {
6383 Phone phone = getPhone(subId);
6384 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006385 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 }
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006389 }
6390 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006391
6392 /**
6393 * Get Client request stats
6394 * @return List of Client Request Stats
6395 * @hide
6396 */
6397 @Override
6398 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006400 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006401 return null;
6402 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006403 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 final long identity = Binder.clearCallingIdentity();
6406 try {
6407 if (phone != null) {
6408 return phone.getClientRequestStats();
6409 }
6410
6411 return null;
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006415 }
6416
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006417 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006418 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006419 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006420 }
Jack Yueb4124c2017-02-16 15:32:43 -08006421
6422 /**
Grace Chen70990072017-03-24 17:21:30 -07006423 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006424 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006425 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006426 * @param state State of SIM (power down, power up, pass through)
6427 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6428 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6429 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006430 *
6431 **/
6432 @Override
Grace Chen70990072017-03-24 17:21:30 -07006433 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006434 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006435 Phone phone = PhoneFactory.getPhone(slotIndex);
6436
vagdeviaf9a5b92018-08-15 16:01:53 -07006437 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006442 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 }
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006446 }
6447 }
Shuo Qiandd210312017-04-12 22:11:33 +00006448
Tyler Gunn65d45c22017-06-05 11:22:26 -07006449 private boolean isUssdApiAllowed(int subId) {
6450 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006451 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006452 if (configManager == null) {
6453 return false;
6454 }
6455 PersistableBundle pb = configManager.getConfigForSubId(subId);
6456 if (pb == null) {
6457 return false;
6458 }
6459 return pb.getBoolean(
6460 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6461 }
6462
Shuo Qiandd210312017-04-12 22:11:33 +00006463 /**
6464 * Check if phone is in emergency callback mode
6465 * @return true if phone is in emergency callback mode
6466 * @param subId sub id
6467 */
goneil9c5f4872017-12-05 14:07:56 -08006468 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006469 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006470 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006471 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472
6473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 if (phone != null) {
6476 return phone.isInEcm();
6477 } else {
6478 return false;
6479 }
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006482 }
6483 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006484
6485 /**
6486 * Get the current signal strength information for the given subscription.
6487 * Because this information is not updated when the device is in a low power state
6488 * it should not be relied-upon to be current.
6489 * @param subId Subscription index
6490 * @return the most recent cached signal strength info from the modem
6491 */
6492 @Override
6493 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494 final long identity = Binder.clearCallingIdentity();
6495 try {
6496 Phone p = getPhone(subId);
6497 if (p == null) {
6498 return null;
6499 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 return p.getSignalStrength();
6502 } finally {
6503 Binder.restoreCallingIdentity(identity);
6504 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006505 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006506
Pengquan Meng77b7f132018-08-22 14:49:57 -07006507 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006508 * Get the current modem radio state for the given slot.
6509 * @param slotIndex slot index.
6510 * @param callingPackage the name of the package making the call.
6511 * @return the current radio power state from the modem
6512 */
6513 @Override
6514 public int getRadioPowerState(int slotIndex, String callingPackage) {
6515 Phone phone = PhoneFactory.getPhone(slotIndex);
6516 if (phone != null) {
6517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6518 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6519 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6520 }
6521
6522 final long identity = Binder.clearCallingIdentity();
6523 try {
6524 return phone.getRadioPowerState();
6525 } finally {
6526 Binder.restoreCallingIdentity(identity);
6527 }
6528 }
6529 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6530 }
6531
6532 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006533 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6534 *
6535 * <p>Requires one of the following permissions:
6536 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6537 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6538 * privileges.
6539 *
6540 * @param subId subscription id
6541 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6542 * {@code false}.
6543 */
6544 @Override
6545 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006546 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6547 null /* message */);
6548
Pengquan Menga1bb6272018-09-06 09:59:22 -07006549 boolean isEnabled = false;
6550 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006551 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006552 Phone phone = getPhone(subId);
6553 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006554 } catch (Exception e) {
6555 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6556 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006560 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006561 }
6562
6563
6564 /**
6565 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6566 *
6567 * <p> Requires permission:
6568 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6569 * privileges.
6570 *
6571 * @param subId subscription id
6572 * @param isEnabled {@code true} means enable, {@code false} means disable.
6573 */
6574 @Override
6575 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6577 mApp, subId, "setDataRoamingEnabled");
6578
Pengquan Menga1bb6272018-09-06 09:59:22 -07006579 final long identity = Binder.clearCallingIdentity();
6580 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006581 Phone phone = getPhone(subId);
6582 if (phone != null) {
6583 phone.setDataRoamingEnabled(isEnabled);
6584 }
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006587 }
6588 }
6589
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006590 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006591 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006592 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6593 mApp, subId, "isManualNetworkSelectionAllowed");
6594
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006595 boolean isAllowed = true;
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006598 Phone phone = getPhone(subId);
6599 if (phone != null) {
6600 isAllowed = phone.isCspPlmnEnabled();
6601 }
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604 }
6605 return isAllowed;
6606 }
6607
6608 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006609 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006610 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006611 try {
6612 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006613 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006614 } catch (SecurityException e) {
6615 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6616 // has carrier privileges on an active UICC
6617 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6618 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006619 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006620 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006621 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006625 UiccController uiccController = UiccController.getInstance();
6626 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006627 if (hasReadPermission) {
6628 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006629 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006630
6631 // Remove private info if the caller doesn't have access
6632 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6633 for (UiccCardInfo cardInfo : cardInfos) {
6634 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6635 // is available
6636 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6637 if (card == null || card.getUiccProfile() == null) {
6638 // assume no access if the card or profile is unavailable
6639 filteredInfos.add(cardInfo.getUnprivileged());
6640 continue;
6641 }
6642 UiccProfile profile = card.getUiccProfile();
6643 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6644 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6645 filteredInfos.add(cardInfo);
6646 } else {
6647 filteredInfos.add(cardInfo.getUnprivileged());
6648 }
6649 }
6650 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
6654 }
6655
6656 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006657 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006658 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 final long identity = Binder.clearCallingIdentity();
6661 try {
6662 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6663 if (slots == null) {
6664 Rlog.i(LOG_TAG, "slots is null.");
6665 return null;
6666 }
6667
6668 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6669 for (int i = 0; i < slots.length; i++) {
6670 UiccSlot slot = slots[i];
6671 if (slot == null) {
6672 continue;
6673 }
6674
Jordan Liu7be7e652019-05-06 18:55:02 +00006675 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676 UiccCard card = slot.getUiccCard();
6677 if (card != null) {
6678 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006679 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006680 cardId = slot.getEid();
6681 if (TextUtils.isEmpty(cardId)) {
6682 cardId = slot.getIccId();
6683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 }
6685
Jordan Liu857451f2019-05-09 16:35:35 -07006686 if (cardId != null) {
6687 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6688 // if cardId is an EID, it's all digits so this is fine
6689 cardId = IccUtils.stripTrailingFs(cardId);
6690 }
6691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 int cardState = 0;
6693 switch (slot.getCardState()) {
6694 case CARDSTATE_ABSENT:
6695 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6696 break;
6697 case CARDSTATE_PRESENT:
6698 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6699 break;
6700 case CARDSTATE_ERROR:
6701 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6702 break;
6703 case CARDSTATE_RESTRICTED:
6704 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6705 break;
6706 default:
6707 break;
6708
6709 }
6710
6711 infos[i] = new UiccSlotInfo(
6712 slot.isActive(),
6713 slot.isEuicc(),
6714 cardId,
6715 cardState,
6716 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006717 slot.isExtendedApduSupported(),
6718 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719 }
6720 return infos;
6721 } finally {
6722 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006723 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006724 }
6725
6726 @Override
6727 public boolean switchSlots(int[] physicalSlots) {
6728 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729
6730 final long identity = Binder.clearCallingIdentity();
6731 try {
6732 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006736 }
Jack Yu4c988042018-02-27 15:30:01 -08006737
6738 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006739 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 return UiccController.getInstance().getCardIdForDefaultEuicc();
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
6745 }
6746 }
6747
6748 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006749 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6750 enforceModifyPermission();
6751 final Phone phone = getPhone(subId);
6752 if (phone == null) {
6753 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6754 return;
6755 }
6756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 final long identity = Binder.clearCallingIdentity();
6758 try {
6759 phone.setRadioIndicationUpdateMode(filters, mode);
6760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
Jack Yu4c988042018-02-27 15:30:01 -08006763 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006764
6765 /**
goneil47ffb6e2018-04-06 15:40:58 -07006766 * A test API to reload the UICC profile.
6767 *
6768 * <p>Requires that the calling app has permission
6769 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6770 * @hide
6771 */
6772 @Override
6773 public void refreshUiccProfile(int subId) {
6774 enforceModifyPermission();
6775
6776 final long identity = Binder.clearCallingIdentity();
6777 try {
6778 Phone phone = getPhone(subId);
6779 if (phone == null) {
6780 return;
6781 }
6782 UiccCard uiccCard = phone.getUiccCard();
6783 if (uiccCard == null) {
6784 return;
6785 }
6786 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6787 if (uiccProfile == null) {
6788 return;
6789 }
6790 uiccProfile.refresh();
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
6794 }
6795
6796 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006797 * Returns false if the mobile data is disabled by default, otherwise return true.
6798 */
6799 private boolean getDefaultDataEnabled() {
6800 return "true".equalsIgnoreCase(
6801 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6802 }
6803
6804 /**
6805 * Returns true if the data roaming is enabled by default, i.e the system property
6806 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6807 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6808 */
6809 private boolean getDefaultDataRoamingEnabled(int subId) {
6810 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006811 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006812 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6813 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6814 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6815 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6816 return isDataRoamingEnabled;
6817 }
6818
6819 /**
6820 * Returns the default network type for the given {@code subId}, if the default network type is
6821 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6822 */
6823 private int getDefaultNetworkType(int subId) {
6824 return Integer.parseInt(
6825 TelephonyManager.getTelephonyProperty(
6826 mSubscriptionController.getPhoneId(subId),
6827 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6828 String.valueOf(Phone.PREFERRED_NT_MODE)));
6829 }
fionaxua13278b2018-03-21 00:08:13 -07006830
6831 @Override
6832 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006833 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835
6836 final long identity = Binder.clearCallingIdentity();
6837 try {
6838 final Phone phone = getPhone(subId);
6839 if (phone == null) {
6840 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6841 return;
6842 }
chen xueaba88a2019-03-15 13:15:10 -07006843 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6844 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 } finally {
6846 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006847 }
fionaxua13278b2018-03-21 00:08:13 -07006848 }
6849
6850 @Override
6851 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006852 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853
6854 final long identity = Binder.clearCallingIdentity();
6855 try {
6856 final Phone phone = getPhone(subId);
6857 if (phone == null) {
6858 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6859 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6860 }
6861 return phone.getCarrierIdListVersion();
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006864 }
fionaxua13278b2018-03-21 00:08:13 -07006865 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006866
6867 @Override
6868 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6870 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6871 return -1;
6872 }
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
6879 }
6880 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006881
6882 @Override
6883 public int getCdmaRoamingMode(int subId) {
6884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6885 mApp, subId, "getCdmaRoamingMode");
6886
6887 final long identity = Binder.clearCallingIdentity();
6888 try {
6889 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6890 } finally {
6891 Binder.restoreCallingIdentity(identity);
6892 }
6893 }
6894
6895 @Override
6896 public boolean setCdmaRoamingMode(int subId, int mode) {
6897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6898 mApp, subId, "setCdmaRoamingMode");
6899
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
6902 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6903 } finally {
6904 Binder.restoreCallingIdentity(identity);
6905 }
6906 }
6907
6908 @Override
6909 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6911 mApp, subId, "setCdmaSubscriptionMode");
6912
6913 final long identity = Binder.clearCallingIdentity();
6914 try {
6915 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6916 } finally {
6917 Binder.restoreCallingIdentity(identity);
6918 }
6919 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006920
6921 private void ensureUserRunning(int userId) {
6922 if (!mUserManager.isUserRunning(userId)) {
6923 throw new IllegalStateException("User " + userId + " does not exist or not running");
6924 }
6925 }
6926
6927 /**
6928 * Returns a list of SMS apps on a given user.
6929 *
6930 * Only the shell user (UID 2000 or 0) can call it.
6931 * Target user must be running.
6932 */
6933 @Override
6934 public String[] getSmsApps(int userId) {
6935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6936 ensureUserRunning(userId);
6937
6938 final Collection<SmsApplicationData> apps =
6939 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6940
6941 String[] ret = new String[apps.size()];
6942 int i = 0;
6943 for (SmsApplicationData app : apps) {
6944 ret[i++] = app.mPackageName;
6945 }
6946 return ret;
6947 }
6948
6949 /**
6950 * Returns the default SMS app package name on a given user.
6951 *
6952 * Only the shell user (UID 2000 or 0) can call it.
6953 * Target user must be running.
6954 */
6955 @Override
6956 public String getDefaultSmsApp(int userId) {
6957 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6958 ensureUserRunning(userId);
6959
6960 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6961 /* updateIfNeeded= */ true, userId);
6962 return cn == null ? null : cn.getPackageName();
6963 }
6964
6965 /**
6966 * Set a package as the default SMS app on a given user.
6967 *
6968 * Only the shell user (UID 2000 or 0) can call it.
6969 * Target user must be running.
6970 */
6971 @Override
6972 public void setDefaultSmsApp(int userId, String packageName) {
6973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6974 ensureUserRunning(userId);
6975
6976 boolean found = false;
6977 for (String pkg : getSmsApps(userId)) {
6978 if (TextUtils.equals(packageName, pkg)) {
6979 found = true;
6980 break;
6981 }
6982 }
6983 if (!found) {
6984 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6985 }
6986
6987 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6988 }
sqianc5eccab2018-10-19 18:46:41 -07006989
6990 @Override
sqian8c685422019-02-22 15:55:18 -08006991 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006992 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006994 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006995 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6996 }
6997 final long identity = Binder.clearCallingIdentity();
6998 try {
sqian854d44b2018-12-12 16:48:18 -08006999 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7000 for (Phone phone: PhoneFactory.getPhones()) {
7001 if (phone.getEmergencyNumberTracker() != null
7002 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7003 emergencyNumberListInternal.put(
7004 phone.getSubId(),
7005 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7006 }
sqian11b7a0e2018-12-05 18:48:28 -08007007 }
sqian854d44b2018-12-12 16:48:18 -08007008 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007009 } finally {
7010 Binder.restoreCallingIdentity(identity);
7011 }
sqianc5eccab2018-10-19 18:46:41 -07007012 }
7013
7014 @Override
sqian8c685422019-02-22 15:55:18 -08007015 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007016 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007017 if (!exactMatch) {
7018 TelephonyPermissions
7019 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007020 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007021 }
7022 final long identity = Binder.clearCallingIdentity();
7023 try {
sqian854d44b2018-12-12 16:48:18 -08007024 for (Phone phone: PhoneFactory.getPhones()) {
7025 if (phone.getEmergencyNumberTracker() != null
7026 && phone.getEmergencyNumberTracker() != null) {
7027 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7028 number, exactMatch)) {
7029 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007030 }
7031 }
sqian11b7a0e2018-12-05 18:48:28 -08007032 }
7033 return false;
7034 } finally {
7035 Binder.restoreCallingIdentity(identity);
7036 }
7037 }
7038
sqianf4ca7ed2019-01-15 18:32:07 -08007039 /**
7040 * Update emergency number list for test mode.
7041 */
7042 @Override
7043 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7045 "updateEmergencyNumberListTestMode");
7046
7047 final long identity = Binder.clearCallingIdentity();
7048 try {
7049 for (Phone phone: PhoneFactory.getPhones()) {
7050 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7051 if (tracker != null) {
7052 tracker.executeEmergencyNumberTestModeCommand(action, num);
7053 }
7054 }
7055 } finally {
7056 Binder.restoreCallingIdentity(identity);
7057 }
7058 }
7059
7060 /**
7061 * Get the full emergency number list for test mode.
7062 */
7063 @Override
7064 public List<String> getEmergencyNumberListTestMode() {
7065 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7066 "getEmergencyNumberListTestMode");
7067
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
7070 Set<String> emergencyNumbers = new HashSet<>();
7071 for (Phone phone: PhoneFactory.getPhones()) {
7072 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7073 if (tracker != null) {
7074 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7075 emergencyNumbers.add(num.getNumber());
7076 }
7077 }
7078 }
7079 return new ArrayList<>(emergencyNumbers);
7080 } finally {
7081 Binder.restoreCallingIdentity(identity);
7082 }
7083 }
7084
chen xud6b45bd2018-10-30 22:27:10 -07007085 @Override
7086 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7087 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7088 Phone phone = getPhone(subId);
7089 if (phone == null) {
7090 return null;
7091 }
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 UiccProfile profile = UiccController.getInstance()
7095 .getUiccProfileForPhone(phone.getPhoneId());
7096 if (profile != null) {
7097 return profile.getCertsFromCarrierPrivilegeAccessRules();
7098 }
7099 } finally {
7100 Binder.restoreCallingIdentity(identity);
7101 }
7102 return null;
7103 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007104
7105 /**
7106 * Enable or disable a modem stack.
7107 */
7108 @Override
7109 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7110 enforceModifyPermission();
7111
7112 final long identity = Binder.clearCallingIdentity();
7113 try {
7114 Phone phone = PhoneFactory.getPhone(slotIndex);
7115 if (phone == null) {
7116 return false;
7117 } else {
7118 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7119 }
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
7123 }
Michelecea4cf22018-12-21 15:00:11 -08007124
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007125 /**
7126 * Whether a modem stack is enabled or not.
7127 */
7128 @Override
7129 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7130 Phone phone = PhoneFactory.getPhone(slotIndex);
7131 if (phone == null) return false;
7132
7133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7134 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7135 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7136 }
7137
7138 final long identity = Binder.clearCallingIdentity();
7139 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007140 try {
7141 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7142 } catch (NoSuchElementException ex) {
7143 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7144 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007145 } finally {
7146 Binder.restoreCallingIdentity(identity);
7147 }
7148 }
7149
Michelecea4cf22018-12-21 15:00:11 -08007150 @Override
Michele0ea7d782019-03-19 14:58:42 -07007151 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007152 enforceModifyPermission();
7153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007157 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007158 .commit();
7159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
7162 }
7163
7164 @Override
Michele0ea7d782019-03-19 14:58:42 -07007165 @TelephonyManager.IsMultiSimSupportedResult
7166 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007168 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7169 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007170 }
Michelecea4cf22018-12-21 15:00:11 -08007171
7172 final long identity = Binder.clearCallingIdentity();
7173 try {
Michele0ea7d782019-03-19 14:58:42 -07007174 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007175 } finally {
7176 Binder.restoreCallingIdentity(identity);
7177 }
7178 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007179
Michele0ea7d782019-03-19 14:58:42 -07007180 @TelephonyManager.IsMultiSimSupportedResult
7181 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007182 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7183 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7184 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007185 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7186 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007187 }
7188 // Check if the hardware supports multisim functionality. If usage of multisim is not
7189 // supported by the modem, indicate that it is restricted.
7190 PhoneCapability staticCapability =
7191 mPhoneConfigurationManager.getStaticPhoneCapability();
7192 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007193 loge("isMultiSimSupportedInternal: no static configuration available");
7194 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007195 }
7196 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007197 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7198 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007199 }
7200 // Check if support of multiple SIMs is restricted by carrier
7201 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007202 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007203 }
7204
Michele0ea7d782019-03-19 14:58:42 -07007205 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007206 }
7207
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007208 /**
7209 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007210 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7211 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7212 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007213 * @param numOfSims number of active sims we want to switch to
7214 */
7215 @Override
7216 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007217 if (numOfSims == 1) {
7218 enforceModifyPermission();
7219 } else {
7220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7221 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7222 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007223 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007224
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007225 try {
Michele30b57b22019-03-01 12:01:14 -08007226 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007227 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007228 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7229 return;
7230 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007231 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
7234 }
7235 }
7236
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007237 @Override
7238 public boolean isApplicationOnUicc(int subId, int appType) {
7239 enforceReadPrivilegedPermission("isApplicationOnUicc");
7240 Phone phone = getPhone(subId);
7241 if (phone == null) {
7242 return false;
7243 }
7244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 UiccCard uiccCard = phone.getUiccCard();
7247 if (uiccCard == null) {
7248 return false;
7249 }
7250 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7251 if (uiccProfile == null) {
7252 return false;
7253 }
7254 if (TelephonyManager.APPTYPE_SIM <= appType
7255 && appType <= TelephonyManager.APPTYPE_ISIM) {
7256 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7257 }
7258 return false;
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
7261 }
7262 }
7263
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007264 /**
chen xub4baa772019-04-03 10:23:41 -07007265 * Get whether making changes to modem configurations will trigger reboot.
7266 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007267 */
7268 @Override
chen xub4baa772019-04-03 10:23:41 -07007269 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7271 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7272 return false;
7273 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
7279 }
7280 }
7281
Nathan Harold29f5f052019-02-15 13:41:57 -08007282 private void updateModemStateMetrics() {
7283 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7284 // TODO: check the state for each modem if the api is ready.
7285 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7286 }
7287
Pengquan Meng3889a572019-01-23 11:16:29 -08007288 @Override
7289 public int[] getSlotsMapping() {
7290 enforceReadPrivilegedPermission("getSlotsMapping");
7291
7292 final long identity = Binder.clearCallingIdentity();
7293 try {
7294 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7295 // All logical slots should have a mapping to a physical slot.
7296 int[] logicalSlotsMapping = new int[phoneCount];
7297 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7298 for (int i = 0; i < slotInfos.length; i++) {
7299 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7300 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7301 }
7302 }
7303 return logicalSlotsMapping;
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
7306 }
7307 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007308
7309 /**
7310 * Get the IRadio HAL Version
7311 */
7312 @Override
7313 public int getRadioHalVersion() {
7314 Phone phone = getDefaultPhone();
7315 if (phone == null) return -1;
7316 HalVersion hv = phone.getHalVersion();
7317 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7318 return hv.major * 100 + hv.minor;
7319 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007320
7321 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007322 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7323 * corresponding network requests on a subId.
7324 *
7325 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007326 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007327 * 2) APN is un-metered for this subscription, or
7328 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7329 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7330 *
7331 * @return whether data is allowed for a apn type.
7332 *
7333 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007334 */
7335 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007336 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007338 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7339 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007340 }
7341
7342 // Now that all security checks passes, perform the operation as ourselves.
7343 final long identity = Binder.clearCallingIdentity();
7344 try {
7345 Phone phone = getPhone(subId);
7346 if (phone == null) return false;
7347
Jack Yu41407ee2019-05-13 16:54:09 -07007348 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007349 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
7353 }
7354
7355 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007356 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007357 enforceReadPrivilegedPermission("isApnMetered");
7358
7359 // Now that all security checks passes, perform the operation as ourselves.
7360 final long identity = Binder.clearCallingIdentity();
7361 try {
7362 Phone phone = getPhone(subId);
7363 if (phone == null) return true; // By default return true.
7364
Jack Yu41407ee2019-05-13 16:54:09 -07007365 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007370
7371 @Override
7372 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7373 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7374 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7375 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7376 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7377 }
7378 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7379 Intent intent = new Intent();
7380 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7381 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7382 // Bring up choose default SMS subscription dialog right now
7383 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7384 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7385 mApp.startActivity(intent);
7386 }
chen xud5ca2d52019-05-28 15:20:57 -07007387
7388 @Override
7389 public String getMmsUAProfUrl(int subId) {
7390 //TODO investigate if this API should require proper permission check in R b/133791609
7391 final long identity = Binder.clearCallingIdentity();
7392 try {
7393 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7394 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7395 } finally {
7396 Binder.restoreCallingIdentity(identity);
7397 }
7398 }
7399
7400 @Override
7401 public String getMmsUserAgent(int subId) {
7402 //TODO investigate if this API should require proper permission check in R b/133791609
7403 final long identity = Binder.clearCallingIdentity();
7404 try {
7405 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7406 .getString(com.android.internal.R.string.config_mms_user_agent);
7407 } finally {
7408 Binder.restoreCallingIdentity(identity);
7409 }
7410 }
Jack Yub07d4972019-05-28 16:12:25 -07007411
7412 @Override
7413 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7414 enforceModifyPermission();
7415
7416 // Now that all security checks passes, perform the operation as ourselves.
7417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 Phone phone = getPhone(subId);
7420 if (phone == null) return false;
7421
7422 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7423 } finally {
7424 Binder.restoreCallingIdentity(identity);
7425 }
7426 }
7427
7428 @Override
7429 public boolean isDataAllowedInVoiceCall(int subId) {
7430 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7431
7432 // Now that all security checks passes, perform the operation as ourselves.
7433 final long identity = Binder.clearCallingIdentity();
7434 try {
7435 Phone phone = getPhone(subId);
7436 if (phone == null) return false;
7437
7438 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7439 } finally {
7440 Binder.restoreCallingIdentity(identity);
7441 }
7442 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007443
7444 /**
7445 * Updates whether conference event pacakge handling is enabled.
7446 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7447 * otherwise.
7448 */
7449 @Override
7450 public void setCepEnabled(boolean isCepEnabled) {
7451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7452
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7456 for (Phone phone : PhoneFactory.getPhones()) {
7457 Phone defaultPhone = phone.getImsPhone();
7458 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7459 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7460 ImsPhoneCallTracker imsPhoneCallTracker =
7461 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7462 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7463 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7464 + imsPhone.getMsisdn());
7465 }
7466 }
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
7470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007471}