blob: 8847e175d4a293ec80bb016038dc9db403d8ad87 [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;
Chen Xu227e06f2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070066import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080067import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070068import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070070import android.telephony.CellInfoGsm;
71import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070072import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070074import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070075import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080076import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070077import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080078import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070079import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080080import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080081import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070082import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080083import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080086import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080087import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070089import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080092import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000093import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070094import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080097import android.telephony.data.ApnSetting;
98import 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 Ebingerbc7dd582019-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;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700146import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800148import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800149import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700150import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800151import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700152import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800153import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700154import com.android.internal.telephony.imsphone.ImsPhone;
155import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800156import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700157import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.IccIoResult;
159import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800160import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700161import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800164import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000165import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700166import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700168import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700169import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800170import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700172import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800173
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700174import java.io.FileDescriptor;
175import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800177import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800178import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800179import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800180import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100181import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800182import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700183import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800184import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185
186/**
187 * Implementation of the ITelephony interface.
188 */
Santos Cordon117fee72014-05-16 17:56:12 -0700189public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190 private static final String LOG_TAG = "PhoneInterfaceManager";
191 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
192 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800193 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
195 // Message codes used with mMainThreadHandler
196 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700197 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
198 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199 private static final int CMD_OPEN_CHANNEL = 9;
200 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
201 private static final int CMD_CLOSE_CHANNEL = 11;
202 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800203 private static final int CMD_NV_READ_ITEM = 13;
204 private static final int EVENT_NV_READ_ITEM_DONE = 14;
205 private static final int CMD_NV_WRITE_ITEM = 15;
206 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
207 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
208 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700209 private static final int CMD_RESET_MODEM_CONFIG = 19;
210 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800211 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
212 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
213 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
214 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800215 private static final int CMD_SEND_ENVELOPE = 25;
216 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000217 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
218 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700219 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
220 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
221 private static final int CMD_EXCHANGE_SIM_IO = 31;
222 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800223 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
224 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700225 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
226 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700227 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
228 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700229 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
230 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
231 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
232 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700233 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
234 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
235 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
236 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700237 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800238 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
239 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000240 private static final int CMD_SWITCH_SLOTS = 50;
241 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700242 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
243 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
244 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
245 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
246 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
247 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
248 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
249 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700250 private static final int CMD_GET_ALL_CELL_INFO = 60;
251 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
252 private static final int CMD_GET_CELL_LOCATION = 62;
253 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700254 private static final int CMD_MODEM_REBOOT = 64;
255 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700256 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
257 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800258 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
259 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700260 private static final int CMD_GET_MODEM_STATUS = 70;
261 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700262 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
263 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800265 // Parameters of select command.
266 private static final int SELECT_COMMAND = 0xA4;
267 private static final int SELECT_P1 = 0x04;
268 private static final int SELECT_P2 = 0;
269 private static final int SELECT_P3 = 0x10;
270
Pengquan Meng85728fb2018-03-12 16:31:21 -0700271 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
272 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
273 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /** The singleton instance. */
276 private static PhoneInterfaceManager sInstance;
277
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700280 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private AppOpsManager mAppOps;
282 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800283 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700285 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Derek Tan97ebb422014-09-05 16:55:38 -0700287 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
288 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800289 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800290 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700291
Michelecea4cf22018-12-21 15:00:11 -0800292 // String to store multi SIM allowed
293 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
294
Derek Tan740e1672017-06-27 14:56:27 -0700295 // The AID of ISD-R.
296 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
297
yinxub1bed742017-04-17 11:45:04 -0700298 private NetworkScanRequestTracker mNetworkScanRequestTracker;
299
David Kelly5e06a7f2018-03-12 14:10:59 +0000300 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
301 private static final int MANUFACTURER_CODE_LENGTH = 8;
302
Derek Tan89e89d42014-07-08 17:00:10 -0700303 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700304 * A request object to use for transmitting data to an ICC.
305 */
306 private static final class IccAPDUArgument {
307 public int channel, cla, command, p1, p2, p3;
308 public String data;
309
310 public IccAPDUArgument(int channel, int cla, int command,
311 int p1, int p2, int p3, String data) {
312 this.channel = channel;
313 this.cla = cla;
314 this.command = command;
315 this.p1 = p1;
316 this.p2 = p2;
317 this.p3 = p3;
318 this.data = data;
319 }
320 }
321
322 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700323 * A request object to use for transmitting data to an ICC.
324 */
325 private static final class ManualNetworkSelectionArgument {
326 public OperatorInfo operatorInfo;
327 public boolean persistSelection;
328
329 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
330 this.operatorInfo = operatorInfo;
331 this.persistSelection = persistSelection;
332 }
333 }
334
335 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
337 * request after sending. The main thread will notify the request when it is complete.
338 */
339 private static final class MainThreadRequest {
340 /** The argument to use for the request */
341 public Object argument;
342 /** The result of the request that is run on the main thread */
343 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800344 // The subscriber id that this request applies to. Defaults to
345 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
346 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347
Nathan Harold92bed182018-10-12 18:16:49 -0700348 // In cases where subId is unavailable, the caller needs to specify the phone.
349 public Phone phone;
350
vagdeviaf9a5b92018-08-15 16:01:53 -0700351 public WorkSource workSource;
352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 public MainThreadRequest(Object argument) {
354 this.argument = argument;
355 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800356
Nathan Harold92bed182018-10-12 18:16:49 -0700357 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
358 this.argument = argument;
359 if (phone != null) {
360 this.phone = phone;
361 }
362 this.workSource = workSource;
363 }
364
vagdeviaf9a5b92018-08-15 16:01:53 -0700365 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800367 if (subId != null) {
368 this.subId = subId;
369 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700370 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 }
373
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800374 private static final class IncomingThirdPartyCallArgs {
375 public final ComponentName component;
376 public final String callId;
377 public final String callerDisplayName;
378
379 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
380 String callerDisplayName) {
381 this.component = component;
382 this.callId = callId;
383 this.callerDisplayName = callerDisplayName;
384 }
385 }
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 /**
388 * A handler that processes messages on the main thread in the phone process. Since many
389 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
390 * inbound binder threads to the main thread in the phone process. The Binder thread
391 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
392 * on, which will be notified when the operation completes and will contain the result of the
393 * request.
394 *
395 * <p>If a MainThreadRequest object is provided in the msg.obj field,
396 * note that request.result must be set to something non-null for the calling thread to
397 * unblock.
398 */
399 private final class MainThreadHandler extends Handler {
400 @Override
401 public void handleMessage(Message msg) {
402 MainThreadRequest request;
403 Message onCompleted;
404 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800405 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700406 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800407 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408
409 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700410 case CMD_HANDLE_USSD_REQUEST: {
411 request = (MainThreadRequest) msg.obj;
412 final Phone phone = getPhoneFromRequest(request);
413 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
414 String ussdRequest = ussdObject.first;
415 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700416
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 if (!isUssdApiAllowed(request.subId)) {
418 // Carrier does not support use of this API, return failure.
419 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
420 UssdResponse response = new UssdResponse(ussdRequest, null);
421 Bundle returnData = new Bundle();
422 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
423 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700424
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 request.result = true;
426 notifyRequester(request);
427 return;
428 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700429
Pengquan Menga1bb6272018-09-06 09:59:22 -0700430 try {
431 request.result = phone != null
432 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
433 } catch (CallStateException cse) {
434 request.result = false;
435 }
436 // Wake up the requesting thread
437 notifyRequester(request);
438 break;
pkanwar32d516d2016-10-14 19:37:38 -0700439 }
440
Yorke Lee716f67e2015-06-17 15:39:16 -0700441 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700443 final Phone phone = getPhoneFromRequest(request);
444 request.result = phone != null ?
445 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
446 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800455 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700456 if (uiccCard == null) {
457 loge("iccTransmitApduLogicalChannel: No UICC");
458 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
462 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 iccArgument.channel, iccArgument.cla, iccArgument.command,
465 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700467 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 break;
469
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700471 ar = (AsyncResult) msg.obj;
472 request = (MainThreadRequest) ar.userObj;
473 if (ar.exception == null && ar.result != null) {
474 request.result = ar.result;
475 } else {
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
477 if (ar.result == null) {
478 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800479 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800481 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 } else {
483 loge("iccTransmitApduLogicalChannel: Unknown exception");
484 }
485 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 break;
488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
490 request = (MainThreadRequest) msg.obj;
491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 if (uiccCard == null) {
494 loge("iccTransmitApduBasicChannel: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 } else {
498 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
499 request);
500 uiccCard.iccTransmitApduBasicChannel(
501 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
502 iccArgument.p3, iccArgument.data, onCompleted);
503 }
504 break;
505
506 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
507 ar = (AsyncResult) msg.obj;
508 request = (MainThreadRequest) ar.userObj;
509 if (ar.exception == null && ar.result != null) {
510 request.result = ar.result;
511 } else {
512 request.result = new IccIoResult(0x6F, 0, (byte[])null);
513 if (ar.result == null) {
514 loge("iccTransmitApduBasicChannel: Empty response");
515 } else if (ar.exception instanceof CommandException) {
516 loge("iccTransmitApduBasicChannel: CommandException: " +
517 ar.exception);
518 } else {
519 loge("iccTransmitApduBasicChannel: Unknown exception");
520 }
521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 break;
524
525 case CMD_EXCHANGE_SIM_IO:
526 request = (MainThreadRequest) msg.obj;
527 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 if (uiccCard == null) {
530 loge("iccExchangeSimIO: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 } else {
534 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
535 request);
536 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
537 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
538 iccArgument.data, onCompleted);
539 }
540 break;
541
542 case EVENT_EXCHANGE_SIM_IO_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
547 } else {
548 request.result = new IccIoResult(0x6f, 0, (byte[])null);
549 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 break;
552
Derek Tan4d5e5c12014-02-04 11:54:58 -0800553 case CMD_SEND_ENVELOPE:
554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800555 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 if (uiccCard == null) {
557 loge("sendEnvelopeWithStatus: No UICC");
558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 } else {
561 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
562 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
563 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 break;
565
566 case EVENT_SEND_ENVELOPE_DONE:
567 ar = (AsyncResult) msg.obj;
568 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700569 if (ar.exception == null && ar.result != null) {
570 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
573 if (ar.result == null) {
574 loge("sendEnvelopeWithStatus: Empty response");
575 } else if (ar.exception instanceof CommandException) {
576 loge("sendEnvelopeWithStatus: CommandException: " +
577 ar.exception);
578 } else {
579 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
580 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800583 break;
584
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 case CMD_OPEN_CHANNEL:
586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800587 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800588 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 if (uiccCard == null) {
590 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800591 request.result = new IccOpenLogicalChannelResponse(-1,
592 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800596 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
597 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 break;
600
601 case EVENT_OPEN_CHANNEL_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 int[] result = (int[]) ar.result;
607 int channelId = result[0];
608 byte[] selectResponse = null;
609 if (result.length > 1) {
610 selectResponse = new byte[result.length - 1];
611 for (int i = 1; i < result.length; ++i) {
612 selectResponse[i - 1] = (byte) result[i];
613 }
614 }
615 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 if (ar.result == null) {
619 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 if (ar.exception != null) {
622 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
623 }
624
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700626 if (ar.exception instanceof CommandException) {
627 CommandException.Error error =
628 ((CommandException) (ar.exception)).getCommandError();
629 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700630 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700631 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 }
634 }
635 openChannelResp = new IccOpenLogicalChannelResponse(
636 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700638 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
642 case CMD_CLOSE_CHANNEL:
643 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800644 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700645 if (uiccCard == null) {
646 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900647 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 } else {
650 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
651 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
652 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 break;
654
655 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800656 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
657 break;
658
659 case CMD_NV_READ_ITEM:
660 request = (MainThreadRequest) msg.obj;
661 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800662 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
663 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800664 break;
665
666 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 ar = (AsyncResult) msg.obj;
668 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800669 if (ar.exception == null && ar.result != null) {
670 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 request.result = "";
673 if (ar.result == null) {
674 loge("nvReadItem: Empty response");
675 } else if (ar.exception instanceof CommandException) {
676 loge("nvReadItem: CommandException: " +
677 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 }
681 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 break;
684
Jake Hambye994d462014-02-03 13:10:13 -0800685 case CMD_NV_WRITE_ITEM:
686 request = (MainThreadRequest) msg.obj;
687 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
688 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800689 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700690 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
693 case EVENT_NV_WRITE_ITEM_DONE:
694 handleNullReturnEvent(msg, "nvWriteItem");
695 break;
696
697 case CMD_NV_WRITE_CDMA_PRL:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800700 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_WRITE_CDMA_PRL_DONE:
704 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
705 break;
706
chen xu6dac5ab2018-10-26 17:39:23 -0700707 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800708 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700709 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case EVENT_RESET_MODEM_CONFIG_DONE:
714 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800715 break;
716
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 case CMD_GET_PREFERRED_NETWORK_TYPE:
718 request = (MainThreadRequest) msg.obj;
719 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700720 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800721 break;
722
723 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
724 ar = (AsyncResult) msg.obj;
725 request = (MainThreadRequest) ar.userObj;
726 if (ar.exception == null && ar.result != null) {
727 request.result = ar.result; // Integer
728 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800729 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 if (ar.result == null) {
731 loge("getPreferredNetworkType: Empty response");
732 } else if (ar.exception instanceof CommandException) {
733 loge("getPreferredNetworkType: CommandException: " +
734 ar.exception);
735 } else {
736 loge("getPreferredNetworkType: Unknown exception");
737 }
738 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700739 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 break;
741
742 case CMD_SET_PREFERRED_NETWORK_TYPE:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
745 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700746 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
750 handleNullReturnEvent(msg, "setPreferredNetworkType");
751 break;
752
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000753 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
754 request = (MainThreadRequest)msg.obj;
755 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800756 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000757 break;
758
759 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
760 ar = (AsyncResult)msg.obj;
761 request = (MainThreadRequest)ar.userObj;
762 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700763 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000764 break;
765
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 case CMD_SET_VOICEMAIL_NUMBER:
767 request = (MainThreadRequest) msg.obj;
768 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
769 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800770 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
771 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 break;
773
774 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
775 handleNullReturnEvent(msg, "setVoicemailNumber");
776 break;
777
Stuart Scott54788802015-03-30 13:18:01 -0700778 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
781 request);
782 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
783 break;
784
785 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
786 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
787 break;
788
Shishir Agrawal302c8692015-06-19 13:49:39 -0700789 case CMD_PERFORM_NETWORK_SCAN:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
792 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
793 break;
794
795 case EVENT_PERFORM_NETWORK_SCAN_DONE:
796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 CellNetworkScanResult cellScanResult;
799 if (ar.exception == null && ar.result != null) {
800 cellScanResult = new CellNetworkScanResult(
801 CellNetworkScanResult.STATUS_SUCCESS,
802 (List<OperatorInfo>) ar.result);
803 } else {
804 if (ar.result == null) {
805 loge("getCellNetworkScanResults: Empty response");
806 }
807 if (ar.exception != null) {
808 loge("getCellNetworkScanResults: Exception: " + ar.exception);
809 }
810 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
811 if (ar.exception instanceof CommandException) {
812 CommandException.Error error =
813 ((CommandException) (ar.exception)).getCommandError();
814 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
815 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
816 } else if (error == CommandException.Error.GENERIC_FAILURE) {
817 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
818 }
819 }
820 cellScanResult = new CellNetworkScanResult(errorCode, null);
821 }
822 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700823 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 break;
825
826 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
827 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700828 ManualNetworkSelectionArgument selArg =
829 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
831 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700832 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
833 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null) {
840 request.result = true;
841 } else {
842 request.result = false;
843 loge("setNetworkSelectionModeManual " + ar.exception);
844 }
845 notifyRequester(request);
846 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700847 break;
848
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 case CMD_GET_MODEM_ACTIVITY_INFO:
850 request = (MainThreadRequest) msg.obj;
851 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700852 if (defaultPhone != null) {
853 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
854 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 break;
856
857 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
858 ar = (AsyncResult) msg.obj;
859 request = (MainThreadRequest) ar.userObj;
860 if (ar.exception == null && ar.result != null) {
861 request.result = ar.result;
862 } else {
863 if (ar.result == null) {
864 loge("queryModemActivityInfo: Empty response");
865 } else if (ar.exception instanceof CommandException) {
866 loge("queryModemActivityInfo: CommandException: " +
867 ar.exception);
868 } else {
869 loge("queryModemActivityInfo: Unknown exception");
870 }
871 }
Amit Mahajand4766222016-01-28 15:28:28 -0800872 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
873 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700874 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800875 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700876 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700877 break;
878
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 case CMD_SET_ALLOWED_CARRIERS:
880 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800881 CarrierRestrictionRules argument =
882 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700883 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800884 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 break;
886
887 case EVENT_SET_ALLOWED_CARRIERS_DONE:
888 ar = (AsyncResult) msg.obj;
889 request = (MainThreadRequest) ar.userObj;
890 if (ar.exception == null && ar.result != null) {
891 request.result = ar.result;
892 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800893 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
894 if (ar.exception instanceof CommandException) {
895 loge("setAllowedCarriers: CommandException: " + ar.exception);
896 CommandException.Error error =
897 ((CommandException) (ar.exception)).getCommandError();
898 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
899 request.result =
900 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
901 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700902 } else {
903 loge("setAllowedCarriers: Unknown exception");
904 }
905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700906 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
909 case CMD_GET_ALLOWED_CARRIERS:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case EVENT_GET_ALLOWED_CARRIERS_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result;
920 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800921 request.result = new IllegalStateException(
922 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 if (ar.result == null) {
924 loge("getAllowedCarriers: Empty response");
925 } else if (ar.exception instanceof CommandException) {
926 loge("getAllowedCarriers: CommandException: " +
927 ar.exception);
928 } else {
929 loge("getAllowedCarriers: Unknown exception");
930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 break;
934
Nathan Haroldb3014052017-01-25 15:57:32 -0800935 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 if (ar.exception == null && ar.result != null) {
939 request.result = ar.result;
940 } else {
941 request.result = new IllegalArgumentException(
942 "Failed to retrieve Forbidden Plmns");
943 if (ar.result == null) {
944 loge("getForbiddenPlmns: Empty response");
945 } else {
946 loge("getForbiddenPlmns: Unknown exception");
947 }
948 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700949 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800950 break;
951
952 case CMD_GET_FORBIDDEN_PLMNS:
953 request = (MainThreadRequest) msg.obj;
954 uiccCard = getUiccCardFromRequest(request);
955 if (uiccCard == null) {
956 loge("getForbiddenPlmns() UiccCard is null");
957 request.result = new IllegalArgumentException(
958 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961 }
962 Integer appType = (Integer) request.argument;
963 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
964 if (uiccApp == null) {
965 loge("getForbiddenPlmns() no app with specified type -- "
966 + appType);
967 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800969 break;
970 } else {
971 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
972 + " specified type -- " + appType);
973 }
974 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
975 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
976 onCompleted);
977 break;
978
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000979 case CMD_SWITCH_SLOTS:
980 request = (MainThreadRequest) msg.obj;
981 int[] physicalSlots = (int[]) request.argument;
982 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
983 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
984 break;
985
986 case EVENT_SWITCH_SLOTS_DONE:
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700990 notifyRequester(request);
991 break;
992 case CMD_GET_NETWORK_SELECTION_MODE:
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
995 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
996 break;
997
998 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception != null) {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1003 } else {
1004 int mode = ((int[]) ar.result)[0];
1005 if (mode == 0) {
1006 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1007 } else {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1009 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001010 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001011 notifyRequester(request);
1012 break;
1013 case CMD_GET_CDMA_ROAMING_MODE:
1014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1016 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1017 break;
1018 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
1021 if (ar.exception != null) {
1022 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1023 } else {
1024 request.result = ((int[]) ar.result)[0];
1025 }
1026 notifyRequester(request);
1027 break;
1028 case CMD_SET_CDMA_ROAMING_MODE:
1029 request = (MainThreadRequest) msg.obj;
1030 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1031 int mode = (int) request.argument;
1032 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1033 break;
1034 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
1037 request.result = ar.exception == null;
1038 notifyRequester(request);
1039 break;
1040 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1041 request = (MainThreadRequest) msg.obj;
1042 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1043 int subscriptionMode = (int) request.argument;
1044 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1045 break;
1046 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
1049 request.result = ar.exception == null;
1050 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001051 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001052 case CMD_GET_ALL_CELL_INFO:
1053 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001055 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 case EVENT_GET_ALL_CELL_INFO_DONE:
1058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001060 // If a timeout occurs, the response will be null
1061 request.result = (ar.exception == null && ar.result != null)
1062 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 synchronized (request) {
1064 request.notifyAll();
1065 }
1066 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001067 case CMD_REQUEST_CELL_INFO_UPDATE:
1068 request = (MainThreadRequest) msg.obj;
1069 request.phone.requestCellInfoUpdate(request.workSource,
1070 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1071 break;
1072 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1076 try {
1077 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001079 cb.onError(
1080 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1081 ar.exception.getClass().getName(),
1082 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001085 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001086 } else {
1087 // use the result as returned
1088 cb.onCellInfo((List<CellInfo>) ar.result);
1089 }
1090 } catch (RemoteException re) {
1091 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1092 }
1093 break;
1094 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001095 request = (MainThreadRequest) msg.obj;
1096 WorkSource ws = (WorkSource) request.argument;
1097 Phone phone = getPhoneFromRequest(request);
1098 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1099 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001100 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null) {
1104 request.result = ar.result;
1105 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1108 ? new CdmaCellLocation() : new GsmCellLocation();
1109 }
1110
1111 synchronized (request) {
1112 request.notifyAll();
1113 }
1114 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001115 case CMD_MODEM_REBOOT:
1116 request = (MainThreadRequest) msg.obj;
1117 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001118 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001119 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001120 case EVENT_CMD_MODEM_REBOOT_DONE:
1121 handleNullReturnEvent(msg, "rebootModem");
1122 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001123 case CMD_REQUEST_ENABLE_MODEM:
1124 request = (MainThreadRequest) msg.obj;
1125 boolean enable = (boolean) request.argument;
1126 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001127 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001128 PhoneConfigurationManager.getInstance()
1129 .enablePhone(request.phone, enable, onCompleted);
1130 break;
1131 case EVENT_ENABLE_MODEM_DONE:
1132 ar = (AsyncResult) msg.obj;
1133 request = (MainThreadRequest) ar.userObj;
1134 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001135 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001136 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001137 if ((boolean) request.result) {
1138 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1139 updateModemStateMetrics();
1140 } else {
1141 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1142 + ar.exception);
1143 }
1144 notifyRequester(request);
1145 break;
1146 case CMD_GET_MODEM_STATUS:
1147 request = (MainThreadRequest) msg.obj;
1148 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1149 PhoneConfigurationManager.getInstance()
1150 .getPhoneStatusFromModem(request.phone, onCompleted);
1151 break;
1152 case EVENT_GET_MODEM_STATUS_DONE:
1153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
1155 int id = request.phone.getPhoneId();
1156 if (ar.exception == null && ar.result != null) {
1157 request.result = ar.result;
1158 //update the cache as modem status has changed
1159 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1160 (boolean) request.result);
1161 } else {
1162 // Return true if modem status cannot be retrieved. For most cases,
1163 // modem status is on. And for older version modems, GET_MODEM_STATUS
1164 // and disable modem are not supported. Modem is always on.
1165 // TODO: this should be fixed in R to support a third
1166 // status UNKNOWN b/131631629
1167 request.result = true;
1168 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1169 + ar.exception);
1170 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001171 notifyRequester(request);
1172 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001173 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1174 ar = (AsyncResult) msg.obj;
1175 request = (MainThreadRequest) ar.userObj;
1176 if (ar.exception == null && ar.result != null) {
1177 request.result = ar.result;
1178 } else {
1179 request.result = -1;
1180 loge("Failed to set Forbidden Plmns");
1181 if (ar.result == null) {
1182 loge("setForbidenPlmns: Empty response");
1183 } else if (ar.exception != null) {
1184 loge("setForbiddenPlmns: Exception: " + ar.exception);
1185 request.result = -1;
1186 } else {
1187 loge("setForbiddenPlmns: Unknown exception");
1188 }
1189 }
1190 notifyRequester(request);
1191 break;
1192 case CMD_SET_FORBIDDEN_PLMNS:
1193 request = (MainThreadRequest) msg.obj;
1194 uiccCard = getUiccCardFromRequest(request);
1195 if (uiccCard == null) {
1196 loge("setForbiddenPlmns: UiccCard is null");
1197 request.result = -1;
1198 notifyRequester(request);
1199 break;
1200 }
1201 Pair<Integer, List<String>> setFplmnsArgs =
1202 (Pair<Integer, List<String>>) request.argument;
1203 appType = setFplmnsArgs.first;
1204 List<String> fplmns = setFplmnsArgs.second;
1205 uiccApp = uiccCard.getApplicationByType(appType);
1206 if (uiccApp == null) {
1207 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1208 request.result = -1;
1209 loge("Failed to get UICC App");
1210 notifyRequester(request);
1211 } else {
1212 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1213 ((SIMRecords) uiccApp.getIccRecords())
1214 .setForbiddenPlmns(onCompleted, fplmns);
1215 }
1216 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 default:
1218 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1219 break;
1220 }
1221 }
Jake Hambye994d462014-02-03 13:10:13 -08001222
Pengquan Menga1bb6272018-09-06 09:59:22 -07001223 private void notifyRequester(MainThreadRequest request) {
1224 synchronized (request) {
1225 request.notifyAll();
1226 }
1227 }
1228
Jake Hambye994d462014-02-03 13:10:13 -08001229 private void handleNullReturnEvent(Message msg, String command) {
1230 AsyncResult ar = (AsyncResult) msg.obj;
1231 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1232 if (ar.exception == null) {
1233 request.result = true;
1234 } else {
1235 request.result = false;
1236 if (ar.exception instanceof CommandException) {
1237 loge(command + ": CommandException: " + ar.exception);
1238 } else {
1239 loge(command + ": Unknown exception");
1240 }
1241 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001242 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 }
1245
1246 /**
1247 * Posts the specified command to be executed on the main thread,
1248 * waits for the request to complete, and returns the result.
1249 * @see #sendRequestAsync
1250 */
1251 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001252 return sendRequest(
1253 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001254 }
1255
1256 /**
1257 * Posts the specified command to be executed on the main thread,
1258 * waits for the request to complete, and returns the result.
1259 * @see #sendRequestAsync
1260 */
1261 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1262 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001263 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001264 }
1265
1266 /**
1267 * Posts the specified command to be executed on the main thread,
1268 * waits for the request to complete, and returns the result.
1269 * @see #sendRequestAsync
1270 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001271 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001272 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001273 }
1274
1275 /**
1276 * Posts the specified command to be executed on the main thread,
1277 * waits for the request to complete, and returns the result.
1278 * @see #sendRequestAsync
1279 */
Nathan Harold92bed182018-10-12 18:16:49 -07001280 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1281 return sendRequest(command, argument, subId, null, workSource);
1282 }
1283
1284 /**
1285 * Posts the specified command to be executed on the main thread,
1286 * waits for the request to complete, and returns the result.
1287 * @see #sendRequestAsync
1288 */
1289 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1290 return sendRequest(
1291 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1292 }
1293
1294 /**
1295 * Posts the specified command to be executed on the main thread,
1296 * waits for the request to complete, and returns the result.
1297 * @see #sendRequestAsync
1298 */
1299 private Object sendRequest(
1300 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1302 throw new RuntimeException("This method will deadlock if called from the main thread.");
1303 }
1304
Nathan Harold92bed182018-10-12 18:16:49 -07001305 MainThreadRequest request = null;
1306 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1307 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1308 } else if (phone != null) {
1309 request = new MainThreadRequest(argument, phone, workSource);
1310 } else {
1311 request = new MainThreadRequest(argument, subId, workSource);
1312 }
1313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 Message msg = mMainThreadHandler.obtainMessage(command, request);
1315 msg.sendToTarget();
1316
1317 // Wait for the request to complete
1318 synchronized (request) {
1319 while (request.result == null) {
1320 try {
1321 request.wait();
1322 } catch (InterruptedException e) {
1323 // Do nothing, go back and wait until the request is complete
1324 }
1325 }
1326 }
1327 return request.result;
1328 }
1329
1330 /**
1331 * Asynchronous ("fire and forget") version of sendRequest():
1332 * Posts the specified command to be executed on the main thread, and
1333 * returns immediately.
1334 * @see #sendRequest
1335 */
1336 private void sendRequestAsync(int command) {
1337 mMainThreadHandler.sendEmptyMessage(command);
1338 }
1339
1340 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001341 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001342 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001343 */
1344 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001345 sendRequestAsync(command, argument, null, null);
1346 }
1347
1348 /**
1349 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1350 * @see {@link #sendRequest(int,Object)}
1351 */
1352 private void sendRequestAsync(
1353 int command, Object argument, Phone phone, WorkSource workSource) {
1354 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001355 Message msg = mMainThreadHandler.obtainMessage(command, request);
1356 msg.sendToTarget();
1357 }
1358
1359 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 * Initialize the singleton PhoneInterfaceManager instance.
1361 * This is only done once, at startup, from PhoneApp.onCreate().
1362 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001363 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 synchronized (PhoneInterfaceManager.class) {
1365 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001366 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 } else {
1368 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1369 }
1370 return sInstance;
1371 }
1372 }
1373
1374 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001375 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001378 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1380 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001381 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001382 mTelephonySharedPreferences =
1383 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001384 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001385 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 publish();
1388 }
1389
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001390 private Phone getDefaultPhone() {
1391 Phone thePhone = getPhone(getDefaultSubscription());
1392 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1393 }
1394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 private void publish() {
1396 if (DBG) log("publish: " + this);
1397
1398 ServiceManager.addService("phone", this);
1399 }
1400
Stuart Scott584921c2015-01-15 17:10:34 -08001401 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001402 if (request.phone != null) {
1403 return request.phone;
1404 } else {
1405 return getPhoneFromSubId(request.subId);
1406 }
1407 }
1408
1409 private Phone getPhoneFromSubId(int subId) {
1410 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1411 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001412 }
1413
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001414 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1415 Phone phone = getPhoneFromRequest(request);
1416 return phone == null ? null :
1417 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1418 }
1419
Wink Saville36469e72014-06-11 15:17:00 -07001420 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001421 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001422 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424
1425 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001427 }
1428
Wink Savilleb564aae2014-10-23 10:18:09 -07001429 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 if (DBG) log("dial: " + number);
1431 // No permission check needed here: This is just a wrapper around the
1432 // ACTION_DIAL intent, which is available to any app since it puts up
1433 // the UI before it does anything.
1434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001435 final long identity = Binder.clearCallingIdentity();
1436 try {
1437 String url = createTelUrl(number);
1438 if (url == null) {
1439 return;
1440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001442 // PENDING: should we just silently fail if phone is offhook or ringing?
1443 PhoneConstants.State state = mCM.getState(subId);
1444 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1445 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1446 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1447 mApp.startActivity(intent);
1448 }
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 }
1452 }
1453
1454 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 if (DBG) log("call: " + number);
1460
1461 // This is just a wrapper around the ACTION_CALL intent, but we still
1462 // need to do a permission check since we're calling startActivity()
1463 // from the context of the phone app.
1464 enforceCallPermission();
1465
Jordan Liu1617b712019-07-10 15:06:26 -07001466 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001467 != AppOpsManager.MODE_ALLOWED) {
1468 return;
1469 }
1470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001471 final long identity = Binder.clearCallingIdentity();
1472 try {
1473 String url = createTelUrl(number);
1474 if (url == null) {
1475 return;
1476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001478 boolean isValid = false;
1479 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1480 if (slist != null) {
1481 for (SubscriptionInfo subInfoRecord : slist) {
1482 if (subInfoRecord.getSubscriptionId() == subId) {
1483 isValid = true;
1484 break;
1485 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001486 }
Wink Saville08874612014-08-31 19:19:58 -07001487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001488 if (!isValid) {
1489 return;
1490 }
Wink Saville08874612014-08-31 19:19:58 -07001491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001492 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1493 intent.putExtra(SUBSCRIPTION_KEY, subId);
1494 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1495 mApp.startActivity(intent);
1496 } finally {
1497 Binder.restoreCallingIdentity(identity);
1498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 }
1500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001502 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001503 }
1504
Wink Savilleb564aae2014-10-23 10:18:09 -07001505 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001506 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001507 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1508 }
1509
1510 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001511 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001512 }
1513
Wink Savilleb564aae2014-10-23 10:18:09 -07001514 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001516 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1517 }
1518
1519 /** {@hide} */
1520 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001521 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001522 }
1523
Wink Savilleb564aae2014-10-23 10:18:09 -07001524 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001526
1527 final long identity = Binder.clearCallingIdentity();
1528 try {
1529 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1530 checkSimPin.start();
1531 return checkSimPin.unlockSim(null, pin);
1532 } finally {
1533 Binder.restoreCallingIdentity(identity);
1534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536
Wink Saville9de0f752013-10-22 19:04:03 -07001537 /** {@hide} */
1538 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001544
1545 final long identity = Binder.clearCallingIdentity();
1546 try {
1547 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1548 checkSimPuk.start();
1549 return checkSimPuk.unlockSim(puk, pin);
1550 } finally {
1551 Binder.restoreCallingIdentity(identity);
1552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 }
1554
1555 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001556 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 * a synchronous one.
1558 */
1559 private static class UnlockSim extends Thread {
1560
1561 private final IccCard mSimCard;
1562
1563 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001564 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1565 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566
1567 // For replies from SimCard interface
1568 private Handler mHandler;
1569
1570 // For async handler to identify request type
1571 private static final int SUPPLY_PIN_COMPLETE = 100;
1572
1573 public UnlockSim(IccCard simCard) {
1574 mSimCard = simCard;
1575 }
1576
1577 @Override
1578 public void run() {
1579 Looper.prepare();
1580 synchronized (UnlockSim.this) {
1581 mHandler = new Handler() {
1582 @Override
1583 public void handleMessage(Message msg) {
1584 AsyncResult ar = (AsyncResult) msg.obj;
1585 switch (msg.what) {
1586 case SUPPLY_PIN_COMPLETE:
1587 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1588 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001589 mRetryCount = msg.arg1;
1590 if (ar.exception != null) {
1591 if (ar.exception instanceof CommandException &&
1592 ((CommandException)(ar.exception)).getCommandError()
1593 == CommandException.Error.PASSWORD_INCORRECT) {
1594 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1595 } else {
1596 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1597 }
1598 } else {
1599 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 mDone = true;
1602 UnlockSim.this.notifyAll();
1603 }
1604 break;
1605 }
1606 }
1607 };
1608 UnlockSim.this.notifyAll();
1609 }
1610 Looper.loop();
1611 }
1612
1613 /*
1614 * Use PIN or PUK to unlock SIM card
1615 *
1616 * If PUK is null, unlock SIM card with PIN
1617 *
1618 * If PUK is not null, unlock SIM card with PUK and set PIN code
1619 */
Wink Saville9de0f752013-10-22 19:04:03 -07001620 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621
1622 while (mHandler == null) {
1623 try {
1624 wait();
1625 } catch (InterruptedException e) {
1626 Thread.currentThread().interrupt();
1627 }
1628 }
1629 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1630
1631 if (puk == null) {
1632 mSimCard.supplyPin(pin, callback);
1633 } else {
1634 mSimCard.supplyPuk(puk, pin, callback);
1635 }
1636
1637 while (!mDone) {
1638 try {
1639 Log.d(LOG_TAG, "wait for done");
1640 wait();
1641 } catch (InterruptedException e) {
1642 // Restore the interrupted status
1643 Thread.currentThread().interrupt();
1644 }
1645 }
1646 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001647 int[] resultArray = new int[2];
1648 resultArray[0] = mResult;
1649 resultArray[1] = mRetryCount;
1650 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652 }
1653
1654 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001655 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001656
1657 }
1658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 // No permission check needed here: this call is harmless, and it's
1661 // needed for the ServiceState.requestStateUpdate() call (which is
1662 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.updateServiceLocation();
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 }
1673
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001674 @Override
1675 public boolean isRadioOn(String callingPackage) {
1676 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001677 }
1678
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001679 @Override
1680 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001682 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001683 return false;
1684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001685
1686 final long identity = Binder.clearCallingIdentity();
1687 try {
1688 return isRadioOnForSubscriber(subId);
1689 } finally {
1690 Binder.restoreCallingIdentity(identity);
1691 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001692 }
1693
1694 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001695 final long identity = Binder.clearCallingIdentity();
1696 try {
1697 final Phone phone = getPhone(subId);
1698 if (phone != null) {
1699 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1700 } else {
1701 return false;
1702 }
1703 } finally {
1704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 }
1707
1708 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001709 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 }
Wink Saville36469e72014-06-11 15:17:00 -07001711
Wink Savilleb564aae2014-10-23 10:18:09 -07001712 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 final Phone phone = getPhone(subId);
1718 if (phone != null) {
1719 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Wink Saville36469e72014-06-11 15:17:00 -07001724 }
1725
1726 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001727 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001728 }
1729
Wink Savilleb564aae2014-10-23 10:18:09 -07001730 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 final Phone phone = getPhone(subId);
1736 if (phone == null) {
1737 return false;
1738 }
1739 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1740 toggleRadioOnOffForSubscriber(subId);
1741 }
1742 return true;
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
Wink Saville36469e72014-06-11 15:17:00 -07001747
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001748 public boolean needMobileRadioShutdown() {
1749 /*
1750 * If any of the Radios are available, it will need to be
1751 * shutdown. So return true if any Radio is available.
1752 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1756 Phone phone = PhoneFactory.getPhone(i);
1757 if (phone != null && phone.isRadioAvailable()) return true;
1758 }
1759 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1760 return false;
1761 } finally {
1762 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001763 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 }
1765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001767 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 enforceModifyPermission();
1769
1770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1773 logv("Shutting down Phone " + i);
1774 shutdownRadioUsingPhoneId(i);
1775 }
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 }
1779 }
1780
1781 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001782 Phone phone = PhoneFactory.getPhone(phoneId);
1783 if (phone != null && phone.isRadioAvailable()) {
1784 phone.shutdownRadio();
1785 }
1786 }
1787
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001789 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001790
1791 final long identity = Binder.clearCallingIdentity();
1792 try {
1793 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1794 if (defaultPhone != null) {
1795 defaultPhone.setRadioPower(turnOn);
1796 return true;
1797 } else {
1798 loge("There's no default phone.");
1799 return false;
1800 }
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001803 }
Wink Saville36469e72014-06-11 15:17:00 -07001804 }
1805
Wink Savilleb564aae2014-10-23 10:18:09 -07001806 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001808
1809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 final Phone phone = getPhone(subId);
1812 if (phone != null) {
1813 phone.setRadioPower(turnOn);
1814 return true;
1815 } else {
1816 return false;
1817 }
1818 } finally {
1819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 }
1822
Wink Saville36469e72014-06-11 15:17:00 -07001823 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 public boolean enableDataConnectivity() {
1826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827
1828 final long identity = Binder.clearCallingIdentity();
1829 try {
1830 int subId = mSubscriptionController.getDefaultDataSubId();
1831 final Phone phone = getPhone(subId);
1832 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001833 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834 return true;
1835 } else {
1836 return false;
1837 }
1838 } finally {
1839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 }
1842
Wink Saville36469e72014-06-11 15:17:00 -07001843 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001844 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 public boolean disableDataConnectivity() {
1846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 int subId = mSubscriptionController.getDefaultDataSubId();
1851 final Phone phone = getPhone(subId);
1852 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001853 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001854 return true;
1855 } else {
1856 return false;
1857 }
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001864 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 final long identity = Binder.clearCallingIdentity();
1866 try {
1867 final Phone phone = getPhone(subId);
1868 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001869 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001870 } else {
1871 return false;
1872 }
1873 } finally {
1874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
1878 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001879 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001880 }
1881
pkanwarae03a6b2016-11-06 20:37:09 -08001882 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883 enforceCallPermission();
1884
1885 final long identity = Binder.clearCallingIdentity();
1886 try {
1887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1888 return;
1889 }
1890 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1891 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
1894 }
pkanwar32d516d2016-10-14 19:37:38 -07001895 };
1896
Wink Savilleb564aae2014-10-23 10:18:09 -07001897 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899
1900 final long identity = Binder.clearCallingIdentity();
1901 try {
1902 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1903 return false;
1904 }
1905 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1906 } finally {
1907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001912 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001915 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916 final long identity = Binder.clearCallingIdentity();
1917 try {
1918 Phone phone = PhoneFactory.getPhone(slotIndex);
1919 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1920 PhoneConstantConversions.convertCallState(phone.getState());
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
1923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 }
1925
Sanket Padawe356d7632015-06-22 14:03:32 -07001926 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001927 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001928 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1929 }
1930
1931 @Override
1932 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933 final long identity = Binder.clearCallingIdentity();
1934 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001935 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001936 if (phone != null) {
1937 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1938 } else {
1939 return PhoneConstantConversions.convertDataState(
1940 PhoneConstants.DataState.DISCONNECTED);
1941 }
1942 } finally {
1943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001948 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001949 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1950 }
1951
1952 @Override
1953 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 final long identity = Binder.clearCallingIdentity();
1955 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001956 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001957 if (phone != null) {
1958 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1959 } else {
1960 return TelephonyManager.DATA_ACTIVITY_NONE;
1961 }
1962 } finally {
1963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 }
1966
1967 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001968 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001969 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001970 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001971
1972 LocationAccessPolicy.LocationPermissionResult locationResult =
1973 LocationAccessPolicy.checkLocationPermission(mApp,
1974 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1975 .setCallingPackage(callingPackage)
1976 .setCallingPid(Binder.getCallingPid())
1977 .setCallingUid(Binder.getCallingUid())
1978 .setMethod("getCellLocation")
1979 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1980 .build());
1981 switch (locationResult) {
1982 case DENIED_HARD:
1983 throw new SecurityException("Not allowed to access cell location");
1984 case DENIED_SOFT:
1985 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 }
1987
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001988 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 final long identity = Binder.clearCallingIdentity();
1990 try {
1991 if (DBG_LOC) log("getCellLocation: is active user");
1992 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001993 int subId = mSubscriptionController.getDefaultDataSubId();
1994 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1995 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 return data;
1997 } finally {
1998 Binder.restoreCallingIdentity(identity);
1999 }
Svetoslav64fad262015-04-14 14:35:21 -07002000 }
2001
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 @Override
Jack Yu1e81ccd2019-09-26 11:48:33 -07002003 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2004 if (!TextUtils.isEmpty(callingPackage)) {
2005 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2007 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2008 return "";
2009 }
2010 }
2011
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002012 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2013 // registered cell info, so return a NULL country instead.
2014 final long identity = Binder.clearCallingIdentity();
2015 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002016 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2017 // Get default phone in this case.
2018 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2019 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002020 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002021 // Todo: fix this when we can get the actual cellular network info when the device
2022 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002023 if (TelephonyManager.NETWORK_TYPE_IWLAN
2024 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2025 return "";
2026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002027 Phone phone = PhoneFactory.getPhone(phoneId);
2028 if (phone != null) {
2029 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002030 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002031 if (sst != null) {
2032 LocaleTracker lt = sst.getLocaleTracker();
2033 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002034 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2035 return lt.getCurrentCountry();
2036 } else if (emergencyNumberTracker != null) {
2037 return emergencyNumberTracker.getEmergencyCountryIso();
2038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 }
2040 }
2041 }
2042 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002043 } finally {
2044 Binder.restoreCallingIdentity(identity);
2045 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002046 }
2047
2048 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002050 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002051 }
2052
Sanket Padawe356d7632015-06-22 14:03:32 -07002053 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002054 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 mApp.enforceCallingOrSelfPermission(
2056 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057
2058 final long identity = Binder.clearCallingIdentity();
2059 try {
2060 final Phone phone = getPhone(subId);
2061 if (phone != null) {
2062 phone.enableLocationUpdates();
2063 }
2064 } finally {
2065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 }
2068
2069 @Override
2070 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002071 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002072 }
2073
Sanket Padawe356d7632015-06-22 14:03:32 -07002074 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002075 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 mApp.enforceCallingOrSelfPermission(
2077 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078
2079 final long identity = Binder.clearCallingIdentity();
2080 try {
2081 final Phone phone = getPhone(subId);
2082 if (phone != null) {
2083 phone.disableLocationUpdates();
2084 }
2085 } finally {
2086 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 }
2089
Nathan Harold31d7ff32018-10-15 20:20:30 -07002090 /**
2091 * Returns the target SDK version number for a given package name.
2092 *
Nathan Haroldec184742019-07-10 17:04:16 -07002093 * This call MUST be invoked before clearing the calling UID.
2094 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002095 * @return target SDK if the package is found or INT_MAX.
2096 */
2097 private int getTargetSdk(String packageName) {
2098 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002099 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002100 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002101 if (ai != null) return ai.targetSdkVersion;
2102 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002103 loge("Failed to get package info for pkg="
2104 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002105 }
2106 return Integer.MAX_VALUE;
2107 }
2108
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 @Override
2110 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002111 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2112 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002113 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2114 throw new SecurityException(
2115 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2116 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002117
Jordan Liu1617b712019-07-10 15:06:26 -07002118 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2120 return null;
2121 }
Svetoslav64fad262015-04-14 14:35:21 -07002122
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002123 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124
Nathan Haroldf180aac2018-06-01 18:43:55 -07002125 List<CellInfo> info = getAllCellInfo(callingPackage);
2126 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127
Nathan Haroldf180aac2018-06-01 18:43:55 -07002128 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2129 for (CellInfo ci : info) {
2130 if (ci instanceof CellInfoGsm) {
2131 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2132 } else if (ci instanceof CellInfoWcdma) {
2133 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002136 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 }
2138
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002139 private List<CellInfo> getCachedCellInfo() {
2140 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2141 for (Phone phone : PhoneFactory.getPhones()) {
2142 List<CellInfo> info = phone.getAllCellInfo();
2143 if (info != null) cellInfos.addAll(info);
2144 }
2145 return cellInfos;
2146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147
2148 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002149 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002150 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002151 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002152
2153 LocationAccessPolicy.LocationPermissionResult locationResult =
2154 LocationAccessPolicy.checkLocationPermission(mApp,
2155 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2156 .setCallingPackage(callingPackage)
2157 .setCallingPid(Binder.getCallingPid())
2158 .setCallingUid(Binder.getCallingUid())
2159 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002160 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002161 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2162 .build());
2163 switch (locationResult) {
2164 case DENIED_HARD:
2165 throw new SecurityException("Not allowed to access cell info");
2166 case DENIED_SOFT:
2167 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 final int targetSdk = getTargetSdk(callingPackage);
2171 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2172 return getCachedCellInfo();
2173 }
2174
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002175 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002177 final long identity = Binder.clearCallingIdentity();
2178 try {
2179 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2180 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002181 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002182 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183 if (info != null) cellInfos.addAll(info);
2184 }
2185 return cellInfos;
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
2189 }
2190
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002191 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002192 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2193 requestCellInfoUpdateInternal(
2194 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2195 }
2196
2197 @Override
2198 public void requestCellInfoUpdateWithWorkSource(
2199 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2200 enforceModifyPermission();
2201 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2202 }
2203
2204 private void requestCellInfoUpdateInternal(
2205 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002206 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002207 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002208
2209 LocationAccessPolicy.LocationPermissionResult locationResult =
2210 LocationAccessPolicy.checkLocationPermission(mApp,
2211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2212 .setCallingPackage(callingPackage)
2213 .setCallingPid(Binder.getCallingPid())
2214 .setCallingUid(Binder.getCallingUid())
2215 .setMethod("requestCellInfoUpdate")
2216 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2217 .build());
2218 switch (locationResult) {
2219 case DENIED_HARD:
2220 throw new SecurityException("Not allowed to access cell info");
2221 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002222 try {
2223 cb.onCellInfo(new ArrayList<CellInfo>());
2224 } catch (RemoteException re) {
2225 // Drop without consequences
2226 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002227 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002228 }
2229
Nathan Harolda939a962019-05-09 10:13:47 -07002230
2231 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002232 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2233
2234 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2235 }
2236
2237 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002239 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002240 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241
2242 final long identity = Binder.clearCallingIdentity();
2243 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002244 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 } finally {
2246 Binder.restoreCallingIdentity(identity);
2247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 }
2249
Shishir Agrawala9f32182016-04-12 12:00:16 -07002250 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002251 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002252 Phone phone = PhoneFactory.getPhone(slotIndex);
2253 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002254 return null;
2255 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002256 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002257 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2258 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002259 return null;
2260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261
2262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 return phone.getImei();
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
2267 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002268 }
2269
2270 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002271 public String getTypeAllocationCodeForSlot(int slotIndex) {
2272 Phone phone = PhoneFactory.getPhone(slotIndex);
2273 String tac = null;
2274 if (phone != null) {
2275 String imei = phone.getImei();
2276 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2277 }
2278 return tac;
2279 }
2280
2281 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002282 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002283 Phone phone = PhoneFactory.getPhone(slotIndex);
2284 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002285 return null;
2286 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002287
Jeff Davidson913390f2018-02-23 17:11:49 -08002288 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002289 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2290 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002291 return null;
2292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 return phone.getMeid();
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
Jack Yu2af8d712017-03-15 17:14:14 -07002300 }
2301
2302 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002303 public String getManufacturerCodeForSlot(int slotIndex) {
2304 Phone phone = PhoneFactory.getPhone(slotIndex);
2305 String manufacturerCode = null;
2306 if (phone != null) {
2307 String meid = phone.getMeid();
2308 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2309 }
2310 return manufacturerCode;
2311 }
2312
2313 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002314 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002315 Phone phone = PhoneFactory.getPhone(slotIndex);
2316 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002317 return null;
2318 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002319 int subId = phone.getSubId();
2320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2321 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2322 return null;
2323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 return phone.getDeviceSvn();
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
2330 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002331 }
2332
fionaxu43304da2017-11-27 22:51:16 -08002333 @Override
2334 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335 final long identity = Binder.clearCallingIdentity();
2336 try {
2337 final Phone phone = getPhone(subId);
2338 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2339 } finally {
2340 Binder.restoreCallingIdentity(identity);
2341 }
fionaxu43304da2017-11-27 22:51:16 -08002342 }
2343
2344 @Override
2345 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 final Phone phone = getPhone(subId);
2349 return phone == null ? null : phone.getCarrierName();
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
2352 }
fionaxu43304da2017-11-27 22:51:16 -08002353 }
2354
calvinpanffe225e2018-11-01 19:43:06 +08002355 @Override
chen xu0026ca62019-03-06 15:28:50 -08002356 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002361 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002362 } finally {
2363 Binder.restoreCallingIdentity(identity);
2364 }
2365 }
2366
2367 @Override
chen xu0026ca62019-03-06 15:28:50 -08002368 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002372 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002373 } finally {
2374 Binder.restoreCallingIdentity(identity);
2375 }
2376 }
2377
chen xu651eec72018-11-11 19:03:44 -08002378 @Override
chen xu864e11c2018-12-06 22:10:03 -08002379 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2380 if (!isSubscriptionMccMnc) {
2381 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2382 }
chen xu651eec72018-11-11 19:03:44 -08002383 final Phone phone = PhoneFactory.getPhone(slotIndex);
2384 if (phone == null) {
2385 return TelephonyManager.UNKNOWN_CARRIER_ID;
2386 }
2387 final long identity = Binder.clearCallingIdentity();
2388 try {
2389 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
2393 }
2394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 //
2396 // Internal helper methods.
2397 //
2398
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002399 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2401 *
2402 * @throws SecurityException if the caller does not have the required permission
2403 */
2404 private void enforceModifyPermission() {
2405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2406 }
2407
2408 /**
2409 * Make sure the caller has the CALL_PHONE permission.
2410 *
2411 * @throws SecurityException if the caller does not have the required permission
2412 */
2413 private void enforceCallPermission() {
2414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2415 }
2416
Stuart Scott8eef64f2015-04-08 15:13:54 -07002417 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002418 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002419 "ConnectivityService");
2420 }
2421
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 private String createTelUrl(String number) {
2423 if (TextUtils.isEmpty(number)) {
2424 return null;
2425 }
2426
Jake Hambye994d462014-02-03 13:10:13 -08002427 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
Ihab Awadf9e92732013-12-05 18:02:52 -08002430 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2432 }
2433
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002434 private static void logv(String msg) {
2435 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2436 }
2437
Ihab Awadf9e92732013-12-05 18:02:52 -08002438 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2440 }
2441
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002442 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002444 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002445 }
2446
Sanket Padawe356d7632015-06-22 14:03:32 -07002447 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002448 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 final Phone phone = PhoneFactory.getPhone(slotIndex);
2452 if (phone == null) {
2453 return PhoneConstants.PHONE_TYPE_NONE;
2454 } else {
2455 return phone.getPhoneType();
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461
2462 /**
2463 * Returns the CDMA ERI icon index to display
2464 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 @Override
2466 public int getCdmaEriIconIndex(String callingPackage) {
2467 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002468 }
2469
Sanket Padawe356d7632015-06-22 14:03:32 -07002470 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002473 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002474 return -1;
2475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 final Phone phone = getPhone(subId);
2480 if (phone != null) {
2481 return phone.getCdmaEriIconIndex();
2482 } else {
2483 return -1;
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
2490 /**
2491 * Returns the CDMA ERI icon mode,
2492 * 0 - ON
2493 * 1 - FLASHING
2494 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002495 @Override
2496 public int getCdmaEriIconMode(String callingPackage) {
2497 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002498 }
2499
Sanket Padawe356d7632015-06-22 14:03:32 -07002500 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002501 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002503 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002504 return -1;
2505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506
2507 final long identity = Binder.clearCallingIdentity();
2508 try {
2509 final Phone phone = getPhone(subId);
2510 if (phone != null) {
2511 return phone.getCdmaEriIconMode();
2512 } else {
2513 return -1;
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
2519
2520 /**
2521 * Returns the CDMA ERI text,
2522 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002523 @Override
2524 public String getCdmaEriText(String callingPackage) {
2525 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002526 }
2527
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002529 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002531 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002532 return null;
2533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534
2535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 final Phone phone = getPhone(subId);
2538 if (phone != null) {
2539 return phone.getCdmaEriText();
2540 } else {
2541 return null;
2542 }
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 }
2547
2548 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002549 * Returns the CDMA MDN.
2550 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002551 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002552 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2554 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002559 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 return phone.getLine1Number();
2561 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002562 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 return null;
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002567 }
2568 }
2569
2570 /**
2571 * Returns the CDMA MIN.
2572 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002574 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2576 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 final Phone phone = getPhone(subId);
2581 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2582 return phone.getCdmaMin();
2583 } else {
2584 return null;
2585 }
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002588 }
2589 }
2590
Hall Liud892bec2018-11-30 14:51:45 -08002591 @Override
2592 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2593 INumberVerificationCallback callback, String callingPackage) {
2594 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2595 != PERMISSION_GRANTED) {
2596 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2597 }
2598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2599
2600 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2601 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2602 throw new SecurityException("Calling package must be configured in the device config");
2603 }
2604
2605 if (range == null) {
2606 throw new NullPointerException("Range must be non-null");
2607 }
2608
2609 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002610 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002611
2612 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2613 }
2614
Junda Liuca05d5d2014-08-14 22:36:34 -07002615 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 * Returns true if CDMA provisioning needs to run.
2617 */
2618 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002621 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 } finally {
2623 Binder.restoreCallingIdentity(identity);
2624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
2627 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002628 * Sets the voice mail number of a given subId.
2629 */
2630 @Override
2631 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002632 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2637 new Pair<String, String>(alphaTag, number), new Integer(subId));
2638 return success;
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
2641 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002642 }
2643
Ta-wei Yen87c49842016-05-13 21:19:52 -07002644 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002645 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002647 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002648 if (!TextUtils.equals(callingPackage, systemDialer)) {
2649 throw new SecurityException("caller must be system dialer");
2650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2655 if (phoneAccountHandle == null) {
2656 return null;
2657 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002658 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 } finally {
2660 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002661 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002662 }
2663
2664 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002665 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002668 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002669 return null;
2670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002672 final long identity = Binder.clearCallingIdentity();
2673 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002674 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002675 } finally {
2676 Binder.restoreCallingIdentity(identity);
2677 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002678 }
2679
2680 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002681 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2682 VisualVoicemailSmsFilterSettings settings) {
2683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002688 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002692 }
2693
2694 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002695 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002701 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 } finally {
2703 Binder.restoreCallingIdentity(identity);
2704 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002705 }
2706
2707 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002708 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2709 String callingPackage, int subId) {
2710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711
2712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002715 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 } finally {
2717 Binder.restoreCallingIdentity(identity);
2718 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002719 }
2720
2721 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002722 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002723 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724
2725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002728 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 } finally {
2730 Binder.restoreCallingIdentity(identity);
2731 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002732 }
2733
2734 @Override
2735 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2736 String number, int port, String text, PendingIntent sentIntent) {
2737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002738 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002739 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002740 SmsController smsController = PhoneFactory.getSmsController();
2741 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2742 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002743 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002744
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002745 /**
fionaxu0152e512016-11-14 13:36:14 -08002746 * Sets the voice activation state of a given subId.
2747 */
2748 @Override
2749 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2751 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752
2753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 final Phone phone = getPhone(subId);
2756 if (phone != null) {
2757 phone.setVoiceActivationState(activationState);
2758 } else {
2759 loge("setVoiceActivationState fails with invalid subId: " + subId);
2760 }
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002763 }
2764 }
2765
2766 /**
2767 * Sets the data activation state of a given subId.
2768 */
2769 @Override
2770 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2772 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773
2774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 final Phone phone = getPhone(subId);
2777 if (phone != null) {
2778 phone.setDataActivationState(activationState);
2779 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002780 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 }
2782 } finally {
2783 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002784 }
2785 }
2786
2787 /**
2788 * Returns the voice activation state of a given subId.
2789 */
2790 @Override
2791 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002792 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793
fionaxu0152e512016-11-14 13:36:14 -08002794 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 if (phone != null) {
2798 return phone.getVoiceActivationState();
2799 } else {
2800 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2801 }
2802 } finally {
2803 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002804 }
2805 }
2806
2807 /**
2808 * Returns the data activation state of a given subId.
2809 */
2810 @Override
2811 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002812 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813
fionaxu0152e512016-11-14 13:36:14 -08002814 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 if (phone != null) {
2818 return phone.getDataActivationState();
2819 } else {
2820 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2821 }
2822 } finally {
2823 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002824 }
2825 }
2826
2827 /**
Wink Saville36469e72014-06-11 15:17:00 -07002828 * Returns the unread count of voicemails for a subId
2829 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002831 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2833 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2834 return 0;
2835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = getPhone(subId);
2839 if (phone != null) {
2840 return phone.getVoiceMessageCount();
2841 } else {
2842 return 0;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002850 * returns true, if the device is in a state where both voice and data
2851 * are supported simultaneously. This can change based on location or network condition.
2852 */
2853 @Override
2854 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 final Phone phone = getPhone(subId);
2858 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
2861 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002862 }
2863
2864 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002865 * Send the dialer code if called from the current default dialer or the caller has
2866 * carrier privilege.
2867 * @param inputCode The dialer code to send
2868 */
2869 @Override
2870 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002871 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002872 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002873 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2874 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002875 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002876 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2877 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002882 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
fionaxu235cc5e2017-03-06 22:25:57 -08002886 }
2887
Pengquan Menga1bb6272018-09-06 09:59:22 -07002888 @Override
2889 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002890 if (!isActiveSubscription(subId)) {
2891 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2892 }
2893
Pengquan Menga1bb6272018-09-06 09:59:22 -07002894 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2895 }
2896
Brad Ebinger35c841c2018-10-01 10:40:55 -07002897 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002898 public boolean isInEmergencySmsMode() {
2899 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 for (Phone phone : PhoneFactory.getPhones()) {
2903 if (phone.isInEmergencySmsMode()) {
2904 return true;
2905 }
2906 }
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
2909 }
2910 return false;
2911 }
2912
2913 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002914 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2915 throws RemoteException {
2916 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002917 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2918 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2919 "IMS not available on device.");
2920 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002921 final long token = Binder.clearCallingIdentity();
2922 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002924 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002926 } catch (ImsException e) {
2927 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002928 } finally {
2929 Binder.restoreCallingIdentity(token);
2930 }
2931 }
2932
2933 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002934 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2935 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002936 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2937 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2938 }
Meng Wangafbc5852019-09-19 17:37:13 -07002939 final long token = Binder.clearCallingIdentity();
2940 try {
2941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2942 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2943 .removeRegistrationCallbackForSubscription(c, subId);
2944 } catch (ImsException e) {
2945 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2946 + "is inactive, ignoring unregister.");
2947 // If the subscription is no longer active, just return, since the callback
2948 // will already have been removed internally.
2949 } finally {
2950 Binder.restoreCallingIdentity(token);
2951 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 }
2953
2954 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002955 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2956 throws RemoteException {
2957 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002958 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2959 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2960 "IMS not available on device.");
2961 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2963 final long token = Binder.clearCallingIdentity();
2964 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002965 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002967 } catch (ImsException e) {
2968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 } finally {
2970 Binder.restoreCallingIdentity(token);
2971 }
2972 }
2973
2974 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002975 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2976 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002977 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2978 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2979 }
Meng Wangafbc5852019-09-19 17:37:13 -07002980
2981 final long token = Binder.clearCallingIdentity();
2982 try {
2983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2984 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002985 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07002986 } catch (ImsException e) {
2987 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2988 + "is inactive, ignoring unregister.");
2989 // If the subscription is no longer active, just return, since the callback
2990 // will already have been removed internally.
2991 } finally {
2992 Binder.restoreCallingIdentity(token);
2993 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 }
2995
2996 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002997 public boolean isCapable(int subId, int capability, int regTech) {
2998 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3000 final long token = Binder.clearCallingIdentity();
3001 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003002 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003003 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003004 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3006 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003007 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003008 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3009 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003010 } finally {
3011 Binder.restoreCallingIdentity(token);
3012 }
3013 }
3014
3015 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003016 public boolean isAvailable(int subId, int capability, int regTech) {
3017 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003018 final long token = Binder.clearCallingIdentity();
3019 try {
3020 Phone phone = getPhone(subId);
3021 if (phone == null) return false;
3022 return phone.isImsCapabilityAvailable(capability, regTech);
3023 } finally {
3024 Binder.restoreCallingIdentity(token);
3025 }
3026 }
3027
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003028 /**
3029 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3030 * subscription.
3031 * @param subId The subscription to use to check the configuration.
3032 * @param callback The callback that will be used to send the result.
3033 * @param capability The MmTelFeature capability that will be used to send the result.
3034 * @param transportType The transport type of the MmTelFeature capability.
3035 */
3036 @Override
3037 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3038 int transportType) {
3039 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3040 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3041 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3042 "IMS not available on device.");
3043 }
3044 final long token = Binder.clearCallingIdentity();
3045 try {
3046 int slotId = getSlotIndex(subId);
3047 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3048 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3049 + subId + "'");
3050 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3051 }
3052 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3053 transportType, aBoolean -> {
3054 try {
3055 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3056 } catch (RemoteException e) {
3057 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3058 + "running. Ignore");
3059 }
3060 });
3061 } finally {
3062 Binder.restoreCallingIdentity(token);
3063 }
3064 }
3065
Brad Ebinger35c841c2018-10-01 10:40:55 -07003066 @Override
3067 public boolean isAdvancedCallingSettingEnabled(int subId) {
3068 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3070 final long token = Binder.clearCallingIdentity();
3071 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003072 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003074 } catch (ImsException e) {
3075 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003076 } finally {
3077 Binder.restoreCallingIdentity(token);
3078 }
3079 }
3080
3081 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003082 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003084 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003090 } catch (ImsException e) {
3091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 }
3096
3097 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003098 public boolean isVtSettingEnabled(int subId) {
3099 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003103 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3104 } catch (ImsException e) {
3105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
3109 }
3110
3111 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003112 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003114 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003118 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003119 } catch (ImsException e) {
3120 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
3124 }
3125
3126 @Override
3127 public boolean isVoWiFiSettingEnabled(int subId) {
3128 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003132 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003134 } catch (ImsException e) {
3135 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
3139 }
3140
3141 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003142 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003144 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003148 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003149 } catch (ImsException e) {
3150 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
3154 }
3155
3156 @Override
3157 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3158 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003162 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003164 } catch (ImsException e) {
3165 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003166 } finally {
3167 Binder.restoreCallingIdentity(identity);
3168 }
3169 }
3170
3171 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003172 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003174 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003178 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003179 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003180 } catch (ImsException e) {
3181 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
3185 }
3186
3187 @Override
3188 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3190 "setVoWiFiNonPersistent");
3191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003194 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003195 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003196 } catch (ImsException e) {
3197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
3201 }
3202
3203 @Override
3204 public int getVoWiFiModeSetting(int subId) {
3205 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 } catch (ImsException e) {
3212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
3216 }
3217
3218 @Override
3219 public void setVoWiFiModeSetting(int subId, int mode) {
3220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3221 "setVoWiFiModeSetting");
3222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003225 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
3235 public int getVoWiFiRoamingModeSetting(int subId) {
3236 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003240 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 } catch (ImsException e) {
3243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
3249 @Override
3250 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3252 "setVoWiFiRoamingModeSetting");
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003256 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003258 } catch (ImsException e) {
3259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
3263 }
3264
3265 @Override
3266 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3268 "setRttCapabilityEnabled");
3269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003272 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3273 } catch (ImsException e) {
3274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
3278 }
3279
3280 @Override
3281 public boolean isTtyOverVolteEnabled(int subId) {
3282 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003288 } catch (ImsException e) {
3289 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
3293 }
3294
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003295 @Override
3296 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3297 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003301 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003302 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003303 } catch (ImsException e) {
3304 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
3311 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3312 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3313 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003314 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3315 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3316 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003317 try {
3318 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003319 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003320 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003321 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003322 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3323 + "is inactive, ignoring unregister.");
3324 // If the subscription is no longer active, just return, since the callback will already
3325 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003326 } finally {
3327 Binder.restoreCallingIdentity(identity);
3328 }
3329 }
3330
3331 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003332 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3333 boolean isProvisioned) {
3334 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3335 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3336 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3337 }
3338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3339 "setProvisioningStatusForCapability");
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3343 Phone phone = getPhone(subId);
3344 if (phone == null) {
3345 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3346 + subId);
3347 return;
3348 }
3349 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3350 return;
3351 }
3352
3353 // this capability requires provisioning, route to the correct API.
3354 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3355 switch (capability) {
3356 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3357 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3358 ims.setVolteProvisioned(isProvisioned);
3359 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3360 ims.setWfcProvisioned(isProvisioned);
3361 }
3362 break;
3363 }
3364 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3365 // There is currently no difference in VT provisioning type.
3366 ims.setVtProvisioned(isProvisioned);
3367 break;
3368 }
3369 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3370 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3371 // change the capability of the feature instead if needed.
3372 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3373 == isProvisioned) {
3374 // No change in provisioning.
3375 return;
3376 }
3377 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3378 try {
3379 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003380 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003381 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3382 + ", Exception" + e.getMessage());
3383 }
3384 break;
3385 }
3386 default: {
3387 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3388 + capability + "', which does not require provisioning.");
3389 }
3390 }
3391
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
3395 }
3396
3397 @Override
3398 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3399 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3400 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3401 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3402 }
3403 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3407 Phone phone = getPhone(subId);
3408 if (phone == null) {
3409 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3410 + subId);
3411 // We will fail with "true" as the provisioning status because this is the default
3412 // if we do not require provisioning.
3413 return true;
3414 }
3415
3416 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3417 return true;
3418 }
3419
3420 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3421 switch (capability) {
3422 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3423 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3424 return ims.isVolteProvisionedOnDevice();
3425 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3426 return ims.isWfcProvisionedOnDevice();
3427 }
3428 // This should never happen, since we are checking tech above to make sure it
3429 // is either LTE or IWLAN.
3430 throw new IllegalArgumentException("Invalid radio technology for voice "
3431 + "capability.");
3432 }
3433 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3434 // There is currently no difference in VT provisioning type.
3435 return ims.isVtProvisionedOnDevice();
3436 }
3437 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3438 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3439 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3440 }
3441 default: {
3442 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3443 + capability + "', which does not require provisioning.");
3444 }
3445 }
3446
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
3450 }
3451
3452 @Override
3453 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3454 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3455 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3456 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3457 }
3458 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3459 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3460 return (provisionedBits & capability) > 0;
3461 }
3462
3463 @Override
3464 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3465 boolean isProvisioned) {
3466 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3467 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3468 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3469 }
3470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3471 "setProvisioningStatusForCapability");
3472 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3473 // If the current provisioning status for capability already matches isProvisioned,
3474 // do nothing.
3475 if (((provisionedBits & capability) > 0) == isProvisioned) {
3476 return;
3477 }
3478 if (isProvisioned) {
3479 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3480 } else {
3481 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3482 }
3483 }
3484
3485 /**
3486 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3487 * technology. The bitfield should mirror the bitfield defined by
3488 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3489 */
3490 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3491 String key = getMmTelProvisioningKey(subId, tech);
3492 // Default is no capabilities are provisioned.
3493 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3494 }
3495
3496 /**
3497 * Sets the MmTel capability provisioning bitfield (defined by
3498 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3499 * technology specified.
3500 *
3501 * Note: This is a synchronous command and should not be called on UI thread.
3502 */
3503 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3504 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3505 String key = getMmTelProvisioningKey(subId, tech);
3506 editor.putInt(key, newField);
3507 editor.commit();
3508 }
3509
3510 private static String getMmTelProvisioningKey(int subId, int tech) {
3511 // resulting key is provision_ims_mmtel_{subId}_{tech}
3512 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3513 }
3514
3515 /**
3516 * Query CarrierConfig to see if the specified capability requires provisioning for the
3517 * carrier associated with the subscription id.
3518 */
3519 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3520 int capability) {
3521 CarrierConfigManager configManager = new CarrierConfigManager(context);
3522 PersistableBundle c = configManager.getConfigForSubId(subId);
3523 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003524 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003525 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3526 false);
3527 boolean requireVoiceVtProvisioning = c.getBoolean(
3528 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3529
3530 // First check to make sure that the capability requires provisioning.
3531 switch (capability) {
3532 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3533 // intentional fallthrough
3534 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3535 if (requireVoiceVtProvisioning) {
3536 // Voice and Video requires provisioning
3537 return true;
3538 }
3539 break;
3540 }
3541 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3542 if (requireUtProvisioning) {
3543 // UT requires provisioning
3544 return true;
3545 }
3546 break;
3547 }
3548 }
3549 return false;
3550 }
3551
3552 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003553 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003554 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3555 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3556 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003557 enforceReadPrivilegedPermission("getImsProvisioningInt");
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003561 int slotId = getSlotIndex(subId);
3562 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3563 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3564 + subId + "' for key:" + key);
3565 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3566 }
3567 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003568 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003569 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3570 + subId + "' for key:" + key);
3571 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
3575 }
3576
3577 @Override
3578 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003579 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3580 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3581 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003582 enforceReadPrivilegedPermission("getImsProvisioningString");
3583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003586 int slotId = getSlotIndex(subId);
3587 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3588 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3589 + subId + "' for key:" + key);
3590 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3591 }
3592 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003593 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003594 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3595 + subId + "' for key:" + key);
3596 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
3600 }
3601
3602 @Override
3603 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003604 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3605 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3606 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3608 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003612 int slotId = getSlotIndex(subId);
3613 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3614 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3615 + subId + "' for key:" + key);
3616 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3617 }
3618 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003619 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003620 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3621 + "' for key:" + key);
3622 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003623 } finally {
3624 Binder.restoreCallingIdentity(identity);
3625 }
3626 }
3627
3628 @Override
3629 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003630 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3631 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3632 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3634 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003638 int slotId = getSlotIndex(subId);
3639 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3640 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3641 + subId + "' for key:" + key);
3642 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3643 }
3644 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003645 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003646 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3647 + "' for key:" + key);
3648 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
3652 }
3653
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003654 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 int slotId = SubscriptionManager.getSlotIndex(subId);
3656 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003657 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3658 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 }
3660 return slotId;
3661 }
3662
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003663 private int getSlotIndex(int subId) {
3664 int slotId = SubscriptionManager.getSlotIndex(subId);
3665 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3666 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3667 }
3668 return slotId;
3669 }
3670
Wink Saville36469e72014-06-11 15:17:00 -07003671 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003672 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003673 */
3674 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003675 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003676 final int targetSdk = getTargetSdk(callingPackage);
3677 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3678 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3679 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003680 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3681 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003682 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3683 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 final Phone phone = getPhone(subId);
3688 if (phone != null) {
3689 return phone.getServiceState().getDataNetworkType();
3690 } else {
3691 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3692 }
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003696 }
3697
3698 /**
3699 * Returns the data network type
3700 */
3701 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003702 public int getDataNetworkType(String callingPackage) {
3703 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003704 }
3705
3706 /**
3707 * Returns the data network type for a subId
3708 */
3709 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003710 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003712 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003713 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3714 }
3715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 final Phone phone = getPhone(subId);
3719 if (phone != null) {
3720 return phone.getServiceState().getDataNetworkType();
3721 } else {
3722 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3723 }
3724 } finally {
3725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003727 }
3728
3729 /**
Wink Saville36469e72014-06-11 15:17:00 -07003730 * Returns the Voice network type for a subId
3731 */
3732 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003733 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003735 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003736 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3737 }
3738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 final Phone phone = getPhone(subId);
3742 if (phone != null) {
3743 return phone.getServiceState().getVoiceNetworkType();
3744 } else {
3745 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3746 }
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003750 }
3751
3752 /**
3753 * @return true if a ICC card is present
3754 */
3755 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003756 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003757 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3758 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003759 }
3760
3761 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003762 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003763 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003764 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003765 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 final Phone phone = PhoneFactory.getPhone(slotIndex);
3769 if (phone != null) {
3770 return phone.getIccCard().hasIccCard();
3771 } else {
3772 return false;
3773 }
3774 } finally {
3775 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003777 }
3778
3779 /**
3780 * Return if the current radio is LTE on CDMA. This
3781 * is a tri-state return value as for a period of time
3782 * the mode may be unknown.
3783 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003784 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003785 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003786 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003787 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003788 @Override
3789 public int getLteOnCdmaMode(String callingPackage) {
3790 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003791 }
3792
Sanket Padawe356d7632015-06-22 14:03:32 -07003793 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003794 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003796 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003797 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3798 }
3799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 final Phone phone = getPhone(subId);
3803 if (phone == null) {
3804 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3805 } else {
3806 return phone.getLteOnCdmaMode();
3807 }
3808 } finally {
3809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003810 }
Wink Saville36469e72014-06-11 15:17:00 -07003811 }
3812
Wink Saville36469e72014-06-11 15:17:00 -07003813 /**
3814 * {@hide}
3815 * Returns Default subId, 0 in the case of single standby.
3816 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003817 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003818 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003819 }
3820
Shishir Agrawala9f32182016-04-12 12:00:16 -07003821 private int getSlotForDefaultSubscription() {
3822 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3823 }
3824
Wink Savilleb564aae2014-10-23 10:18:09 -07003825 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003826 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003827 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003828
Pengquan Menge92a50d2018-09-21 15:54:48 -07003829 private boolean isActiveSubscription(int subId) {
3830 return mSubscriptionController.isActiveSubId(subId);
3831 }
3832
Ihab Awadf2177b72013-11-25 13:33:23 -08003833 /**
3834 * @see android.telephony.TelephonyManager.WifiCallingChoices
3835 */
3836 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3841 getWhenToMakeWifiCallsDefaultPreference());
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
3844 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003845 }
3846
3847 /**
3848 * @see android.telephony.TelephonyManager.WifiCallingChoices
3849 */
3850 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003854 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
3858 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003859 }
3860
Sailesh Nepald1e68152013-12-12 19:08:02 -08003861 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003862 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003863 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003864 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003865
Jordan Liu4c733742019-02-28 12:03:40 -08003866 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3867 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3868 if (phoneId == -1) {
3869 throw new IllegalArgumentException("Given slot index: " + slotIndex
3870 + " does not correspond to an active phone");
3871 }
3872 return PhoneFactory.getPhone(phoneId);
3873 }
3874
Shishir Agrawal566b7612013-10-28 14:41:00 -07003875 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003876 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3877 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3879 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003881 if (DBG) {
3882 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3883 }
3884 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3885 p2);
3886 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003887
Jordan Liu4c733742019-02-28 12:03:40 -08003888
3889 @Override
3890 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3891 int slotIndex, String callingPackage, String aid, int p2) {
3892 enforceModifyPermission();
3893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3894 if (DBG) {
3895 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3896 }
3897 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3898 callingPackage, aid, p2);
3899 }
3900
3901 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3902 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 if (TextUtils.equals(ISDR_AID, aid)) {
3906 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003907 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3908 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 if (bestComponent == null
3910 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3911 loge("The calling package is not allowed to access ISD-R.");
3912 throw new SecurityException(
3913 "The calling package is not allowed to access ISD-R.");
3914 }
Derek Tan740e1672017-06-27 14:56:27 -07003915 }
Derek Tan740e1672017-06-27 14:56:27 -07003916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003918 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3919 null /* workSource */);
3920 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 return response;
3922 } finally {
3923 Binder.restoreCallingIdentity(identity);
3924 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003925 }
3926
3927 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003928 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3930 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003931 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3932 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3933 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003934
Jordan Liu4c733742019-02-28 12:03:40 -08003935 @Override
3936 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3937 enforceModifyPermission();
3938 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3939 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3940 channel);
3941 }
3942
3943 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 final long identity = Binder.clearCallingIdentity();
3945 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946 if (channel < 0) {
3947 return false;
3948 }
Jordan Liu4c733742019-02-28 12:03:40 -08003949 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3950 null /* workSource */);
3951 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 return success;
3953 } finally {
3954 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003955 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003956 }
3957
3958 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003959 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003960 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3962 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003963 if (DBG) {
3964 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3965 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3966 + p3 + " data=" + data);
3967 }
3968 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3969 command, p1, p2, p3, data);
3970 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003971
Jordan Liu4c733742019-02-28 12:03:40 -08003972 @Override
3973 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3974 int command, int p1, int p2, int p3, String data) {
3975 enforceModifyPermission();
3976 if (DBG) {
3977 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3978 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3979 + p3 + " data=" + data);
3980 }
3981 return iccTransmitApduLogicalChannelWithPermission(
3982 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3983 data);
3984 }
3985
3986 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3987 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988 final long identity = Binder.clearCallingIdentity();
3989 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003990 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003991 return "";
3992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003995 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3996 null /* workSource */);
3997 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999 // Append the returned status code to the end of the response payload.
4000 String s = Integer.toHexString(
4001 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4002 if (response.payload != null) {
4003 s = IccUtils.bytesToHexString(response.payload) + s;
4004 }
4005 return s;
4006 } finally {
4007 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004008 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004009 }
Jake Hambye994d462014-02-03 13:10:13 -08004010
Evan Charltonc66da362014-05-16 14:06:40 -07004011 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004012 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4013 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4015 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004017 if (DBG) {
4018 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4019 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4020 }
4021 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4022 cla, command, p1, p2, p3, data);
4023 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004024
Jordan Liu4c733742019-02-28 12:03:40 -08004025 @Override
4026 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4027 int command, int p1, int p2, int p3, String data) {
4028 enforceModifyPermission();
4029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4030 if (DBG) {
4031 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4032 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4033 + " data=" + data);
4034 }
4035
4036 return iccTransmitApduBasicChannelWithPermission(
4037 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4038 p2, p3, data);
4039 }
4040
4041 // open APDU basic channel assuming the caller has sufficient permissions
4042 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4043 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4047 && TextUtils.equals(ISDR_AID, data)) {
4048 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004049 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4050 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051 if (bestComponent == null
4052 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4053 loge("The calling package is not allowed to select ISD-R.");
4054 throw new SecurityException(
4055 "The calling package is not allowed to select ISD-R.");
4056 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004057 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004060 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4061 null /* workSource */);
4062 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 // Append the returned status code to the end of the response payload.
4065 String s = Integer.toHexString(
4066 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4067 if (response.payload != null) {
4068 s = IccUtils.bytesToHexString(response.payload) + s;
4069 }
4070 return s;
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004073 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004074 }
4075
4076 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004077 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004078 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 if (DBG) {
4085 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4086 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4087 }
4088
4089 IccIoResult response =
4090 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4091 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4092 subId);
4093
4094 if (DBG) {
4095 log("Exchange SIM_IO [R]" + response);
4096 }
4097
4098 byte[] result = null;
4099 int length = 2;
4100 if (response.payload != null) {
4101 length = 2 + response.payload.length;
4102 result = new byte[length];
4103 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4104 } else {
4105 result = new byte[length];
4106 }
4107
4108 result[length - 1] = (byte) response.sw2;
4109 result[length - 2] = (byte) response.sw1;
4110 return result;
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004113 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004114 }
4115
Nathan Haroldb3014052017-01-25 15:57:32 -08004116 /**
4117 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4118 * on a particular subscription
4119 */
sqianb6e41952018-03-12 14:54:01 -07004120 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4122 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4123 return null;
4124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 if (appType != TelephonyManager.APPTYPE_USIM
4129 && appType != TelephonyManager.APPTYPE_SIM) {
4130 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4131 return null;
4132 }
4133 Object response = sendRequest(
4134 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4135 if (response instanceof String[]) {
4136 return (String[]) response;
4137 }
yincheng zhao2737e882019-09-06 17:06:54 -07004138 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004140 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 } finally {
4142 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004143 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004144 }
4145
yincheng zhao2737e882019-09-06 17:06:54 -07004146 /**
4147 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4148 * subscription.
4149 *
4150 * @param subId the id of the subscription.
4151 * @param appType the uicc app type, must be USIM or SIM.
4152 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4153 * @param callingPackage the op Package name.
4154 * @return number of fplmns that is successfully written to the SIM.
4155 */
4156 public int setForbiddenPlmns(
4157 int subId, int appType, List<String> fplmns, String callingPackage) {
4158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4159 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4160 if (DBG) logv("no permissions for setForbiddenplmns");
4161 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4162 }
4163 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4164 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4165 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4166 }
4167 if (fplmns == null) {
4168 throw new IllegalArgumentException("Fplmn List provided is null");
4169 }
4170 for (String fplmn : fplmns) {
4171 if (!CellIdentity.isValidPlmn(fplmn)) {
4172 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4173 }
4174 }
4175 final long identity = Binder.clearCallingIdentity();
4176 try {
4177 Object response = sendRequest(
4178 CMD_SET_FORBIDDEN_PLMNS,
4179 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4180 subId);
4181 return (int) response;
4182 } finally {
4183 Binder.restoreCallingIdentity(identity);
4184 }
4185 }
4186
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004187 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004188 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4190 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4195 if (response.payload == null) {
4196 return "";
4197 }
Evan Charltonc66da362014-05-16 14:06:40 -07004198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199 // Append the returned status code to the end of the response payload.
4200 String s = Integer.toHexString(
4201 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4202 s = IccUtils.bytesToHexString(response.payload) + s;
4203 return s;
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
Evan Charltonc66da362014-05-16 14:06:40 -07004207 }
4208
Jake Hambye994d462014-02-03 13:10:13 -08004209 /**
4210 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4211 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4212 *
4213 * @param itemID the ID of the item to read
4214 * @return the NV item as a String, or null on error.
4215 */
4216 @Override
4217 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4220 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221
4222 final long identity = Binder.clearCallingIdentity();
4223 try {
4224 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004225 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4227 return value;
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Jake Hambye994d462014-02-03 13:10:13 -08004231 }
4232
4233 /**
4234 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4235 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4236 *
4237 * @param itemID the ID of the item to read
4238 * @param itemValue the value to write, as a String
4239 * @return true on success; false on any failure
4240 */
4241 @Override
4242 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4245 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246
4247 final long identity = Binder.clearCallingIdentity();
4248 try {
4249 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4250 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004251 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4253 return success;
4254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
Jake Hambye994d462014-02-03 13:10:13 -08004257 }
4258
4259 /**
4260 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4261 * Used for device configuration by some CDMA operators.
4262 *
4263 * @param preferredRoamingList byte array containing the new PRL
4264 * @return true on success; false on any failure
4265 */
4266 @Override
4267 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4269 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270
4271 final long identity = Binder.clearCallingIdentity();
4272 try {
4273 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4274 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4275 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4276 return success;
4277 } finally {
4278 Binder.restoreCallingIdentity(identity);
4279 }
Jake Hambye994d462014-02-03 13:10:13 -08004280 }
4281
4282 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004283 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004284 * Used for device configuration by some CDMA operators.
4285 *
chen xu6dac5ab2018-10-26 17:39:23 -07004286 * @param slotIndex - device slot.
4287 *
Jake Hambye994d462014-02-03 13:10:13 -08004288 * @return true on success; false on any failure
4289 */
4290 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004291 public boolean resetModemConfig(int slotIndex) {
4292 Phone phone = PhoneFactory.getPhone(slotIndex);
4293 if (phone != null) {
4294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4295 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296
chen xu6dac5ab2018-10-26 17:39:23 -07004297 final long identity = Binder.clearCallingIdentity();
4298 try {
4299 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4300 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4301 return success;
4302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 }
chen xu6dac5ab2018-10-26 17:39:23 -07004306 return false;
4307 }
4308
4309 /**
4310 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4311 *
4312 * @param slotIndex - device slot.
4313 *
4314 * @return true on success; false on any failure
4315 */
4316 @Override
4317 public boolean rebootModem(int slotIndex) {
4318 Phone phone = PhoneFactory.getPhone(slotIndex);
4319 if (phone != null) {
4320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4321 mApp, phone.getSubId(), "rebootModem");
4322
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4326 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4327 return success;
4328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004333 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004334
Svet Ganovb320e182015-04-16 12:30:10 -07004335 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004336 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004338 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004339 return new String[0];
4340 }
4341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342 final long identity = Binder.clearCallingIdentity();
4343 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004344 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
Wink Saville36469e72014-06-11 15:17:00 -07004348 }
4349
Brad Ebinger51f743a2017-01-23 13:50:20 -08004350 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004351 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4352 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004353 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004354 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004355 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004359 ImsResolver resolver = PhoneFactory.getImsResolver();
4360 if (resolver == null) {
4361 // may happen if the device does not support IMS.
4362 return;
4363 }
4364 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004368 }
4369
4370 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004371 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4372 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004373 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004374 public void disableIms(int slotId) {
4375 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376
4377 final long identity = Binder.clearCallingIdentity();
4378 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004379 ImsResolver resolver = PhoneFactory.getImsResolver();
4380 if (resolver == null) {
4381 // may happen if the device does not support IMS.
4382 return;
4383 }
4384 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004388 }
4389
4390 /**
4391 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4392 * feature or {@link null} if the service is not available. If the feature is available, the
4393 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4394 */
4395 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004396 IImsServiceFeatureCallback callback) {
4397 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398
4399 final long identity = Binder.clearCallingIdentity();
4400 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004401 ImsResolver resolver = PhoneFactory.getImsResolver();
4402 if (resolver == null) {
4403 // may happen if the device does not support IMS.
4404 return null;
4405 }
4406 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004410 }
4411
4412 /**
4413 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4414 * feature during emergency calling or {@link null} if the service is not available. If the
4415 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4416 * listener for feature updates.
4417 */
4418 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4419 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420
4421 final long identity = Binder.clearCallingIdentity();
4422 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004423 ImsResolver resolver = PhoneFactory.getImsResolver();
4424 if (resolver == null) {
4425 // may happen if the device does not support IMS.
4426 return null;
4427 }
4428 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004432 }
4433
Brad Ebinger5f64b052017-12-14 14:26:15 -08004434 /**
4435 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004436 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004437 */
4438 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4439 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440
4441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004443 ImsResolver resolver = PhoneFactory.getImsResolver();
4444 if (resolver == null) {
4445 // may happen if the device does not support IMS.
4446 return null;
4447 }
4448 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004452 }
4453
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004454 /**
4455 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004456 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004457 */
4458 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4459 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004460
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004463 ImsResolver resolver = PhoneFactory.getImsResolver();
4464 if (resolver == null) {
4465 // may happen if the device does not support IMS.
4466 return null;
4467 }
4468 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004472 }
4473
Brad Ebinger884c07b2018-02-15 16:17:40 -08004474 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004475 * Sets the ImsService Package Name that Telephony will bind to.
4476 *
4477 * @param slotId the slot ID that the ImsService should bind for.
4478 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4479 * ImsService is the device default ImsService.
4480 * @param packageName The package name of the application that contains the ImsService to bind
4481 * to.
4482 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4483 * @hide
4484 */
4485 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004486 int[] subIds = SubscriptionManager.getSubId(slotId);
4487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4488 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4489 "setImsService");
4490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 final long identity = Binder.clearCallingIdentity();
4492 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004493 ImsResolver resolver = PhoneFactory.getImsResolver();
4494 if (resolver == null) {
4495 // may happen if the device does not support IMS.
4496 return false;
4497 }
4498 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4499 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004503 }
4504
4505 /**
4506 * Return the ImsService configuration.
4507 *
4508 * @param slotId The slot that the ImsService is associated with.
4509 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4510 * the device default.
4511 * @return the package name of the ImsService configuration.
4512 */
4513 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004514 int[] subIds = SubscriptionManager.getSubId(slotId);
4515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4516 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4517 "getImsService");
4518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 final long identity = Binder.clearCallingIdentity();
4520 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004521 ImsResolver resolver = PhoneFactory.getImsResolver();
4522 if (resolver == null) {
4523 // may happen if the device does not support IMS.
4524 return "";
4525 }
4526 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004530 }
4531
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004532 /**
4533 * Get the MmTelFeature state associated with the requested subscription id.
4534 * @param subId The subscription that the MmTelFeature is associated with.
4535 * @param callback A callback with an integer containing the
4536 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4537 */
4538 @Override
4539 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4540 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4541 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4543 "IMS not available on device.");
4544 }
4545 final long token = Binder.clearCallingIdentity();
4546 try {
4547 int slotId = getSlotIndex(subId);
4548 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4549 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4550 + subId + "'");
4551 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4552 }
4553 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4554 try {
4555 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4556 } catch (RemoteException e) {
4557 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4558 + "Ignore");
4559 }
4560 });
4561 } finally {
4562 Binder.restoreCallingIdentity(token);
4563 }
4564 }
4565
Wink Saville36469e72014-06-11 15:17:00 -07004566 public void setImsRegistrationState(boolean registered) {
4567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004571 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 } finally {
4573 Binder.restoreCallingIdentity(identity);
4574 }
Wink Saville36469e72014-06-11 15:17:00 -07004575 }
4576
4577 /**
Stuart Scott54788802015-03-30 13:18:01 -07004578 * Set the network selection mode to automatic.
4579 *
4580 */
4581 @Override
4582 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4584 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585
Pengquan Menge92a50d2018-09-21 15:54:48 -07004586 if (!isActiveSubscription(subId)) {
4587 return;
4588 }
4589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4593 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4594 } finally {
4595 Binder.restoreCallingIdentity(identity);
4596 }
Stuart Scott54788802015-03-30 13:18:01 -07004597 }
4598
Pengquan Mengea84e042018-09-20 14:57:26 -07004599 /**
4600 * Ask the radio to connect to the input network and change selection mode to manual.
4601 *
4602 * @param subId the id of the subscription.
4603 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4604 * the operator to attach to.
4605 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4606 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4607 * normal network selection next time.
4608 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004609 */
4610 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004611 public boolean setNetworkSelectionModeManual(
4612 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4614 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004615
4616 if (!isActiveSubscription(subId)) {
4617 return false;
4618 }
4619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620 final long identity = Binder.clearCallingIdentity();
4621 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004622 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004624 if (DBG) {
4625 log("setNetworkSelectionModeManual: subId: " + subId
4626 + " operator: " + operatorInfo);
4627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004632 }
4633
4634 /**
4635 * Scans for available networks.
4636 */
4637 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004638 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4640 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004641 LocationAccessPolicy.LocationPermissionResult locationResult =
4642 LocationAccessPolicy.checkLocationPermission(mApp,
4643 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4644 .setCallingPackage(callingPackage)
4645 .setCallingPid(Binder.getCallingPid())
4646 .setCallingUid(Binder.getCallingUid())
4647 .setMethod("getCellNetworkScanResults")
4648 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4649 .build());
4650 switch (locationResult) {
4651 case DENIED_HARD:
4652 throw new SecurityException("Not allowed to access scan results -- location");
4653 case DENIED_SOFT:
4654 return null;
4655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656
Pengquan Menga1bb6272018-09-06 09:59:22 -07004657 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004658 try {
4659 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004660 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004665 }
4666
4667 /**
yinxub1bed742017-04-17 11:45:04 -07004668 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004669 *
yinxub1bed742017-04-17 11:45:04 -07004670 * @param subId id of the subscription
4671 * @param request contains the radio access networks with bands/channels to scan
4672 * @param messenger callback messenger for scan results or errors
4673 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004674 * @return the id of the requested scan which can be used to stop the scan.
4675 */
4676 @Override
4677 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004678 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4680 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004681 LocationAccessPolicy.LocationPermissionResult locationResult =
4682 LocationAccessPolicy.checkLocationPermission(mApp,
4683 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4684 .setCallingPackage(callingPackage)
4685 .setCallingPid(Binder.getCallingPid())
4686 .setCallingUid(Binder.getCallingUid())
4687 .setMethod("requestNetworkScan")
4688 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4689 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004690 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004691 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004692 if (e != null) {
4693 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4694 throw e;
4695 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004696 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004697 return TelephonyScanManager.INVALID_SCAN_ID;
4698 }
4699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700 }
Hall Liu912dfd32019-04-25 14:02:26 -07004701 int callingUid = Binder.getCallingUid();
4702 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 return mNetworkScanRequestTracker.startNetworkScan(
4706 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004707 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
yinxu504e1392017-04-12 16:03:22 -07004711 }
4712
Hall Liub2ac8ef2019-02-28 15:56:23 -08004713 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004714 NetworkScanRequest request, int subId) {
4715 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4716 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4717 boolean hasNetworkScanPermission =
4718 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4719 == PERMISSION_GRANTED;
4720
4721 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4722 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4723 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004724 }
4725
4726 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4727 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004728 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4729 return new SecurityException("Specific channels must not be"
4730 + " scanned without location access.");
4731 }
4732 }
4733 }
4734
Hall Liub2ac8ef2019-02-28 15:56:23 -08004735 return null;
4736 }
4737
yinxu504e1392017-04-12 16:03:22 -07004738 /**
4739 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004740 *
4741 * @param subId id of the subscription
4742 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004743 */
4744 @Override
4745 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4747 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748
Hall Liu912dfd32019-04-25 14:02:26 -07004749 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 final long identity = Binder.clearCallingIdentity();
4751 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004752 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
yinxu504e1392017-04-12 16:03:22 -07004756 }
4757
4758 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004759 * Get the calculated preferred network type.
4760 * Used for debugging incorrect network type.
4761 *
4762 * @return the preferred network type, defined in RILConstants.java.
4763 */
4764 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004765 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004766 final Phone defaultPhone = getDefaultPhone();
4767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4768 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004769 return RILConstants.PREFERRED_NETWORK_MODE;
4770 }
4771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004772 final long identity = Binder.clearCallingIdentity();
4773 try {
4774 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004775 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 } finally {
4777 Binder.restoreCallingIdentity(identity);
4778 }
Junda Liu84d15a22014-07-02 11:21:04 -07004779 }
4780
4781 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004782 * Get the preferred network type.
4783 * Used for device configuration by some CDMA operators.
4784 *
4785 * @return the preferred network type, defined in RILConstants.java.
4786 */
4787 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004788 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004789 TelephonyPermissions
4790 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4791 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792
4793 final long identity = Binder.clearCallingIdentity();
4794 try {
4795 if (DBG) log("getPreferredNetworkType");
4796 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4797 int networkType = (result != null ? result[0] : -1);
4798 if (DBG) log("getPreferredNetworkType: " + networkType);
4799 return networkType;
4800 } finally {
4801 Binder.restoreCallingIdentity(identity);
4802 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004803 }
4804
4805 /**
4806 * Set the preferred network type.
4807 * Used for device configuration by some CDMA operators.
4808 *
4809 * @param networkType the preferred network type, defined in RILConstants.java.
4810 * @return true on success; false on any failure.
4811 */
4812 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004813 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4815 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816
4817 final long identity = Binder.clearCallingIdentity();
4818 try {
4819 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4820 Boolean success = (Boolean) sendRequest(
4821 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4822 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4823 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004824 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4826 }
4827 return success;
4828 } finally {
4829 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004830 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004831 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004832
4833 /**
Miaoa84611c2019-03-15 09:21:10 +08004834 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004835 *
Miaoa84611c2019-03-15 09:21:10 +08004836 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004837 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004838 * @hide
4839 */
4840 @Override
Miaoa84611c2019-03-15 09:21:10 +08004841 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004843 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004844 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845 try {
Miaoa84611c2019-03-15 09:21:10 +08004846 if (phone != null) {
4847 return phone.hasMatchedTetherApnSetting();
4848 } else {
4849 return false;
4850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 } finally {
4852 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004853 }
Junda Liu475951f2014-11-07 16:45:03 -08004854 }
4855
4856 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004857 * Set mobile data enabled
4858 * Used by the user through settings etc to turn on/off mobile data
4859 *
4860 * @param enable {@code true} turn turn data on, else {@code false}
4861 */
4862 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004863 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4865 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866
4867 final long identity = Binder.clearCallingIdentity();
4868 try {
4869 int phoneId = mSubscriptionController.getPhoneId(subId);
4870 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4871 Phone phone = PhoneFactory.getPhone(phoneId);
4872 if (phone != null) {
4873 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004874 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004876 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004877 }
4878 } finally {
4879 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004880 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004881 }
4882
4883 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004884 * Get the user enabled state of Mobile Data.
4885 *
4886 * TODO: remove and use isUserDataEnabled.
4887 * This can't be removed now because some vendor codes
4888 * calls through ITelephony directly while they should
4889 * use TelephonyManager.
4890 *
4891 * @return true on enabled
4892 */
4893 @Override
4894 public boolean getDataEnabled(int subId) {
4895 return isUserDataEnabled(subId);
4896 }
4897
4898 /**
4899 * Get whether mobile data is enabled per user setting.
4900 *
4901 * There are other factors deciding whether mobile data is actually enabled, but they are
4902 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004903 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004904 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004905 *
4906 * @return {@code true} if data is enabled else {@code false}
4907 */
4908 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004909 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004910 try {
4911 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4912 null);
4913 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4915 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917
4918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 int phoneId = mSubscriptionController.getPhoneId(subId);
4921 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4922 Phone phone = PhoneFactory.getPhone(phoneId);
4923 if (phone != null) {
4924 boolean retVal = phone.isUserDataEnabled();
4925 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4926 return retVal;
4927 } else {
4928 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4929 return false;
4930 }
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004933 }
4934 }
4935
4936 /**
4937 * Get whether mobile data is enabled.
4938 *
4939 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4940 * whether mobile data is actually enabled.
4941 *
4942 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4943 *
4944 * @return {@code true} if data is enabled else {@code false}
4945 */
4946 @Override
4947 public boolean isDataEnabled(int subId) {
4948 try {
4949 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4950 null);
4951 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4953 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955
4956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 int phoneId = mSubscriptionController.getPhoneId(subId);
4959 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4960 Phone phone = PhoneFactory.getPhone(phoneId);
4961 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004962 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4964 return retVal;
4965 } else {
4966 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4967 return false;
4968 }
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004971 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004972 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004973
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004974 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
4975 Phone phone) {
4976 //load access rules from carrier configs, and check those as well: b/139133814
4977 SubscriptionController subController = SubscriptionController.getInstance();
4978 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4979 || subController == null) return privilegeFromSim;
4980
4981 int uid = Binder.getCallingUid();
4982 PackageManager pkgMgr = phone.getContext().getPackageManager();
4983 String[] packages = pkgMgr.getPackagesForUid(uid);
4984
4985 final long identity = Binder.clearCallingIdentity();
4986 try {
4987 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4988 SubscriptionManager subManager = (SubscriptionManager)
4989 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4990 for (String pkg : packages) {
4991 if (subManager.canManageSubscription(subInfo, pkg)) {
4992 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4993 }
4994 }
4995 return privilegeFromSim;
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
4999 }
5000
5001 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5002 String pkgName) {
5003 //load access rules from carrier configs, and check those as well: b/139133814
5004 SubscriptionController subController = SubscriptionController.getInstance();
5005 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5006 || subController == null) return privilegeFromSim;
5007
5008 final long identity = Binder.clearCallingIdentity();
5009 try {
5010 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5011 SubscriptionManager subManager = (SubscriptionManager)
5012 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5013 return subManager.canManageSubscription(subInfo, pkgName)
5014 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5015 } finally {
5016 Binder.restoreCallingIdentity(identity);
5017 }
5018 }
5019
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005020 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005021 public int getCarrierPrivilegeStatus(int subId) {
5022 final Phone phone = getPhone(subId);
5023 if (phone == null) {
5024 loge("getCarrierPrivilegeStatus: Invalid subId");
5025 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5026 }
5027 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005028 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005029 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005030 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5031 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005032
5033 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5034 card.getCarrierPrivilegeStatusForCurrentTransaction(
5035 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005036 }
Junda Liu29340342014-07-10 15:23:27 -07005037
5038 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005039 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5040 final Phone phone = getPhone(subId);
5041 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005042 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005043 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5044 }
5045 UiccProfile profile =
5046 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5047 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005048 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005049 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5050 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005051 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5052 profile.getCarrierPrivilegeStatusForUid(
5053 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005054 }
5055
5056 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005057 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5058 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005059 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005060 }
5061
5062 int phoneId = SubscriptionManager.getPhoneId(subId);
5063 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005064 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005065 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005066 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5067 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005068 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5069 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5070 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005071 }
5072
5073 @Override
5074 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005075 if (TextUtils.isEmpty(pkgName))
5076 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005077 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5078 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5079 UiccCard card = UiccController.getInstance().getUiccCard(i);
5080 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005081 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005082 continue;
5083 }
5084
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005085 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5086 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5087 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005088 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5089 break;
5090 }
5091 }
5092
5093 return result;
Junda Liu29340342014-07-10 15:23:27 -07005094 }
Derek Tan89e89d42014-07-08 17:00:10 -07005095
5096 @Override
Junda Liue64de782015-04-16 17:19:16 -07005097 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5098 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5099 loge("phoneId " + phoneId + " is not valid.");
5100 return null;
5101 }
5102 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005103 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005104 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005105 return null ;
5106 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005107 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005108 }
5109
Amith Yamasani6e118872016-02-19 12:53:51 -08005110 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005111 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005112 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005113 List<String> privilegedPackages = new ArrayList<>();
5114 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005115 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5116 // has UICC in that slot.
5117 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005118 if (card.hasCarrierPrivilegeRules()) {
5119 if (packages == null) {
5120 // Only check packages in user 0 for now
5121 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005122 PackageManager.MATCH_DISABLED_COMPONENTS
5123 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005124 | PackageManager.GET_SIGNING_CERTIFICATES,
5125 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005126 }
5127 for (int p = packages.size() - 1; p >= 0; p--) {
5128 PackageInfo pkgInfo = packages.get(p);
5129 if (pkgInfo != null && pkgInfo.packageName != null
5130 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005131 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005132 privilegedPackages.add(pkgInfo.packageName);
5133 }
5134 }
5135 }
5136 }
5137 return privilegedPackages;
5138 }
5139
chen xuf7e9fe82019-05-09 19:31:02 -07005140 @Override
5141 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5142 List<String> privilegedPackages = new ArrayList<>();
5143 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5144 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5145 }
5146 return privilegedPackages;
5147 }
5148
Wink Savilleb564aae2014-10-23 10:18:09 -07005149 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005150 final Phone phone = getPhone(subId);
5151 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005152 if (card == null) {
5153 loge("getIccId: No UICC");
5154 return null;
5155 }
5156 String iccId = card.getIccId();
5157 if (TextUtils.isEmpty(iccId)) {
5158 loge("getIccId: ICC ID is null or empty.");
5159 return null;
5160 }
5161 return iccId;
5162 }
5163
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005164 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005165 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5166 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005167 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5168 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 final long identity = Binder.clearCallingIdentity();
5171 try {
5172 final String iccId = getIccId(subId);
5173 final Phone phone = getPhone(subId);
5174 if (phone == null) {
5175 return false;
5176 }
5177 final String subscriberId = phone.getSubscriberId();
5178
5179 if (DBG_MERGE) {
5180 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5181 + subscriberId + " to " + number);
5182 }
5183
5184 if (TextUtils.isEmpty(iccId)) {
5185 return false;
5186 }
5187
5188 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5189
5190 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5191 if (alphaTag == null) {
5192 editor.remove(alphaTagPrefKey);
5193 } else {
5194 editor.putString(alphaTagPrefKey, alphaTag);
5195 }
5196
5197 // Record both the line number and IMSI for this ICCID, since we need to
5198 // track all merged IMSIs based on line number
5199 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5200 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5201 if (number == null) {
5202 editor.remove(numberPrefKey);
5203 editor.remove(subscriberPrefKey);
5204 } else {
5205 editor.putString(numberPrefKey, number);
5206 editor.putString(subscriberPrefKey, subscriberId);
5207 }
5208
5209 editor.commit();
5210 return true;
5211 } finally {
5212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005213 }
Derek Tan7226c842014-07-02 17:42:23 -07005214 }
5215
5216 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005217 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005218 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005220 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005221 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005222 return null;
5223 }
Derek Tan97ebb422014-09-05 16:55:38 -07005224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
5227 String iccId = getIccId(subId);
5228 if (iccId != null) {
5229 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5230 if (DBG_MERGE) {
5231 log("getLine1NumberForDisplay returning "
5232 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5233 }
5234 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5237 return null;
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005240 }
Derek Tan7226c842014-07-02 17:42:23 -07005241 }
5242
5243 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005244 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005246 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005247 return null;
5248 }
Derek Tan97ebb422014-09-05 16:55:38 -07005249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 final long identity = Binder.clearCallingIdentity();
5251 try {
5252 String iccId = getIccId(subId);
5253 if (iccId != null) {
5254 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5255 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5256 }
5257 return null;
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005260 }
Derek Tan7226c842014-07-02 17:42:23 -07005261 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005262
5263 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005264 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005265 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5266 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005268 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5269 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005270 return null;
5271 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005272
Jordan Liub49b04b2019-05-06 14:45:15 -07005273 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5274 // the process, where TelephonyManager was instantiated.
5275 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005276 final long identity = Binder.clearCallingIdentity();
5277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005278 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 final TelephonyManager tele = TelephonyManager.from(context);
5280 final SubscriptionManager sub = SubscriptionManager.from(context);
5281
5282 // Figure out what subscribers are currently active
5283 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284
Jordan Liub49b04b2019-05-06 14:45:15 -07005285 // Only consider subs which match the current subId
5286 // This logic can be simplified. See b/131189269 for progress.
5287 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005288 activeSubscriberIds.add(tele.getSubscriberId(subId));
5289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290
5291 // First pass, find a number override for an active subscriber
5292 String mergeNumber = null;
5293 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5294 for (String key : prefs.keySet()) {
5295 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5296 final String subscriberId = (String) prefs.get(key);
5297 if (activeSubscriberIds.contains(subscriberId)) {
5298 final String iccId = key.substring(
5299 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5300 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5301 mergeNumber = (String) prefs.get(numberKey);
5302 if (DBG_MERGE) {
5303 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5304 + " for active subscriber " + subscriberId);
5305 }
5306 if (!TextUtils.isEmpty(mergeNumber)) {
5307 break;
5308 }
5309 }
5310 }
5311 }
5312
5313 // Shortcut when no active merged subscribers
5314 if (TextUtils.isEmpty(mergeNumber)) {
5315 return null;
5316 }
5317
5318 // Second pass, find all subscribers under that line override
5319 final ArraySet<String> result = new ArraySet<>();
5320 for (String key : prefs.keySet()) {
5321 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5322 final String number = (String) prefs.get(key);
5323 if (mergeNumber.equals(number)) {
5324 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5325 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5326 final String subscriberId = (String) prefs.get(subscriberKey);
5327 if (!TextUtils.isEmpty(subscriberId)) {
5328 result.add(subscriberId);
5329 }
5330 }
5331 }
5332 }
5333
5334 final String[] resultArray = result.toArray(new String[result.size()]);
5335 Arrays.sort(resultArray);
5336 if (DBG_MERGE) {
5337 Slog.d(LOG_TAG,
5338 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5339 }
5340 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005341 } finally {
5342 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005343 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005344 }
5345
5346 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005347 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5348 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5349
5350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 final TelephonyManager telephonyManager = mApp.getSystemService(
5353 TelephonyManager.class);
5354 String subscriberId = telephonyManager.getSubscriberId(subId);
5355 if (subscriberId == null) {
5356 if (DBG) {
5357 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5358 + subId);
5359 }
5360 return null;
5361 }
5362
5363 final SubscriptionInfo info = SubscriptionController.getInstance()
5364 .getSubscriptionInfo(subId);
5365 final ParcelUuid groupUuid = info.getGroupUuid();
5366 // If it doesn't belong to any group, return just subscriberId of itself.
5367 if (groupUuid == null) {
5368 return new String[]{subscriberId};
5369 }
5370
5371 // Get all subscriberIds from the group.
5372 final List<String> mergedSubscriberIds = new ArrayList<>();
5373 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5374 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5375 for (SubscriptionInfo subInfo : groupInfos) {
5376 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5377 if (subscriberId != null) {
5378 mergedSubscriberIds.add(subscriberId);
5379 }
5380 }
5381
5382 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385
5386 }
5387 }
5388
5389 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005390 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005391 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5392 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393
5394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 final Phone phone = getPhone(subId);
5397 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005401 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005402
5403 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005404 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005405 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5406 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005407 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408
5409 final long identity = Binder.clearCallingIdentity();
5410 try {
5411 final Phone phone = getPhone(subId);
5412 if (phone == null) {
5413 return false;
5414 }
5415 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5416 cdmaNonRoamingList);
5417 } finally {
5418 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005419 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005420 }
5421
5422 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005423 @Deprecated
5424 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5425 enforceModifyPermission();
5426
5427 int returnValue = 0;
5428 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005429 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005430 if(result.exception == null) {
5431 if (result.result != null) {
5432 byte[] responseData = (byte[])(result.result);
5433 if(responseData.length > oemResp.length) {
5434 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5435 responseData.length + "bytes. Buffer Size is " +
5436 oemResp.length + "bytes.");
5437 }
5438 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5439 returnValue = responseData.length;
5440 }
5441 } else {
5442 CommandException ex = (CommandException) result.exception;
5443 returnValue = ex.getCommandError().ordinal();
5444 if(returnValue > 0) returnValue *= -1;
5445 }
5446 } catch (RuntimeException e) {
5447 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5448 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5449 if(returnValue > 0) returnValue *= -1;
5450 }
5451
5452 return returnValue;
5453 }
5454
5455 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005456 public void setRadioCapability(RadioAccessFamily[] rafs) {
5457 try {
5458 ProxyController.getInstance().setRadioCapability(rafs);
5459 } catch (RuntimeException e) {
5460 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5461 }
5462 }
5463
5464 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005465 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005466 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005467 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005468 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005469 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 final long identity = Binder.clearCallingIdentity();
5472 try {
chen xub97461a2018-10-26 14:17:57 -07005473 TelephonyPermissions
5474 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5475 mApp, phone.getSubId(), "getRadioAccessFamily");
5476 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
chen xub97461a2018-10-26 14:17:57 -07005480 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005481 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005482
5483 @Override
5484 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005485 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005490 ImsManager.getInstance(defaultPhone.getContext(),
5491 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 } finally {
5493 Binder.restoreCallingIdentity(identity);
5494 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005495 }
5496
5497 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005498 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005499 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005501 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005502 return false;
5503 }
Svet Ganovb320e182015-04-16 12:30:10 -07005504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 final long identity = Binder.clearCallingIdentity();
5506 try {
5507 // Check the user preference and the system-level IMS setting. Even if the user has
5508 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5509 // In the long run, we may instead need to check if there exists a connection service
5510 // which can support video calling.
5511 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005512 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 return imsManager.isVtEnabledByPlatform()
5514 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5515 && imsManager.isVtEnabledByUser();
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005519 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005520
Andrew Leea1239f22015-03-02 17:44:07 -08005521 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5524 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5525 return false;
5526 }
5527
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 CarrierConfigManager configManager =
5531 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005532 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Andrew Leea1239f22015-03-02 17:44:07 -08005537 }
5538
5539 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540 public boolean isWorldPhone(int subId, String callingPackage) {
5541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5542 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5543 return false;
5544 }
5545
5546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 CarrierConfigManager configManager =
5549 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005550 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
5554 }
Andrew Leea1239f22015-03-02 17:44:07 -08005555 }
5556
Andrew Lee9431b832015-03-09 18:46:45 -07005557 @Override
5558 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005559 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005560 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005561 }
5562
5563 @Override
5564 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 final long identity = Binder.clearCallingIdentity();
5566 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005567 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
Andrew Lee9431b832015-03-09 18:46:45 -07005571 }
5572
Hall Liuf6668912018-10-31 17:05:23 -07005573 /**
5574 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5575 * support for the feature and device firmware support.
5576 *
5577 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5578 */
5579 @Override
5580 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005582 final Phone phone = getPhone(subscriptionId);
5583 if (phone == null) {
5584 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5585 return false;
5586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005588 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5590 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005591 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 return isCarrierSupported && isDeviceSupported;
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
Hall Liu98187582018-01-22 19:15:32 -08005596 }
5597
Hall Liuf6668912018-10-31 17:05:23 -07005598 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005599 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5600 * RTT setting, will return true if the device and carrier both support RTT.
5601 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005602 */
5603 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 final long identity = Binder.clearCallingIdentity();
5605 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005606 boolean isRttSupported = isRttSupported(subscriptionId);
5607 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005608 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005609 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5610 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5611 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 } finally {
5613 Binder.restoreCallingIdentity(identity);
5614 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005615 }
5616
Sanket Padawe7310cc72015-01-14 09:53:20 -08005617 /**
5618 * Returns the unique device ID of phone, for example, the IMEI for
5619 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5620 *
5621 * <p>Requires Permission:
5622 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5623 */
5624 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005625 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005626 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005627 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005628 return null;
5629 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005630 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005631 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5632 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005633 return null;
5634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 return phone.getDeviceId();
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005642 }
5643
Ping Sunc67b7c22016-03-02 19:16:45 +08005644 /**
5645 * {@hide}
5646 * Returns the IMS Registration Status on a particular subid
5647 *
5648 * @param subId
5649 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005650 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005651 Phone phone = getPhone(subId);
5652 if (phone != null) {
5653 return phone.isImsRegistered();
5654 } else {
5655 return false;
5656 }
5657 }
5658
Santos Cordon7a1885b2015-02-03 11:15:19 -08005659 @Override
5660 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005667 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005668
Tyler Gunnf70ed162019-04-03 15:28:53 -07005669 @Override
5670 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 Phone phone = getPhone(subscriptionId);
5674 if (phone == null) {
5675 return null;
5676 }
5677 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5678 } finally {
5679 Binder.restoreCallingIdentity(identity);
5680 }
5681 }
5682
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005683 /**
5684 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005685 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005686 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 Phone phone = getPhone(subId);
5690 if (phone != null) {
5691 return phone.isWifiCallingEnabled();
5692 } else {
5693 return false;
5694 }
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005697 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005698 }
5699
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005700 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005701 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005702 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005703 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 final long identity = Binder.clearCallingIdentity();
5705 try {
5706 Phone phone = getPhone(subId);
5707 if (phone != null) {
5708 return phone.isVideoEnabled();
5709 } else {
5710 return false;
5711 }
5712 } finally {
5713 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005714 }
5715 }
5716
5717 /**
5718 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5719 * defined in {@link ImsRegistrationImplBase}.
5720 */
5721 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 Phone phone = getPhone(subId);
5725 if (phone != null) {
5726 return phone.getImsRegistrationTech();
5727 } else {
5728 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5729 }
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005732 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005733 }
5734
Stuart Scott8eef64f2015-04-08 15:13:54 -07005735 @Override
5736 public void factoryReset(int subId) {
5737 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005738 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5739 return;
5740 }
5741
Svet Ganovcc087f82015-05-12 20:35:54 -07005742 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005743
Svet Ganovcc087f82015-05-12 20:35:54 -07005744 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005745 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5746 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005747 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005748 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005749 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005750 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5751 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005752 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005753 // There has been issues when Sms raw table somehow stores orphan
5754 // fragments. They lead to garbled message when new fragments come
5755 // in and combined with those stale ones. In case this happens again,
5756 // user can reset all network settings which will clean up this table.
5757 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005758 // Clean up IMS settings as well here.
5759 int slotId = getSlotIndex(subId);
5760 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5761 ImsManager.getInstance(mApp, slotId).factoryReset();
5762 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005763 } finally {
5764 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005765 }
5766 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005767
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005768 private void cleanUpSmsRawTable(Context context) {
5769 ContentResolver resolver = context.getContentResolver();
5770 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5771 resolver.delete(uri, null, null);
5772 }
5773
Narayan Kamath1c496c22015-04-16 14:40:19 +01005774 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005775 public String getSimLocaleForSubscriber(int subId) {
5776 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5777 final Phone phone = getPhone(subId);
5778 if (phone == null) {
5779 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005780 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 final long identity = Binder.clearCallingIdentity();
5783 try {
chen xu5d3637b2019-01-21 23:31:38 -08005784 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5785 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005786 if (info == null) {
5787 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5788 return null;
5789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 // Try and fetch the locale from the carrier properties or from the SIM language
5791 // preferences (EF-PL and EF-LI)...
5792 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005794 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5795 if (localeFromDefaultSim != null) {
5796 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5797 if (DBG) log("Using locale from subId: " + subId + " locale: "
5798 + localeFromDefaultSim);
5799 return localeFromDefaultSim.toLanguageTag();
5800 } else {
5801 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802 }
5803 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 // The SIM language preferences only store a language (e.g. fr = French), not an
5806 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5807 // the SIM and carrier preferences does not include a country we add the country
5808 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005809 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005811 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 return mccLocale.toLanguageTag();
5813 }
5814
5815 if (DBG) log("No locale found - returning null");
5816 return null;
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
5819 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005820 }
5821
5822 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005823 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005824 }
5825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 /**
5827 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5828 */
5829 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005830 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005831 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005832
Chenjie Yu1ba97252018-01-11 18:16:20 -08005833 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005834 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005835
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005836 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005837 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5838 * representing the state of the modem.
5839 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005840 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5841 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005842 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005843 */
5844 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005845 public void requestModemActivityInfo(ResultReceiver result) {
5846 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005847 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848
5849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 ModemActivityInfo ret = null;
5852 synchronized (mLastModemActivityInfo) {
5853 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5854 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005855 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005856 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005858 int[] txTimeMs = info.getTransmitTimeMillis();
5859 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005861 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 }
5863 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005864 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5865 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 mLastModemActivityInfo.setIdleTimeMillis(
5867 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005868 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5869 mLastModemActivityInfo.setReceiveTimeMillis(
5870 info.getReceiveTimeMillis() + mLastModemActivityInfo
5871 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005872 }
Chen Xud78231e2019-09-10 18:49:52 -07005873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5875 mLastModemActivityInfo.getSleepTimeMillis(),
5876 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005877 mLastModemActivityInfo.getTransmitTimeMillis(),
5878 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 Bundle bundle = new Bundle();
5881 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5882 result.send(0, bundle);
5883 } finally {
5884 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005885 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005886 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005887
Siddharth Rayb8114062018-06-17 15:02:38 -07005888 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5889 // less than total activity duration.
5890 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5891 if (info == null) {
5892 return false;
5893 }
5894 int activityDurationMs =
5895 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5896 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005897 int[] txTimeMs = info.getTransmitTimeMillis();
5898 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5899 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005900 }
5901 return (info.isValid()
5902 && (info.getSleepTimeMillis() <= activityDurationMs)
5903 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005904 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005905 && (totalTxTimeMs <= activityDurationMs));
5906 }
5907
Jack Yu85bd38a2015-11-09 11:34:32 -08005908 /**
5909 * {@hide}
5910 * Returns the service state information on specified subscription.
5911 */
5912 @Override
5913 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005915 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005916 return null;
5917 }
5918
Hall Liuf19c44f2018-11-27 14:38:17 -08005919 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5920 LocationAccessPolicy.checkLocationPermission(mApp,
5921 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5922 .setCallingPackage(callingPackage)
5923 .setCallingPid(Binder.getCallingPid())
5924 .setCallingUid(Binder.getCallingUid())
5925 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005926 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005927 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5928 .build());
5929
5930 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5931 LocationAccessPolicy.checkLocationPermission(mApp,
5932 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5933 .setCallingPackage(callingPackage)
5934 .setCallingPid(Binder.getCallingPid())
5935 .setCallingUid(Binder.getCallingUid())
5936 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005937 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005938 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5939 .build());
5940 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5941 boolean hasFinePermission =
5942 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5943 boolean hasCoarsePermission =
5944 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 final long identity = Binder.clearCallingIdentity();
5947 try {
5948 final Phone phone = getPhone(subId);
5949 if (phone == null) {
5950 return null;
5951 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005952
Hall Liuf19c44f2018-11-27 14:38:17 -08005953 ServiceState ss = phone.getServiceState();
5954
5955 // Scrub out the location info in ServiceState depending on what level of access
5956 // the caller has.
5957 if (hasFinePermission) return ss;
5958 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5959 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005963 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005964
5965 /**
5966 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5967 *
5968 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5969 * voicemail ringtone.
5970 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5971 * PhoneAccount.
5972 */
5973 @Override
5974 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 final long identity = Binder.clearCallingIdentity();
5976 try {
5977 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5978 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005979 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005986 }
5987
5988 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005989 * Sets the per-account voicemail ringtone.
5990 *
5991 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5992 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5993 *
5994 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5995 * voicemail ringtone.
5996 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5997 * PhoneAccount.
5998 */
5999 @Override
6000 public void setVoicemailRingtoneUri(String callingPackage,
6001 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006002 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006003 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6004 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006005 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6007 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6008 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 final long identity = Binder.clearCallingIdentity();
6012 try {
6013 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6014 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006015 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 }
6017 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6018 } finally {
6019 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006020 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006021 }
6022
6023 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006024 * Returns whether vibration is set for voicemail notification in Phone settings.
6025 *
6026 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6027 * voicemail vibration setting.
6028 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6029 */
6030 @Override
6031 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 final long identity = Binder.clearCallingIdentity();
6033 try {
6034 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6035 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006036 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6040 } finally {
6041 Binder.restoreCallingIdentity(identity);
6042 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006043 }
6044
Youhan Wange64578a2016-05-02 15:32:42 -07006045 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006046 * Sets the per-account voicemail vibration.
6047 *
6048 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6049 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6050 *
6051 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6052 * voicemail vibration setting.
6053 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6054 * specific PhoneAccount.
6055 */
6056 @Override
6057 public void setVoicemailVibrationEnabled(String callingPackage,
6058 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006059 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006060 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6061 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006062 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6064 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6065 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006066 }
6067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6071 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006072 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 }
6074 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6075 } finally {
6076 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006077 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006078 }
6079
6080 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006081 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6082 *
6083 * @throws SecurityException if the caller does not have the required permission
6084 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006085 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006086 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006087 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006088 }
6089
6090 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006091 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6092 * permission.
6093 *
6094 * @throws SecurityException if the caller does not have the required permission
6095 */
6096 private void enforceSendSmsPermission() {
6097 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6098 }
6099
6100 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006101 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006102 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006103 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006104 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006105 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006109 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 if (componentName == null) {
6111 throw new SecurityException(
6112 "Caller not current active visual voicemail package[null]");
6113 }
6114 String vvmPackage = componentName.getPackageName();
6115 if (!callingPackage.equals(vvmPackage)) {
6116 throw new SecurityException("Caller not current active visual voicemail package["
6117 + vvmPackage + "]");
6118 }
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006121 }
6122 }
6123
6124 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006125 * Return the application ID for the app type.
6126 *
6127 * @param subId the subscription ID that this request applies to.
6128 * @param appType the uicc app type.
6129 * @return Application ID for specificied app type, or null if no uicc.
6130 */
6131 @Override
6132 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006133 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006134 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135
6136 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006137 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 if (phone == null) {
6139 return null;
6140 }
6141 String aid = null;
6142 try {
6143 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6144 .getApplicationByType(appType).getAid();
6145 } catch (Exception e) {
6146 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6147 }
6148 return aid;
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006151 }
Youhan Wange64578a2016-05-02 15:32:42 -07006152 }
6153
Youhan Wang4001d252016-05-11 10:29:41 -07006154 /**
6155 * Return the Electronic Serial Number.
6156 *
6157 * @param subId the subscription ID that this request applies to.
6158 * @return ESN or null if error.
6159 */
6160 @Override
6161 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006162 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006163 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164
6165 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006166 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 if (phone == null) {
6168 return null;
6169 }
6170 String esn = null;
6171 try {
6172 esn = phone.getEsn();
6173 } catch (Exception e) {
6174 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6175 }
6176 return esn;
6177 } finally {
6178 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006179 }
Youhan Wang4001d252016-05-11 10:29:41 -07006180 }
6181
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006182 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006183 * Return the Preferred Roaming List Version.
6184 *
6185 * @param subId the subscription ID that this request applies to.
6186 * @return PRLVersion or null if error.
6187 */
6188 @Override
6189 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006190 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006191 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192
6193 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006194 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 if (phone == null) {
6196 return null;
6197 }
6198 String cdmaPrlVersion = null;
6199 try {
6200 cdmaPrlVersion = phone.getCdmaPrlVersion();
6201 } catch (Exception e) {
6202 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6203 }
6204 return cdmaPrlVersion;
6205 } finally {
6206 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006207 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006208 }
6209
6210 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006211 * Get snapshot of Telephony histograms
6212 * @return List of Telephony histograms
6213 * @hide
6214 */
6215 @Override
6216 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6218 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219
6220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 return RIL.getTelephonyRILTimingHistograms();
6223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006226 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006227
6228 /**
6229 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006230 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6231 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006232 * Require system privileges. In the future we may add this to carrier APIs.
6233 *
Michele Berionne482f8202018-11-27 18:57:59 -08006234 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006235 */
6236 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006237 @TelephonyManager.SetCarrierRestrictionResult
6238 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006239 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006240 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006241
Michele Berionne482f8202018-11-27 18:57:59 -08006242 if (carrierRestrictionRules == null) {
6243 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006244 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 final long identity = Binder.clearCallingIdentity();
6247 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006248 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006249 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 } finally {
6251 Binder.restoreCallingIdentity(identity);
6252 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006253 }
6254
6255 /**
6256 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006257 * Get the allowed carrier list and the excluded carrier list, including the priority between
6258 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006259 * Require system privileges. In the future we may add this to carrier APIs.
6260 *
Michele Berionne482f8202018-11-27 18:57:59 -08006261 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006262 */
6263 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006264 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006265 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006266 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267
6268 final long identity = Binder.clearCallingIdentity();
6269 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006270 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6271 if (response instanceof CarrierRestrictionRules) {
6272 return (CarrierRestrictionRules) response;
6273 }
6274 // Response is an Exception of some kind,
6275 // which is signalled to the user as a NULL retval
6276 return null;
6277 } catch (Exception e) {
6278 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6279 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006283 }
6284
fionaxu59545b42016-05-25 15:53:37 -07006285 /**
6286 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6287 * @param subId the subscription ID that this action applies to.
6288 * @param enabled control enable or disable metered apns.
6289 * {@hide}
6290 */
6291 @Override
6292 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6293 enforceModifyPermission();
6294 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295
6296 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006297 if (phone == null) {
6298 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6299 return;
6300 }
6301 try {
6302 phone.carrierActionSetMeteredApnsEnabled(enabled);
6303 } catch (Exception e) {
6304 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 } finally {
6306 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006307 }
6308 }
6309
6310 /**
6311 * Action set from carrier signalling broadcast receivers to enable/disable radio
6312 * @param subId the subscription ID that this action applies to.
6313 * @param enabled control enable or disable radio.
6314 * {@hide}
6315 */
6316 @Override
6317 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6318 enforceModifyPermission();
6319 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320
6321 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006322 if (phone == null) {
6323 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6324 return;
6325 }
6326 try {
6327 phone.carrierActionSetRadioEnabled(enabled);
6328 } catch (Exception e) {
6329 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330 } finally {
6331 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006332 }
6333 }
6334
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006335 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006336 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6337 * network status based on which carrier apps could apply actions accordingly,
6338 * enable/disable default url handler for example.
6339 *
6340 * @param subId the subscription ID that this action applies to.
6341 * @param report control start/stop reporting the default network status.
6342 * {@hide}
6343 */
6344 @Override
6345 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6346 enforceModifyPermission();
6347 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348
6349 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006350 if (phone == null) {
6351 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6352 return;
6353 }
6354 try {
6355 phone.carrierActionReportDefaultNetworkStatus(report);
6356 } catch (Exception e) {
6357 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 } finally {
6359 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006360 }
6361 }
6362
6363 /**
fionaxud9622282017-07-17 17:51:30 -07006364 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6365 * @param subId the subscription ID that this action applies to.
6366 * {@hide}
6367 */
6368 @Override
6369 public void carrierActionResetAll(int subId) {
6370 enforceModifyPermission();
6371 final Phone phone = getPhone(subId);
6372 if (phone == null) {
6373 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6374 return;
6375 }
6376 try {
6377 phone.carrierActionResetAll();
6378 } catch (Exception e) {
6379 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6380 }
6381 }
6382
6383 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006384 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6385 * bug report is being generated.
6386 */
6387 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006388 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006389 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6390 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006391 writer.println("Permission Denial: can't dump Phone from pid="
6392 + Binder.getCallingPid()
6393 + ", uid=" + Binder.getCallingUid()
6394 + "without permission "
6395 + android.Manifest.permission.DUMP);
6396 return;
6397 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006398 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006399 }
Jack Yueb89b242016-06-22 13:27:47 -07006400
Brad Ebingerdac2f002018-04-03 15:17:52 -07006401 @Override
6402 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6403 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6404 throws RemoteException {
6405 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6406 }
6407
Jack Yueb89b242016-06-22 13:27:47 -07006408 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006409 * Get aggregated video call data usage since boot.
6410 *
6411 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6412 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006413 * {@hide}
6414 */
6415 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006416 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006417 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6418 null);
6419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 final long identity = Binder.clearCallingIdentity();
6421 try {
6422 // NetworkStatsService keeps tracking the active network interface and identity. It
6423 // records the delta with the corresponding network identity.
6424 // We just return the total video call data usage snapshot since boot.
6425 Phone phone = getPhone(subId);
6426 if (phone != null) {
6427 return phone.getVtDataUsage(perUidStats);
6428 }
6429 return null;
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006432 }
Jack Yueb89b242016-06-22 13:27:47 -07006433 }
Jack Yu75ab2952016-07-08 14:29:33 -07006434
6435 /**
6436 * Policy control of data connection. Usually used when data limit is passed.
6437 * @param enabled True if enabling the data, otherwise disabling.
6438 * @param subId Subscription index
6439 * {@hide}
6440 */
6441 @Override
6442 public void setPolicyDataEnabled(boolean enabled, int subId) {
6443 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444
6445 final long identity = Binder.clearCallingIdentity();
6446 try {
6447 Phone phone = getPhone(subId);
6448 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006449 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 }
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006453 }
6454 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006455
6456 /**
6457 * Get Client request stats
6458 * @return List of Client Request Stats
6459 * @hide
6460 */
6461 @Override
6462 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006464 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006465 return null;
6466 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006467 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 final long identity = Binder.clearCallingIdentity();
6470 try {
6471 if (phone != null) {
6472 return phone.getClientRequestStats();
6473 }
6474
6475 return null;
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006479 }
6480
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006481 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006482 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006483 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006484 }
Jack Yueb4124c2017-02-16 15:32:43 -08006485
6486 /**
Grace Chen70990072017-03-24 17:21:30 -07006487 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006488 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006489 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006490 * @param state State of SIM (power down, power up, pass through)
6491 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6492 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6493 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006494 *
6495 **/
6496 @Override
Grace Chen70990072017-03-24 17:21:30 -07006497 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006498 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006499 Phone phone = PhoneFactory.getPhone(slotIndex);
6500
vagdeviaf9a5b92018-08-15 16:01:53 -07006501 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503 final long identity = Binder.clearCallingIdentity();
6504 try {
6505 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006506 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507 }
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006510 }
6511 }
Shuo Qiandd210312017-04-12 22:11:33 +00006512
Tyler Gunn65d45c22017-06-05 11:22:26 -07006513 private boolean isUssdApiAllowed(int subId) {
6514 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006515 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006516 if (configManager == null) {
6517 return false;
6518 }
6519 PersistableBundle pb = configManager.getConfigForSubId(subId);
6520 if (pb == null) {
6521 return false;
6522 }
6523 return pb.getBoolean(
6524 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6525 }
6526
Shuo Qiandd210312017-04-12 22:11:33 +00006527 /**
6528 * Check if phone is in emergency callback mode
6529 * @return true if phone is in emergency callback mode
6530 * @param subId sub id
6531 */
goneil9c5f4872017-12-05 14:07:56 -08006532 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006533 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006534 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006535 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 if (phone != null) {
6540 return phone.isInEcm();
6541 } else {
6542 return false;
6543 }
6544 } finally {
6545 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006546 }
6547 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006548
6549 /**
6550 * Get the current signal strength information for the given subscription.
6551 * Because this information is not updated when the device is in a low power state
6552 * it should not be relied-upon to be current.
6553 * @param subId Subscription index
6554 * @return the most recent cached signal strength info from the modem
6555 */
6556 @Override
6557 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 final long identity = Binder.clearCallingIdentity();
6559 try {
6560 Phone p = getPhone(subId);
6561 if (p == null) {
6562 return null;
6563 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 return p.getSignalStrength();
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006569 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006570
Pengquan Meng77b7f132018-08-22 14:49:57 -07006571 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006572 * Get the current modem radio state for the given slot.
6573 * @param slotIndex slot index.
6574 * @param callingPackage the name of the package making the call.
6575 * @return the current radio power state from the modem
6576 */
6577 @Override
6578 public int getRadioPowerState(int slotIndex, String callingPackage) {
6579 Phone phone = PhoneFactory.getPhone(slotIndex);
6580 if (phone != null) {
6581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6582 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6583 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6584 }
6585
6586 final long identity = Binder.clearCallingIdentity();
6587 try {
6588 return phone.getRadioPowerState();
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
6592 }
6593 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6594 }
6595
6596 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006597 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6598 *
6599 * <p>Requires one of the following permissions:
6600 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6601 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6602 * privileges.
6603 *
6604 * @param subId subscription id
6605 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6606 * {@code false}.
6607 */
6608 @Override
6609 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006610 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6611 null /* message */);
6612
Pengquan Menga1bb6272018-09-06 09:59:22 -07006613 boolean isEnabled = false;
6614 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006615 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006616 Phone phone = getPhone(subId);
6617 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006618 } catch (Exception e) {
6619 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6620 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006621 } finally {
6622 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006624 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006625 }
6626
6627
6628 /**
6629 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6630 *
6631 * <p> Requires permission:
6632 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6633 * privileges.
6634 *
6635 * @param subId subscription id
6636 * @param isEnabled {@code true} means enable, {@code false} means disable.
6637 */
6638 @Override
6639 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6641 mApp, subId, "setDataRoamingEnabled");
6642
Pengquan Menga1bb6272018-09-06 09:59:22 -07006643 final long identity = Binder.clearCallingIdentity();
6644 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006645 Phone phone = getPhone(subId);
6646 if (phone != null) {
6647 phone.setDataRoamingEnabled(isEnabled);
6648 }
6649 } finally {
6650 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006651 }
6652 }
6653
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006654 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006655 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006656 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6657 mApp, subId, "isManualNetworkSelectionAllowed");
6658
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006659 boolean isAllowed = true;
6660 final long identity = Binder.clearCallingIdentity();
6661 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006662 Phone phone = getPhone(subId);
6663 if (phone != null) {
6664 isAllowed = phone.isCspPlmnEnabled();
6665 }
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
6669 return isAllowed;
6670 }
6671
6672 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006673 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006674 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006675 try {
6676 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006677 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006678 } catch (SecurityException e) {
6679 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6680 // has carrier privileges on an active UICC
6681 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6682 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006683 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006684 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006685 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006689 UiccController uiccController = UiccController.getInstance();
6690 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006691 if (hasReadPermission) {
6692 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006693 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006694
6695 // Remove private info if the caller doesn't have access
6696 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6697 for (UiccCardInfo cardInfo : cardInfos) {
6698 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6699 // is available
6700 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6701 if (card == null || card.getUiccProfile() == null) {
6702 // assume no access if the card or profile is unavailable
6703 filteredInfos.add(cardInfo.getUnprivileged());
6704 continue;
6705 }
6706 UiccProfile profile = card.getUiccProfile();
6707 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6708 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6709 filteredInfos.add(cardInfo);
6710 } else {
6711 filteredInfos.add(cardInfo.getUnprivileged());
6712 }
6713 }
6714 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
6718 }
6719
6720 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006721 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006722 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 final long identity = Binder.clearCallingIdentity();
6725 try {
6726 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6727 if (slots == null) {
6728 Rlog.i(LOG_TAG, "slots is null.");
6729 return null;
6730 }
6731
6732 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6733 for (int i = 0; i < slots.length; i++) {
6734 UiccSlot slot = slots[i];
6735 if (slot == null) {
6736 continue;
6737 }
6738
Jordan Liu7be7e652019-05-06 18:55:02 +00006739 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 UiccCard card = slot.getUiccCard();
6741 if (card != null) {
6742 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006743 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006744 cardId = slot.getEid();
6745 if (TextUtils.isEmpty(cardId)) {
6746 cardId = slot.getIccId();
6747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 }
6749
Jordan Liu857451f2019-05-09 16:35:35 -07006750 if (cardId != null) {
6751 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6752 // if cardId is an EID, it's all digits so this is fine
6753 cardId = IccUtils.stripTrailingFs(cardId);
6754 }
6755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 int cardState = 0;
6757 switch (slot.getCardState()) {
6758 case CARDSTATE_ABSENT:
6759 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6760 break;
6761 case CARDSTATE_PRESENT:
6762 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6763 break;
6764 case CARDSTATE_ERROR:
6765 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6766 break;
6767 case CARDSTATE_RESTRICTED:
6768 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6769 break;
6770 default:
6771 break;
6772
6773 }
6774
6775 infos[i] = new UiccSlotInfo(
6776 slot.isActive(),
6777 slot.isEuicc(),
6778 cardId,
6779 cardState,
6780 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006781 slot.isExtendedApduSupported(),
6782 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 }
6784 return infos;
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006787 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006788 }
6789
6790 @Override
6791 public boolean switchSlots(int[] physicalSlots) {
6792 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
6794 final long identity = Binder.clearCallingIdentity();
6795 try {
6796 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006800 }
Jack Yu4c988042018-02-27 15:30:01 -08006801
6802 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006803 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006804 final long identity = Binder.clearCallingIdentity();
6805 try {
6806 return UiccController.getInstance().getCardIdForDefaultEuicc();
6807 } finally {
6808 Binder.restoreCallingIdentity(identity);
6809 }
6810 }
6811
6812 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006813 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6814 enforceModifyPermission();
6815 final Phone phone = getPhone(subId);
6816 if (phone == null) {
6817 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6818 return;
6819 }
6820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 final long identity = Binder.clearCallingIdentity();
6822 try {
6823 phone.setRadioIndicationUpdateMode(filters, mode);
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
6826 }
Jack Yu4c988042018-02-27 15:30:01 -08006827 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006828
6829 /**
goneil47ffb6e2018-04-06 15:40:58 -07006830 * A test API to reload the UICC profile.
6831 *
6832 * <p>Requires that the calling app has permission
6833 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6834 * @hide
6835 */
6836 @Override
6837 public void refreshUiccProfile(int subId) {
6838 enforceModifyPermission();
6839
6840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 Phone phone = getPhone(subId);
6843 if (phone == null) {
6844 return;
6845 }
6846 UiccCard uiccCard = phone.getUiccCard();
6847 if (uiccCard == null) {
6848 return;
6849 }
6850 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6851 if (uiccProfile == null) {
6852 return;
6853 }
6854 uiccProfile.refresh();
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
6858 }
6859
6860 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006861 * Returns false if the mobile data is disabled by default, otherwise return true.
6862 */
6863 private boolean getDefaultDataEnabled() {
6864 return "true".equalsIgnoreCase(
6865 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6866 }
6867
6868 /**
6869 * Returns true if the data roaming is enabled by default, i.e the system property
6870 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6871 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6872 */
6873 private boolean getDefaultDataRoamingEnabled(int subId) {
6874 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006875 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006876 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6877 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6878 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6879 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6880 return isDataRoamingEnabled;
6881 }
6882
6883 /**
6884 * Returns the default network type for the given {@code subId}, if the default network type is
6885 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6886 */
6887 private int getDefaultNetworkType(int subId) {
6888 return Integer.parseInt(
6889 TelephonyManager.getTelephonyProperty(
6890 mSubscriptionController.getPhoneId(subId),
6891 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6892 String.valueOf(Phone.PREFERRED_NT_MODE)));
6893 }
fionaxua13278b2018-03-21 00:08:13 -07006894
6895 @Override
6896 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006897 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
6902 final Phone phone = getPhone(subId);
6903 if (phone == null) {
6904 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6905 return;
6906 }
chen xueaba88a2019-03-15 13:15:10 -07006907 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6908 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 } finally {
6910 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006911 }
fionaxua13278b2018-03-21 00:08:13 -07006912 }
6913
6914 @Override
6915 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006916 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917
6918 final long identity = Binder.clearCallingIdentity();
6919 try {
6920 final Phone phone = getPhone(subId);
6921 if (phone == null) {
6922 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6923 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6924 }
6925 return phone.getCarrierIdListVersion();
6926 } finally {
6927 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006928 }
fionaxua13278b2018-03-21 00:08:13 -07006929 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006930
6931 @Override
6932 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6934 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6935 return -1;
6936 }
6937
6938 final long identity = Binder.clearCallingIdentity();
6939 try {
6940 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
6943 }
6944 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006945
6946 @Override
6947 public int getCdmaRoamingMode(int subId) {
6948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6949 mApp, subId, "getCdmaRoamingMode");
6950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
6953 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
6956 }
6957 }
6958
6959 @Override
6960 public boolean setCdmaRoamingMode(int subId, int mode) {
6961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6962 mApp, subId, "setCdmaRoamingMode");
6963
6964 final long identity = Binder.clearCallingIdentity();
6965 try {
6966 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
6969 }
6970 }
6971
6972 @Override
6973 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6975 mApp, subId, "setCdmaSubscriptionMode");
6976
6977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6980 } finally {
6981 Binder.restoreCallingIdentity(identity);
6982 }
6983 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006984
sqianc5eccab2018-10-19 18:46:41 -07006985 @Override
sqian8c685422019-02-22 15:55:18 -08006986 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006987 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006989 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006990 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6991 }
6992 final long identity = Binder.clearCallingIdentity();
6993 try {
sqian854d44b2018-12-12 16:48:18 -08006994 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6995 for (Phone phone: PhoneFactory.getPhones()) {
6996 if (phone.getEmergencyNumberTracker() != null
6997 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6998 emergencyNumberListInternal.put(
6999 phone.getSubId(),
7000 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7001 }
sqian11b7a0e2018-12-05 18:48:28 -08007002 }
sqian854d44b2018-12-12 16:48:18 -08007003 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
sqianc5eccab2018-10-19 18:46:41 -07007007 }
7008
7009 @Override
sqian8c685422019-02-22 15:55:18 -08007010 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007011 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007012 if (!exactMatch) {
7013 TelephonyPermissions
7014 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007015 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007016 }
7017 final long identity = Binder.clearCallingIdentity();
7018 try {
sqian854d44b2018-12-12 16:48:18 -08007019 for (Phone phone: PhoneFactory.getPhones()) {
7020 if (phone.getEmergencyNumberTracker() != null
7021 && phone.getEmergencyNumberTracker() != null) {
7022 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7023 number, exactMatch)) {
7024 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007025 }
7026 }
sqian11b7a0e2018-12-05 18:48:28 -08007027 }
7028 return false;
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
7032 }
7033
sqianf4ca7ed2019-01-15 18:32:07 -08007034 /**
7035 * Update emergency number list for test mode.
7036 */
7037 @Override
7038 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7040 "updateEmergencyNumberListTestMode");
7041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 for (Phone phone: PhoneFactory.getPhones()) {
7045 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7046 if (tracker != null) {
7047 tracker.executeEmergencyNumberTestModeCommand(action, num);
7048 }
7049 }
7050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
7053 }
7054
7055 /**
7056 * Get the full emergency number list for test mode.
7057 */
7058 @Override
7059 public List<String> getEmergencyNumberListTestMode() {
7060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7061 "getEmergencyNumberListTestMode");
7062
7063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 Set<String> emergencyNumbers = new HashSet<>();
7066 for (Phone phone: PhoneFactory.getPhones()) {
7067 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7068 if (tracker != null) {
7069 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7070 emergencyNumbers.add(num.getNumber());
7071 }
7072 }
7073 }
7074 return new ArrayList<>(emergencyNumbers);
7075 } finally {
7076 Binder.restoreCallingIdentity(identity);
7077 }
7078 }
7079
chen xud6b45bd2018-10-30 22:27:10 -07007080 @Override
7081 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7082 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7083 Phone phone = getPhone(subId);
7084 if (phone == null) {
7085 return null;
7086 }
7087 final long identity = Binder.clearCallingIdentity();
7088 try {
7089 UiccProfile profile = UiccController.getInstance()
7090 .getUiccProfileForPhone(phone.getPhoneId());
7091 if (profile != null) {
7092 return profile.getCertsFromCarrierPrivilegeAccessRules();
7093 }
7094 } finally {
7095 Binder.restoreCallingIdentity(identity);
7096 }
7097 return null;
7098 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007099
7100 /**
7101 * Enable or disable a modem stack.
7102 */
7103 @Override
7104 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7105 enforceModifyPermission();
7106
7107 final long identity = Binder.clearCallingIdentity();
7108 try {
7109 Phone phone = PhoneFactory.getPhone(slotIndex);
7110 if (phone == null) {
7111 return false;
7112 } else {
7113 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7114 }
7115 } finally {
7116 Binder.restoreCallingIdentity(identity);
7117 }
7118 }
Michelecea4cf22018-12-21 15:00:11 -08007119
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007120 /**
7121 * Whether a modem stack is enabled or not.
7122 */
7123 @Override
7124 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7125 Phone phone = PhoneFactory.getPhone(slotIndex);
7126 if (phone == null) return false;
7127
7128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7129 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7130 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7131 }
7132
7133 final long identity = Binder.clearCallingIdentity();
7134 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007135 try {
7136 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7137 } catch (NoSuchElementException ex) {
7138 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7139 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
7143 }
7144
Michelecea4cf22018-12-21 15:00:11 -08007145 @Override
Michele0ea7d782019-03-19 14:58:42 -07007146 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007147 enforceModifyPermission();
7148
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007152 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007153 .commit();
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
7157 }
7158
7159 @Override
Michele0ea7d782019-03-19 14:58:42 -07007160 @TelephonyManager.IsMultiSimSupportedResult
7161 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007163 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7164 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007165 }
Michelecea4cf22018-12-21 15:00:11 -08007166
7167 final long identity = Binder.clearCallingIdentity();
7168 try {
Michele0ea7d782019-03-19 14:58:42 -07007169 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
7173 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007174
Michele0ea7d782019-03-19 14:58:42 -07007175 @TelephonyManager.IsMultiSimSupportedResult
7176 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007177 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7178 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7179 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007180 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7181 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007182 }
7183 // Check if the hardware supports multisim functionality. If usage of multisim is not
7184 // supported by the modem, indicate that it is restricted.
7185 PhoneCapability staticCapability =
7186 mPhoneConfigurationManager.getStaticPhoneCapability();
7187 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007188 loge("isMultiSimSupportedInternal: no static configuration available");
7189 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007190 }
7191 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007192 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7193 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007194 }
7195 // Check if support of multiple SIMs is restricted by carrier
7196 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007197 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007198 }
7199
Michele0ea7d782019-03-19 14:58:42 -07007200 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007201 }
7202
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007203 /**
7204 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007205 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7206 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7207 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007208 * @param numOfSims number of active sims we want to switch to
7209 */
7210 @Override
7211 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007212 if (numOfSims == 1) {
7213 enforceModifyPermission();
7214 } else {
7215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7216 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7217 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007218 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007219
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007220 try {
Michele30b57b22019-03-01 12:01:14 -08007221 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007222 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007223 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7224 return;
7225 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007226 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
7230 }
7231
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007232 @Override
7233 public boolean isApplicationOnUicc(int subId, int appType) {
7234 enforceReadPrivilegedPermission("isApplicationOnUicc");
7235 Phone phone = getPhone(subId);
7236 if (phone == null) {
7237 return false;
7238 }
7239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 UiccCard uiccCard = phone.getUiccCard();
7242 if (uiccCard == null) {
7243 return false;
7244 }
7245 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7246 if (uiccProfile == null) {
7247 return false;
7248 }
7249 if (TelephonyManager.APPTYPE_SIM <= appType
7250 && appType <= TelephonyManager.APPTYPE_ISIM) {
7251 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7252 }
7253 return false;
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 }
7258
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007259 /**
chen xub4baa772019-04-03 10:23:41 -07007260 * Get whether making changes to modem configurations will trigger reboot.
7261 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007262 */
7263 @Override
chen xub4baa772019-04-03 10:23:41 -07007264 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7266 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7267 return false;
7268 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
7274 }
7275 }
7276
Nathan Harold29f5f052019-02-15 13:41:57 -08007277 private void updateModemStateMetrics() {
7278 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7279 // TODO: check the state for each modem if the api is ready.
7280 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7281 }
7282
Pengquan Meng3889a572019-01-23 11:16:29 -08007283 @Override
7284 public int[] getSlotsMapping() {
7285 enforceReadPrivilegedPermission("getSlotsMapping");
7286
7287 final long identity = Binder.clearCallingIdentity();
7288 try {
7289 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7290 // All logical slots should have a mapping to a physical slot.
7291 int[] logicalSlotsMapping = new int[phoneCount];
7292 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7293 for (int i = 0; i < slotInfos.length; i++) {
7294 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7295 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7296 }
7297 }
7298 return logicalSlotsMapping;
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
7302 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007303
7304 /**
7305 * Get the IRadio HAL Version
7306 */
7307 @Override
7308 public int getRadioHalVersion() {
7309 Phone phone = getDefaultPhone();
7310 if (phone == null) return -1;
7311 HalVersion hv = phone.getHalVersion();
7312 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7313 return hv.major * 100 + hv.minor;
7314 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007315
7316 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007317 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7318 * corresponding network requests on a subId.
7319 *
7320 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007321 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007322 * 2) APN is un-metered for this subscription, or
7323 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7324 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7325 *
7326 * @return whether data is allowed for a apn type.
7327 *
7328 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007329 */
7330 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007331 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007332 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7333 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007334
7335 // Now that all security checks passes, perform the operation as ourselves.
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
7338 Phone phone = getPhone(subId);
7339 if (phone == null) return false;
7340
Jack Yu41407ee2019-05-13 16:54:09 -07007341 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007342 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7343 } finally {
7344 Binder.restoreCallingIdentity(identity);
7345 }
7346 }
7347
7348 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007349 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007350 enforceReadPrivilegedPermission("isApnMetered");
7351
7352 // Now that all security checks passes, perform the operation as ourselves.
7353 final long identity = Binder.clearCallingIdentity();
7354 try {
7355 Phone phone = getPhone(subId);
7356 if (phone == null) return true; // By default return true.
7357
Jack Yu41407ee2019-05-13 16:54:09 -07007358 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007359 } finally {
7360 Binder.restoreCallingIdentity(identity);
7361 }
7362 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007363
7364 @Override
7365 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7366 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7367 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7368 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7369 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7370 }
7371 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7372 Intent intent = new Intent();
7373 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7374 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7375 // Bring up choose default SMS subscription dialog right now
7376 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7377 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7378 mApp.startActivity(intent);
7379 }
chen xud5ca2d52019-05-28 15:20:57 -07007380
7381 @Override
7382 public String getMmsUAProfUrl(int subId) {
7383 //TODO investigate if this API should require proper permission check in R b/133791609
7384 final long identity = Binder.clearCallingIdentity();
7385 try {
7386 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7387 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7388 } finally {
7389 Binder.restoreCallingIdentity(identity);
7390 }
7391 }
7392
7393 @Override
7394 public String getMmsUserAgent(int subId) {
7395 //TODO investigate if this API should require proper permission check in R b/133791609
7396 final long identity = Binder.clearCallingIdentity();
7397 try {
7398 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7399 .getString(com.android.internal.R.string.config_mms_user_agent);
7400 } finally {
7401 Binder.restoreCallingIdentity(identity);
7402 }
7403 }
Jack Yub07d4972019-05-28 16:12:25 -07007404
7405 @Override
7406 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7407 enforceModifyPermission();
7408
7409 // Now that all security checks passes, perform the operation as ourselves.
7410 final long identity = Binder.clearCallingIdentity();
7411 try {
7412 Phone phone = getPhone(subId);
7413 if (phone == null) return false;
7414
7415 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7416 } finally {
7417 Binder.restoreCallingIdentity(identity);
7418 }
7419 }
7420
7421 @Override
7422 public boolean isDataAllowedInVoiceCall(int subId) {
7423 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7424
7425 // Now that all security checks passes, perform the operation as ourselves.
7426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 Phone phone = getPhone(subId);
7429 if (phone == null) return false;
7430
7431 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7432 } finally {
7433 Binder.restoreCallingIdentity(identity);
7434 }
7435 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007436
7437 /**
7438 * Updates whether conference event pacakge handling is enabled.
7439 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7440 * otherwise.
7441 */
7442 @Override
7443 public void setCepEnabled(boolean isCepEnabled) {
7444 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7445
7446 final long identity = Binder.clearCallingIdentity();
7447 try {
7448 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7449 for (Phone phone : PhoneFactory.getPhones()) {
7450 Phone defaultPhone = phone.getImsPhone();
7451 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7452 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7453 ImsPhoneCallTracker imsPhoneCallTracker =
7454 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7455 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7456 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7457 + imsPhone.getMsisdn());
7458 }
7459 }
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
7463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007464}