blob: 9a31be60c2d112e0f5175c889e8befa445611290 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080070import android.telephony.CellIdentityCdma;
71import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070073import android.telephony.CellInfoGsm;
74import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070086import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
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 Ebinger774ba362019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800117import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700123import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700124import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800125import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700126import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800129import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700130import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800131import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800133import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.LocaleTracker;
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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900157import 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;
zoey chen84e2b212019-12-18 17:07:20 +0800166import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700167import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800171import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700173import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800174
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700175import java.io.FileDescriptor;
176import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800179import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800181import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100182import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700184import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187/**
188 * Implementation of the ITelephony interface.
189 */
Santos Cordon117fee72014-05-16 17:56:12 -0700190public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private static final String LOG_TAG = "PhoneInterfaceManager";
192 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
193 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196 // Message codes used with mMainThreadHandler
197 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700198 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
199 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200 private static final int CMD_OPEN_CHANNEL = 9;
201 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
202 private static final int CMD_CLOSE_CHANNEL = 11;
203 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800204 private static final int CMD_NV_READ_ITEM = 13;
205 private static final int EVENT_NV_READ_ITEM_DONE = 14;
206 private static final int CMD_NV_WRITE_ITEM = 15;
207 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
208 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
209 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700210 private static final int CMD_RESET_MODEM_CONFIG = 19;
211 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800212 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
213 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
214 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
215 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800216 private static final int CMD_SEND_ENVELOPE = 25;
217 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000218 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
219 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700220 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
221 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
222 private static final int CMD_EXCHANGE_SIM_IO = 31;
223 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800224 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
225 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700226 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700228 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
229 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700230 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
231 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
232 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
233 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700234 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
235 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
236 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
237 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700238 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
240 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000241 private static final int CMD_SWITCH_SLOTS = 50;
242 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700243 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
244 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
245 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
246 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
247 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
248 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
249 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
250 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700251 private static final int CMD_GET_ALL_CELL_INFO = 60;
252 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
253 private static final int CMD_GET_CELL_LOCATION = 62;
254 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700255 private static final int CMD_MODEM_REBOOT = 64;
256 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700257 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
258 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800259 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
260 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700261 private static final int CMD_GET_MODEM_STATUS = 70;
262 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700263 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
264 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700265 private static final int CMD_ERASE_MODEM_CONFIG = 74;
266 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800268 // Parameters of select command.
269 private static final int SELECT_COMMAND = 0xA4;
270 private static final int SELECT_P1 = 0x04;
271 private static final int SELECT_P2 = 0;
272 private static final int SELECT_P3 = 0x10;
273
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 /** The singleton instance. */
275 private static PhoneInterfaceManager sInstance;
276
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800279 private ImsResolver mImsResolver;
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 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700304 * Experiment flag to enable erase modem config on reset network, default value is false
305 */
306 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
307 "reset_network_erase_modem_config_enabled";
308
309 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700310 * A request object to use for transmitting data to an ICC.
311 */
312 private static final class IccAPDUArgument {
313 public int channel, cla, command, p1, p2, p3;
314 public String data;
315
316 public IccAPDUArgument(int channel, int cla, int command,
317 int p1, int p2, int p3, String data) {
318 this.channel = channel;
319 this.cla = cla;
320 this.command = command;
321 this.p1 = p1;
322 this.p2 = p2;
323 this.p3 = p3;
324 this.data = data;
325 }
326 }
327
328 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700329 * A request object to use for transmitting data to an ICC.
330 */
331 private static final class ManualNetworkSelectionArgument {
332 public OperatorInfo operatorInfo;
333 public boolean persistSelection;
334
335 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
336 this.operatorInfo = operatorInfo;
337 this.persistSelection = persistSelection;
338 }
339 }
340
341 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
343 * request after sending. The main thread will notify the request when it is complete.
344 */
345 private static final class MainThreadRequest {
346 /** The argument to use for the request */
347 public Object argument;
348 /** The result of the request that is run on the main thread */
349 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 // The subscriber id that this request applies to. Defaults to
351 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
352 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 // In cases where subId is unavailable, the caller needs to specify the phone.
355 public Phone phone;
356
vagdeviaf9a5b92018-08-15 16:01:53 -0700357 public WorkSource workSource;
358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 public MainThreadRequest(Object argument) {
360 this.argument = argument;
361 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362
Nathan Harold92bed182018-10-12 18:16:49 -0700363 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
364 this.argument = argument;
365 if (phone != null) {
366 this.phone = phone;
367 }
368 this.workSource = workSource;
369 }
370
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 if (subId != null) {
374 this.subId = subId;
375 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800380 private static final class IncomingThirdPartyCallArgs {
381 public final ComponentName component;
382 public final String callId;
383 public final String callerDisplayName;
384
385 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
386 String callerDisplayName) {
387 this.component = component;
388 this.callId = callId;
389 this.callerDisplayName = callerDisplayName;
390 }
391 }
392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 /**
394 * A handler that processes messages on the main thread in the phone process. Since many
395 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
396 * inbound binder threads to the main thread in the phone process. The Binder thread
397 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
398 * on, which will be notified when the operation completes and will contain the result of the
399 * request.
400 *
401 * <p>If a MainThreadRequest object is provided in the msg.obj field,
402 * note that request.result must be set to something non-null for the calling thread to
403 * unblock.
404 */
405 private final class MainThreadHandler extends Handler {
406 @Override
407 public void handleMessage(Message msg) {
408 MainThreadRequest request;
409 Message onCompleted;
410 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800411 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800413 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
415 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 case CMD_HANDLE_USSD_REQUEST: {
417 request = (MainThreadRequest) msg.obj;
418 final Phone phone = getPhoneFromRequest(request);
419 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
420 String ussdRequest = ussdObject.first;
421 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 if (!isUssdApiAllowed(request.subId)) {
424 // Carrier does not support use of this API, return failure.
425 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
426 UssdResponse response = new UssdResponse(ussdRequest, null);
427 Bundle returnData = new Bundle();
428 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
429 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 request.result = true;
432 notifyRequester(request);
433 return;
434 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700435
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 try {
437 request.result = phone != null
438 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
439 } catch (CallStateException cse) {
440 request.result = false;
441 }
442 // Wake up the requesting thread
443 notifyRequester(request);
444 break;
pkanwar32d516d2016-10-14 19:37:38 -0700445 }
446
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 final Phone phone = getPhoneFromRequest(request);
450 request.result = phone != null ?
451 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
452 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduLogicalChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
468 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 iccArgument.channel, iccArgument.cla, iccArgument.command,
471 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 break;
475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 if (ar.result == null) {
484 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800485 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800487 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 } else {
489 loge("iccTransmitApduLogicalChannel: Unknown exception");
490 }
491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 break;
494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccTransmitApduBasicChannel: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
505 request);
506 uiccCard.iccTransmitApduBasicChannel(
507 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
508 iccArgument.p3, iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 if (ar.result == null) {
520 loge("iccTransmitApduBasicChannel: Empty response");
521 } else if (ar.exception instanceof CommandException) {
522 loge("iccTransmitApduBasicChannel: CommandException: " +
523 ar.exception);
524 } else {
525 loge("iccTransmitApduBasicChannel: Unknown exception");
526 }
527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 break;
530
531 case CMD_EXCHANGE_SIM_IO:
532 request = (MainThreadRequest) msg.obj;
533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 if (uiccCard == null) {
536 loge("iccExchangeSimIO: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
541 request);
542 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
543 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
544 iccArgument.data, onCompleted);
545 }
546 break;
547
548 case EVENT_EXCHANGE_SIM_IO_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6f, 0, (byte[])null);
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 case CMD_SEND_ENVELOPE:
560 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 if (uiccCard == null) {
563 loge("sendEnvelopeWithStatus: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
568 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 break;
571
572 case EVENT_SEND_ENVELOPE_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("sendEnvelopeWithStatus: Empty response");
581 } else if (ar.exception instanceof CommandException) {
582 loge("sendEnvelopeWithStatus: CommandException: " +
583 ar.exception);
584 } else {
585 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 break;
590
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 case CMD_OPEN_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800594 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800597 request.result = new IccOpenLogicalChannelResponse(-1,
598 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800602 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
603 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_OPEN_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 int[] result = (int[]) ar.result;
613 int channelId = result[0];
614 byte[] selectResponse = null;
615 if (result.length > 1) {
616 selectResponse = new byte[result.length - 1];
617 for (int i = 1; i < result.length; ++i) {
618 selectResponse[i - 1] = (byte) result[i];
619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 if (ar.result == null) {
625 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 if (ar.exception != null) {
628 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
629 }
630
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700632 if (ar.exception instanceof CommandException) {
633 CommandException.Error error =
634 ((CommandException) (ar.exception)).getCommandError();
635 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700636 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700637 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(
642 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700644 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case CMD_CLOSE_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900653 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
657 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
661 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800662 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
663 break;
664
665 case CMD_NV_READ_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800668 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
669 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 request.result = "";
679 if (ar.result == null) {
680 loge("nvReadItem: Empty response");
681 } else if (ar.exception instanceof CommandException) {
682 loge("nvReadItem: CommandException: " +
683 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800685 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
Jake Hambye994d462014-02-03 13:10:13 -0800691 case CMD_NV_WRITE_ITEM:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
694 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700696 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_ITEM_DONE:
700 handleNullReturnEvent(msg, "nvWriteItem");
701 break;
702
703 case CMD_NV_WRITE_CDMA_PRL:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
709 case EVENT_NV_WRITE_CDMA_PRL_DONE:
710 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800714 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700715 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800716 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
chen xu6dac5ab2018-10-26 17:39:23 -0700719 case EVENT_RESET_MODEM_CONFIG_DONE:
720 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 case CMD_GET_PREFERRED_NETWORK_TYPE:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // Integer
734 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800735 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 if (ar.result == null) {
737 loge("getPreferredNetworkType: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("getPreferredNetworkType: CommandException: " +
740 ar.exception);
741 } else {
742 loge("getPreferredNetworkType: Unknown exception");
743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000770 break;
771
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 case CMD_SET_VOICEMAIL_NUMBER:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
775 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800776 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
777 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800778 break;
779
780 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
781 handleNullReturnEvent(msg, "setVoicemailNumber");
782 break;
783
Stuart Scott54788802015-03-30 13:18:01 -0700784 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
787 request);
788 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
789 break;
790
791 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
792 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
793 break;
794
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 case CMD_PERFORM_NETWORK_SCAN:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
798 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
799 break;
800
801 case EVENT_PERFORM_NETWORK_SCAN_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 CellNetworkScanResult cellScanResult;
805 if (ar.exception == null && ar.result != null) {
806 cellScanResult = new CellNetworkScanResult(
807 CellNetworkScanResult.STATUS_SUCCESS,
808 (List<OperatorInfo>) ar.result);
809 } else {
810 if (ar.result == null) {
811 loge("getCellNetworkScanResults: Empty response");
812 }
813 if (ar.exception != null) {
814 loge("getCellNetworkScanResults: Exception: " + ar.exception);
815 }
816 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
817 if (ar.exception instanceof CommandException) {
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
820 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
821 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
822 } else if (error == CommandException.Error.GENERIC_FAILURE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
824 }
825 }
826 cellScanResult = new CellNetworkScanResult(errorCode, null);
827 }
828 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700829 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
833 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 ManualNetworkSelectionArgument selArg =
835 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
837 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
839 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
842 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null) {
846 request.result = true;
847 } else {
848 request.result = false;
849 loge("setNetworkSelectionModeManual " + ar.exception);
850 }
851 notifyRequester(request);
852 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700853 break;
854
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 case CMD_GET_MODEM_ACTIVITY_INFO:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700858 if (defaultPhone != null) {
859 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
863 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
869 if (ar.result == null) {
870 loge("queryModemActivityInfo: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("queryModemActivityInfo: CommandException: " +
873 ar.exception);
874 } else {
875 loge("queryModemActivityInfo: Unknown exception");
876 }
877 }
Amit Mahajand4766222016-01-28 15:28:28 -0800878 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
879 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700880 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700883 break;
884
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 case CMD_SET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800887 CarrierRestrictionRules argument =
888 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800890 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_SET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800899 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
900 if (ar.exception instanceof CommandException) {
901 loge("setAllowedCarriers: CommandException: " + ar.exception);
902 CommandException.Error error =
903 ((CommandException) (ar.exception)).getCommandError();
904 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
905 request.result =
906 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 } else {
909 loge("setAllowedCarriers: Unknown exception");
910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case CMD_GET_ALLOWED_CARRIERS:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800918 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
921 case EVENT_GET_ALLOWED_CARRIERS_DONE:
922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result;
926 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800927 request.result = new IllegalStateException(
928 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 if (ar.result == null) {
930 loge("getAllowedCarriers: Empty response");
931 } else if (ar.exception instanceof CommandException) {
932 loge("getAllowedCarriers: CommandException: " +
933 ar.exception);
934 } else {
935 loge("getAllowedCarriers: Unknown exception");
936 }
937 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
947 request.result = new IllegalArgumentException(
948 "Failed to retrieve Forbidden Plmns");
949 if (ar.result == null) {
950 loge("getForbiddenPlmns: Empty response");
951 } else {
952 loge("getForbiddenPlmns: Unknown exception");
953 }
954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 }
968 Integer appType = (Integer) request.argument;
969 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
970 if (uiccApp == null) {
971 loge("getForbiddenPlmns() no app with specified type -- "
972 + appType);
973 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700974 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700996 notifyRequester(request);
997 break;
998 case CMD_GET_NETWORK_SELECTION_MODE:
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1001 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1002 break;
1003
1004 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception != null) {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1009 } else {
1010 int mode = ((int[]) ar.result)[0];
1011 if (mode == 0) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1013 } else {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001017 notifyRequester(request);
1018 break;
1019 case CMD_GET_CDMA_ROAMING_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1022 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1023 break;
1024 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1029 } else {
1030 request.result = ((int[]) ar.result)[0];
1031 }
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_ROAMING_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1037 int mode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
1045 break;
1046 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1049 int subscriptionMode = (int) request.argument;
1050 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1051 break;
1052 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 request.result = ar.exception == null;
1056 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case CMD_GET_ALL_CELL_INFO:
1059 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001061 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 case EVENT_GET_ALL_CELL_INFO_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001066 // If a timeout occurs, the response will be null
1067 request.result = (ar.exception == null && ar.result != null)
1068 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 synchronized (request) {
1070 request.notifyAll();
1071 }
1072 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 case CMD_REQUEST_CELL_INFO_UPDATE:
1074 request = (MainThreadRequest) msg.obj;
1075 request.phone.requestCellInfoUpdate(request.workSource,
1076 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1077 break;
1078 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1082 try {
1083 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001085 cb.onError(
1086 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1087 ar.exception.getClass().getName(),
1088 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001091 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else {
1093 // use the result as returned
1094 cb.onCellInfo((List<CellInfo>) ar.result);
1095 }
1096 } catch (RemoteException re) {
1097 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1098 }
1099 break;
1100 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 request = (MainThreadRequest) msg.obj;
1102 WorkSource ws = (WorkSource) request.argument;
1103 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001104 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null) {
1110 request.result = ar.result;
1111 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001114 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001115 }
1116
1117 synchronized (request) {
1118 request.notifyAll();
1119 }
1120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case CMD_MODEM_REBOOT:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001124 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001125 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001126 case EVENT_CMD_MODEM_REBOOT_DONE:
1127 handleNullReturnEvent(msg, "rebootModem");
1128 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 case CMD_REQUEST_ENABLE_MODEM:
1130 request = (MainThreadRequest) msg.obj;
1131 boolean enable = (boolean) request.argument;
1132 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001134 PhoneConfigurationManager.getInstance()
1135 .enablePhone(request.phone, enable, onCompleted);
1136 break;
1137 case EVENT_ENABLE_MODEM_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001141 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001142 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 if ((boolean) request.result) {
1144 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1145 updateModemStateMetrics();
1146 } else {
1147 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1148 + ar.exception);
1149 }
1150 notifyRequester(request);
1151 break;
1152 case CMD_GET_MODEM_STATUS:
1153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1155 PhoneConfigurationManager.getInstance()
1156 .getPhoneStatusFromModem(request.phone, onCompleted);
1157 break;
1158 case EVENT_GET_MODEM_STATUS_DONE:
1159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 int id = request.phone.getPhoneId();
1162 if (ar.exception == null && ar.result != null) {
1163 request.result = ar.result;
1164 //update the cache as modem status has changed
1165 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1166 (boolean) request.result);
1167 } else {
1168 // Return true if modem status cannot be retrieved. For most cases,
1169 // modem status is on. And for older version modems, GET_MODEM_STATUS
1170 // and disable modem are not supported. Modem is always on.
1171 // TODO: this should be fixed in R to support a third
1172 // status UNKNOWN b/131631629
1173 request.result = true;
1174 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1175 + ar.exception);
1176 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001177 notifyRequester(request);
1178 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001179 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 } else {
1185 request.result = -1;
1186 loge("Failed to set Forbidden Plmns");
1187 if (ar.result == null) {
1188 loge("setForbidenPlmns: Empty response");
1189 } else if (ar.exception != null) {
1190 loge("setForbiddenPlmns: Exception: " + ar.exception);
1191 request.result = -1;
1192 } else {
1193 loge("setForbiddenPlmns: Unknown exception");
1194 }
1195 }
1196 notifyRequester(request);
1197 break;
1198 case CMD_SET_FORBIDDEN_PLMNS:
1199 request = (MainThreadRequest) msg.obj;
1200 uiccCard = getUiccCardFromRequest(request);
1201 if (uiccCard == null) {
1202 loge("setForbiddenPlmns: UiccCard is null");
1203 request.result = -1;
1204 notifyRequester(request);
1205 break;
1206 }
1207 Pair<Integer, List<String>> setFplmnsArgs =
1208 (Pair<Integer, List<String>>) request.argument;
1209 appType = setFplmnsArgs.first;
1210 List<String> fplmns = setFplmnsArgs.second;
1211 uiccApp = uiccCard.getApplicationByType(appType);
1212 if (uiccApp == null) {
1213 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1214 request.result = -1;
1215 loge("Failed to get UICC App");
1216 notifyRequester(request);
1217 } else {
1218 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1219 ((SIMRecords) uiccApp.getIccRecords())
1220 .setForbiddenPlmns(onCompleted, fplmns);
1221 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001222 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001223 case CMD_ERASE_MODEM_CONFIG:
1224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1226 defaultPhone.eraseModemConfig(onCompleted);
1227 break;
1228 case EVENT_ERASE_MODEM_CONFIG_DONE:
1229 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001230 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 default:
1232 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1233 break;
1234 }
1235 }
Jake Hambye994d462014-02-03 13:10:13 -08001236
Pengquan Menga1bb6272018-09-06 09:59:22 -07001237 private void notifyRequester(MainThreadRequest request) {
1238 synchronized (request) {
1239 request.notifyAll();
1240 }
1241 }
1242
Jake Hambye994d462014-02-03 13:10:13 -08001243 private void handleNullReturnEvent(Message msg, String command) {
1244 AsyncResult ar = (AsyncResult) msg.obj;
1245 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1246 if (ar.exception == null) {
1247 request.result = true;
1248 } else {
1249 request.result = false;
1250 if (ar.exception instanceof CommandException) {
1251 loge(command + ": CommandException: " + ar.exception);
1252 } else {
1253 loge(command + ": Unknown exception");
1254 }
1255 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001256 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
1260 /**
1261 * Posts the specified command to be executed on the main thread,
1262 * waits for the request to complete, and returns the result.
1263 * @see #sendRequestAsync
1264 */
1265 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001266 return sendRequest(
1267 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001268 }
1269
1270 /**
1271 * Posts the specified command to be executed on the main thread,
1272 * waits for the request to complete, and returns the result.
1273 * @see #sendRequestAsync
1274 */
1275 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1276 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001277 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
1280 /**
1281 * Posts the specified command to be executed on the main thread,
1282 * waits for the request to complete, and returns the result.
1283 * @see #sendRequestAsync
1284 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001285 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001286 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001287 }
1288
1289 /**
1290 * Posts the specified command to be executed on the main thread,
1291 * waits for the request to complete, and returns the result.
1292 * @see #sendRequestAsync
1293 */
Nathan Harold92bed182018-10-12 18:16:49 -07001294 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1295 return sendRequest(command, argument, subId, null, workSource);
1296 }
1297
1298 /**
1299 * Posts the specified command to be executed on the main thread,
1300 * waits for the request to complete, and returns the result.
1301 * @see #sendRequestAsync
1302 */
1303 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1304 return sendRequest(
1305 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1306 }
1307
1308 /**
1309 * Posts the specified command to be executed on the main thread,
1310 * waits for the request to complete, and returns the result.
1311 * @see #sendRequestAsync
1312 */
1313 private Object sendRequest(
1314 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1316 throw new RuntimeException("This method will deadlock if called from the main thread.");
1317 }
1318
Nathan Harold92bed182018-10-12 18:16:49 -07001319 MainThreadRequest request = null;
1320 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1321 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1322 } else if (phone != null) {
1323 request = new MainThreadRequest(argument, phone, workSource);
1324 } else {
1325 request = new MainThreadRequest(argument, subId, workSource);
1326 }
1327
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 Message msg = mMainThreadHandler.obtainMessage(command, request);
1329 msg.sendToTarget();
1330
1331 // Wait for the request to complete
1332 synchronized (request) {
1333 while (request.result == null) {
1334 try {
1335 request.wait();
1336 } catch (InterruptedException e) {
1337 // Do nothing, go back and wait until the request is complete
1338 }
1339 }
1340 }
1341 return request.result;
1342 }
1343
1344 /**
1345 * Asynchronous ("fire and forget") version of sendRequest():
1346 * Posts the specified command to be executed on the main thread, and
1347 * returns immediately.
1348 * @see #sendRequest
1349 */
1350 private void sendRequestAsync(int command) {
1351 mMainThreadHandler.sendEmptyMessage(command);
1352 }
1353
1354 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001355 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001356 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 */
1358 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 sendRequestAsync(command, argument, null, null);
1360 }
1361
1362 /**
1363 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1364 * @see {@link #sendRequest(int,Object)}
1365 */
1366 private void sendRequestAsync(
1367 int command, Object argument, Phone phone, WorkSource workSource) {
1368 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001369 Message msg = mMainThreadHandler.obtainMessage(command, request);
1370 msg.sendToTarget();
1371 }
1372
1373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 * Initialize the singleton PhoneInterfaceManager instance.
1375 * This is only done once, at startup, from PhoneApp.onCreate().
1376 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001377 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 synchronized (PhoneInterfaceManager.class) {
1379 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 } else {
1382 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1383 }
1384 return sInstance;
1385 }
1386 }
1387
1388 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001392 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001393 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1395 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001396 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001397 mTelephonySharedPreferences =
1398 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001399 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001400 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 publish();
1403 }
1404
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001405 private Phone getDefaultPhone() {
1406 Phone thePhone = getPhone(getDefaultSubscription());
1407 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1408 }
1409
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 private void publish() {
1411 if (DBG) log("publish: " + this);
1412
1413 ServiceManager.addService("phone", this);
1414 }
1415
Stuart Scott584921c2015-01-15 17:10:34 -08001416 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001417 if (request.phone != null) {
1418 return request.phone;
1419 } else {
1420 return getPhoneFromSubId(request.subId);
1421 }
1422 }
1423
1424 private Phone getPhoneFromSubId(int subId) {
1425 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1426 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001427 }
1428
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001429 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1430 Phone phone = getPhoneFromRequest(request);
1431 return phone == null ? null :
1432 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1433 }
1434
Wink Saville36469e72014-06-11 15:17:00 -07001435 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001436 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001437 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001440 private void sendEraseModemConfig(Phone phone) {
1441 if (phone != null) {
1442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1443 mApp, phone.getSubId(), "eraseModemConfig");
1444 final long identity = Binder.clearCallingIdentity();
1445 try {
1446 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1447 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
1450 }
1451 }
1452 }
1453
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 if (DBG) log("dial: " + number);
1460 // No permission check needed here: This is just a wrapper around the
1461 // ACTION_DIAL intent, which is available to any app since it puts up
1462 // the UI before it does anything.
1463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001464 final long identity = Binder.clearCallingIdentity();
1465 try {
1466 String url = createTelUrl(number);
1467 if (url == null) {
1468 return;
1469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001471 // PENDING: should we just silently fail if phone is offhook or ringing?
1472 PhoneConstants.State state = mCM.getState(subId);
1473 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1474 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1475 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1476 mApp.startActivity(intent);
1477 }
1478 } finally {
1479 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481 }
1482
1483 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001485 }
1486
Wink Savilleb564aae2014-10-23 10:18:09 -07001487 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 if (DBG) log("call: " + number);
1489
1490 // This is just a wrapper around the ACTION_CALL intent, but we still
1491 // need to do a permission check since we're calling startActivity()
1492 // from the context of the phone app.
1493 enforceCallPermission();
1494
Jordan Liu1617b712019-07-10 15:06:26 -07001495 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 != AppOpsManager.MODE_ALLOWED) {
1497 return;
1498 }
1499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001500 final long identity = Binder.clearCallingIdentity();
1501 try {
1502 String url = createTelUrl(number);
1503 if (url == null) {
1504 return;
1505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001507 boolean isValid = false;
1508 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1509 if (slist != null) {
1510 for (SubscriptionInfo subInfoRecord : slist) {
1511 if (subInfoRecord.getSubscriptionId() == subId) {
1512 isValid = true;
1513 break;
1514 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001515 }
Wink Saville08874612014-08-31 19:19:58 -07001516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001517 if (!isValid) {
1518 return;
1519 }
Wink Saville08874612014-08-31 19:19:58 -07001520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001521 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1522 intent.putExtra(SUBSCRIPTION_KEY, subId);
1523 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1524 mApp.startActivity(intent);
1525 } finally {
1526 Binder.restoreCallingIdentity(identity);
1527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 }
1529
Wink Savilleb564aae2014-10-23 10:18:09 -07001530 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001531 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001532 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001537 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1538 }
1539
Wink Savilleb564aae2014-10-23 10:18:09 -07001540 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001542
1543 final long identity = Binder.clearCallingIdentity();
1544 try {
1545 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1546 checkSimPin.start();
1547 return checkSimPin.unlockSim(null, pin);
1548 } finally {
1549 Binder.restoreCallingIdentity(identity);
1550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001555
1556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1559 checkSimPuk.start();
1560 return checkSimPuk.unlockSim(puk, pin);
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
1566 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001567 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 * a synchronous one.
1569 */
1570 private static class UnlockSim extends Thread {
1571
1572 private final IccCard mSimCard;
1573
1574 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001575 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1576 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577
1578 // For replies from SimCard interface
1579 private Handler mHandler;
1580
1581 // For async handler to identify request type
1582 private static final int SUPPLY_PIN_COMPLETE = 100;
1583
1584 public UnlockSim(IccCard simCard) {
1585 mSimCard = simCard;
1586 }
1587
1588 @Override
1589 public void run() {
1590 Looper.prepare();
1591 synchronized (UnlockSim.this) {
1592 mHandler = new Handler() {
1593 @Override
1594 public void handleMessage(Message msg) {
1595 AsyncResult ar = (AsyncResult) msg.obj;
1596 switch (msg.what) {
1597 case SUPPLY_PIN_COMPLETE:
1598 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1599 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001600 mRetryCount = msg.arg1;
1601 if (ar.exception != null) {
1602 if (ar.exception instanceof CommandException &&
1603 ((CommandException)(ar.exception)).getCommandError()
1604 == CommandException.Error.PASSWORD_INCORRECT) {
1605 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1606 } else {
1607 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1608 }
1609 } else {
1610 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 mDone = true;
1613 UnlockSim.this.notifyAll();
1614 }
1615 break;
1616 }
1617 }
1618 };
1619 UnlockSim.this.notifyAll();
1620 }
1621 Looper.loop();
1622 }
1623
1624 /*
1625 * Use PIN or PUK to unlock SIM card
1626 *
1627 * If PUK is null, unlock SIM card with PIN
1628 *
1629 * If PUK is not null, unlock SIM card with PUK and set PIN code
1630 */
Wink Saville9de0f752013-10-22 19:04:03 -07001631 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632
1633 while (mHandler == null) {
1634 try {
1635 wait();
1636 } catch (InterruptedException e) {
1637 Thread.currentThread().interrupt();
1638 }
1639 }
1640 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1641
1642 if (puk == null) {
1643 mSimCard.supplyPin(pin, callback);
1644 } else {
1645 mSimCard.supplyPuk(puk, pin, callback);
1646 }
1647
1648 while (!mDone) {
1649 try {
1650 Log.d(LOG_TAG, "wait for done");
1651 wait();
1652 } catch (InterruptedException e) {
1653 // Restore the interrupted status
1654 Thread.currentThread().interrupt();
1655 }
1656 }
1657 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001658 int[] resultArray = new int[2];
1659 resultArray[0] = mResult;
1660 resultArray[1] = mRetryCount;
1661 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 }
1663 }
1664
1665 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001666 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001667
1668 }
1669
Wink Savilleb564aae2014-10-23 10:18:09 -07001670 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 // No permission check needed here: this call is harmless, and it's
1672 // needed for the ServiceState.requestStateUpdate() call (which is
1673 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001674 final long identity = Binder.clearCallingIdentity();
1675 try {
1676 final Phone phone = getPhone(subId);
1677 if (phone != null) {
1678 phone.updateServiceLocation();
1679 }
1680 } finally {
1681 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001685 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001686 @Override
1687 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001688 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001689 }
1690
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001691 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001692 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1693 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1694 callingFeatureId);
1695 }
1696
1697 @Deprecated
1698 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001699 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001700 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1701 }
1702
1703 @Override
1704 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1705 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001707 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001708 return false;
1709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710
1711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 return isRadioOnForSubscriber(subId);
1714 } finally {
1715 Binder.restoreCallingIdentity(identity);
1716 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001717 }
1718
1719 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001720 final long identity = Binder.clearCallingIdentity();
1721 try {
1722 final Phone phone = getPhone(subId);
1723 if (phone != null) {
1724 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1725 } else {
1726 return false;
1727 }
1728 } finally {
1729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001730 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 }
1732
1733 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001734 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
Wink Saville36469e72014-06-11 15:17:00 -07001736
Wink Savilleb564aae2014-10-23 10:18:09 -07001737 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739
1740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 final Phone phone = getPhone(subId);
1743 if (phone != null) {
1744 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Wink Saville36469e72014-06-11 15:17:00 -07001749 }
1750
1751 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001752 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001753 }
1754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone == null) {
1762 return false;
1763 }
1764 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1765 toggleRadioOnOffForSubscriber(subId);
1766 }
1767 return true;
1768 } finally {
1769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
Wink Saville36469e72014-06-11 15:17:00 -07001772
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001773 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001774 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001775 /*
1776 * If any of the Radios are available, it will need to be
1777 * shutdown. So return true if any Radio is available.
1778 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 final long identity = Binder.clearCallingIdentity();
1780 try {
1781 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1782 Phone phone = PhoneFactory.getPhone(i);
1783 if (phone != null && phone.isRadioAvailable()) return true;
1784 }
1785 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1786 return false;
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001789 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001790 }
1791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001792 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001794 enforceModifyPermission();
1795
1796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1799 logv("Shutting down Phone " + i);
1800 shutdownRadioUsingPhoneId(i);
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001804 }
1805 }
1806
1807 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001808 Phone phone = PhoneFactory.getPhone(phoneId);
1809 if (phone != null && phone.isRadioAvailable()) {
1810 phone.shutdownRadio();
1811 }
1812 }
1813
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001815 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001816
1817 final long identity = Binder.clearCallingIdentity();
1818 try {
1819 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1820 if (defaultPhone != null) {
1821 defaultPhone.setRadioPower(turnOn);
1822 return true;
1823 } else {
1824 loge("There's no default phone.");
1825 return false;
1826 }
1827 } finally {
1828 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001829 }
Wink Saville36469e72014-06-11 15:17:00 -07001830 }
1831
Wink Savilleb564aae2014-10-23 10:18:09 -07001832 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone phone = getPhone(subId);
1838 if (phone != null) {
1839 phone.setRadioPower(turnOn);
1840 return true;
1841 } else {
1842 return false;
1843 }
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 }
1848
Wink Saville36469e72014-06-11 15:17:00 -07001849 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001850 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 public boolean enableDataConnectivity() {
1852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001853
1854 final long identity = Binder.clearCallingIdentity();
1855 try {
1856 int subId = mSubscriptionController.getDefaultDataSubId();
1857 final Phone phone = getPhone(subId);
1858 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001859 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860 return true;
1861 } else {
1862 return false;
1863 }
1864 } finally {
1865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 }
1868
Wink Saville36469e72014-06-11 15:17:00 -07001869 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 public boolean disableDataConnectivity() {
1872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001873
1874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 int subId = mSubscriptionController.getDefaultDataSubId();
1877 final Phone phone = getPhone(subId);
1878 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001879 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 return true;
1881 } else {
1882 return false;
1883 }
1884 } finally {
1885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001890 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 final Phone phone = getPhone(subId);
1894 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001895 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896 } else {
1897 return false;
1898 }
1899 } finally {
1900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001905 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001906 }
1907
pkanwarae03a6b2016-11-06 20:37:09 -08001908 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 enforceCallPermission();
1910
1911 final long identity = Binder.clearCallingIdentity();
1912 try {
1913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1914 return;
1915 }
1916 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1917 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1918 } finally {
1919 Binder.restoreCallingIdentity(identity);
1920 }
pkanwar32d516d2016-10-14 19:37:38 -07001921 };
1922
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001925
1926 final long identity = Binder.clearCallingIdentity();
1927 try {
1928 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1929 return false;
1930 }
1931 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1932 } finally {
1933 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001934 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 }
1936
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001938 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001941 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001942 final long identity = Binder.clearCallingIdentity();
1943 try {
1944 Phone phone = PhoneFactory.getPhone(slotIndex);
1945 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1946 PhoneConstantConversions.convertCallState(phone.getState());
1947 } finally {
1948 Binder.restoreCallingIdentity(identity);
1949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
1951
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001953 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001954 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1955 }
1956
1957 @Override
1958 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001959 final long identity = Binder.clearCallingIdentity();
1960 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001961 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 if (phone != null) {
1963 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1964 } else {
1965 return PhoneConstantConversions.convertDataState(
1966 PhoneConstants.DataState.DISCONNECTED);
1967 }
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 }
1972
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001974 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001975 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1976 }
1977
1978 @Override
1979 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 final long identity = Binder.clearCallingIdentity();
1981 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001982 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 if (phone != null) {
1984 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1985 } else {
1986 return TelephonyManager.DATA_ACTIVITY_NONE;
1987 }
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
1993 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08001994 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001995 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001996 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001997
1998 LocationAccessPolicy.LocationPermissionResult locationResult =
1999 LocationAccessPolicy.checkLocationPermission(mApp,
2000 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2001 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002002 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002003 .setCallingPid(Binder.getCallingPid())
2004 .setCallingUid(Binder.getCallingUid())
2005 .setMethod("getCellLocation")
2006 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2007 .build());
2008 switch (locationResult) {
2009 case DENIED_HARD:
2010 throw new SecurityException("Not allowed to access cell location");
2011 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002012 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2013 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
2015
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002016 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017 final long identity = Binder.clearCallingIdentity();
2018 try {
2019 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002020 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002021 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022 } finally {
2023 Binder.restoreCallingIdentity(identity);
2024 }
Svetoslav64fad262015-04-14 14:35:21 -07002025 }
2026
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002028 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2029 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002030 if (!TextUtils.isEmpty(callingPackage)) {
2031 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2033 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002034 return "";
2035 }
2036 }
2037
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002038 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2039 // registered cell info, so return a NULL country instead.
2040 final long identity = Binder.clearCallingIdentity();
2041 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002042 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2043 // Get default phone in this case.
2044 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2045 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002046 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002047 // Todo: fix this when we can get the actual cellular network info when the device
2048 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002049 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002050 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2051 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 return "";
2053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 Phone phone = PhoneFactory.getPhone(phoneId);
2055 if (phone != null) {
2056 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002057 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058 if (sst != null) {
2059 LocaleTracker lt = sst.getLocaleTracker();
2060 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002061 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2062 return lt.getCurrentCountry();
2063 } else if (emergencyNumberTracker != null) {
2064 return emergencyNumberTracker.getEmergencyCountryIso();
2065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002066 }
2067 }
2068 }
2069 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002070 } finally {
2071 Binder.restoreCallingIdentity(identity);
2072 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002073 }
2074
2075 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002077 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002078 }
2079
Sanket Padawe356d7632015-06-22 14:03:32 -07002080 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002081 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 mApp.enforceCallingOrSelfPermission(
2083 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084
2085 final long identity = Binder.clearCallingIdentity();
2086 try {
2087 final Phone phone = getPhone(subId);
2088 if (phone != null) {
2089 phone.enableLocationUpdates();
2090 }
2091 } finally {
2092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095
2096 @Override
2097 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002098 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002099 }
2100
Sanket Padawe356d7632015-06-22 14:03:32 -07002101 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002102 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 mApp.enforceCallingOrSelfPermission(
2104 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002105
2106 final long identity = Binder.clearCallingIdentity();
2107 try {
2108 final Phone phone = getPhone(subId);
2109 if (phone != null) {
2110 phone.disableLocationUpdates();
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
Nathan Harold31d7ff32018-10-15 20:20:30 -07002117 /**
2118 * Returns the target SDK version number for a given package name.
2119 *
Nathan Haroldec184742019-07-10 17:04:16 -07002120 * This call MUST be invoked before clearing the calling UID.
2121 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002122 * @return target SDK if the package is found or INT_MAX.
2123 */
2124 private int getTargetSdk(String packageName) {
2125 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002126 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002127 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002128 if (ai != null) return ai.targetSdkVersion;
2129 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002130 loge("Failed to get package info for pkg="
2131 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002132 }
2133 return Integer.MAX_VALUE;
2134 }
2135
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 @Override
2137 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002138 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2139 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002140 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002141 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2142 throw new SecurityException(
2143 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2144 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002145
Jordan Liu1617b712019-07-10 15:06:26 -07002146 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2148 return null;
2149 }
Svetoslav64fad262015-04-14 14:35:21 -07002150
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002151 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002153 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002154 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Nathan Haroldf180aac2018-06-01 18:43:55 -07002156 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2157 for (CellInfo ci : info) {
2158 if (ci instanceof CellInfoGsm) {
2159 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2160 } else if (ci instanceof CellInfoWcdma) {
2161 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002164 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002167 private List<CellInfo> getCachedCellInfo() {
2168 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2169 for (Phone phone : PhoneFactory.getPhones()) {
2170 List<CellInfo> info = phone.getAllCellInfo();
2171 if (info != null) cellInfos.addAll(info);
2172 }
2173 return cellInfos;
2174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175
2176 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002177 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002178 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002179 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002180
2181 LocationAccessPolicy.LocationPermissionResult locationResult =
2182 LocationAccessPolicy.checkLocationPermission(mApp,
2183 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2184 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002185 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002186 .setCallingPid(Binder.getCallingPid())
2187 .setCallingUid(Binder.getCallingUid())
2188 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002189 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002190 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2191 .build());
2192 switch (locationResult) {
2193 case DENIED_HARD:
2194 throw new SecurityException("Not allowed to access cell info");
2195 case DENIED_SOFT:
2196 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002199 final int targetSdk = getTargetSdk(callingPackage);
2200 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2201 return getCachedCellInfo();
2202 }
2203
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002204 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002205 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2209 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002210 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002211 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002212 if (info != null) cellInfos.addAll(info);
2213 }
2214 return cellInfos;
2215 } finally {
2216 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218 }
2219
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002220 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002221 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2222 String callingFeatureId) {
2223 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2224 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 }
2226
2227 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002228 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2229 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002230 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002231 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002232 }
2233
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002234 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2235 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002236 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002237 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002238
2239 LocationAccessPolicy.LocationPermissionResult locationResult =
2240 LocationAccessPolicy.checkLocationPermission(mApp,
2241 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2242 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002243 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002244 .setCallingPid(Binder.getCallingPid())
2245 .setCallingUid(Binder.getCallingUid())
2246 .setMethod("requestCellInfoUpdate")
2247 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2248 .build());
2249 switch (locationResult) {
2250 case DENIED_HARD:
2251 throw new SecurityException("Not allowed to access cell info");
2252 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002253 try {
2254 cb.onCellInfo(new ArrayList<CellInfo>());
2255 } catch (RemoteException re) {
2256 // Drop without consequences
2257 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002258 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002259 }
2260
Nathan Harolda939a962019-05-09 10:13:47 -07002261
2262 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002263 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2264
2265 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2266 }
2267
2268 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002270 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272
2273 final long identity = Binder.clearCallingIdentity();
2274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276 } finally {
2277 Binder.restoreCallingIdentity(identity);
2278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
Shishir Agrawala9f32182016-04-12 12:00:16 -07002281 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002282 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002283 Phone phone = PhoneFactory.getPhone(slotIndex);
2284 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002285 return null;
2286 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002287 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002288 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002289 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 return null;
2291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 return phone.getImei();
2296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002299 }
2300
2301 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002302 public String getTypeAllocationCodeForSlot(int slotIndex) {
2303 Phone phone = PhoneFactory.getPhone(slotIndex);
2304 String tac = null;
2305 if (phone != null) {
2306 String imei = phone.getImei();
2307 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2308 }
2309 return tac;
2310 }
2311
2312 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002313 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002314 Phone phone = PhoneFactory.getPhone(slotIndex);
2315 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002316 return null;
2317 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002318
Jeff Davidson913390f2018-02-23 17:11:49 -08002319 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002320 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002321 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 return null;
2323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 return phone.getMeid();
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
2330 }
Jack Yu2af8d712017-03-15 17:14:14 -07002331 }
2332
2333 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002334 public String getManufacturerCodeForSlot(int slotIndex) {
2335 Phone phone = PhoneFactory.getPhone(slotIndex);
2336 String manufacturerCode = null;
2337 if (phone != null) {
2338 String meid = phone.getMeid();
2339 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2340 }
2341 return manufacturerCode;
2342 }
2343
2344 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002345 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2346 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002347 Phone phone = PhoneFactory.getPhone(slotIndex);
2348 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002349 return null;
2350 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002351 int subId = phone.getSubId();
2352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002353 mApp, subId, callingPackage, callingFeatureId,
2354 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002355 return null;
2356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357
2358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 return phone.getDeviceSvn();
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
2363 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002364 }
2365
fionaxu43304da2017-11-27 22:51:16 -08002366 @Override
2367 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 final Phone phone = getPhone(subId);
2371 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
fionaxu43304da2017-11-27 22:51:16 -08002375 }
2376
2377 @Override
2378 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 final Phone phone = getPhone(subId);
2382 return phone == null ? null : phone.getCarrierName();
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
fionaxu43304da2017-11-27 22:51:16 -08002386 }
2387
calvinpanffe225e2018-11-01 19:43:06 +08002388 @Override
chen xu0026ca62019-03-06 15:28:50 -08002389 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 final Phone phone = getPhone(subId);
2393 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002394 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002395 } finally {
2396 Binder.restoreCallingIdentity(identity);
2397 }
2398 }
2399
2400 @Override
chen xu0026ca62019-03-06 15:28:50 -08002401 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002402 final long identity = Binder.clearCallingIdentity();
2403 try {
2404 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002405 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002406 } finally {
2407 Binder.restoreCallingIdentity(identity);
2408 }
2409 }
2410
chen xu651eec72018-11-11 19:03:44 -08002411 @Override
chen xu864e11c2018-12-06 22:10:03 -08002412 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2413 if (!isSubscriptionMccMnc) {
2414 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2415 }
chen xu651eec72018-11-11 19:03:44 -08002416 final Phone phone = PhoneFactory.getPhone(slotIndex);
2417 if (phone == null) {
2418 return TelephonyManager.UNKNOWN_CARRIER_ID;
2419 }
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
2426 }
2427
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 //
2429 // Internal helper methods.
2430 //
2431
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002432 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2434 *
2435 * @throws SecurityException if the caller does not have the required permission
2436 */
2437 private void enforceModifyPermission() {
2438 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2439 }
2440
Shuo Qianf2b2df42019-11-13 17:43:31 -08002441 private void enforceActiveEmergencySessionPermission() {
2442 mApp.enforceCallingOrSelfPermission(
2443 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2444 }
2445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 /**
2447 * Make sure the caller has the CALL_PHONE permission.
2448 *
2449 * @throws SecurityException if the caller does not have the required permission
2450 */
2451 private void enforceCallPermission() {
2452 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2453 }
2454
paulhu423b5f22019-08-23 19:17:33 +08002455 private void enforceSettingsPermission() {
2456 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002457 }
2458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 private String createTelUrl(String number) {
2460 if (TextUtils.isEmpty(number)) {
2461 return null;
2462 }
2463
Jake Hambye994d462014-02-03 13:10:13 -08002464 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466
Ihab Awadf9e92732013-12-05 18:02:52 -08002467 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2469 }
2470
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002471 private static void logv(String msg) {
2472 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2473 }
2474
Ihab Awadf9e92732013-12-05 18:02:52 -08002475 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2477 }
2478
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002479 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002481 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002482 }
2483
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002485 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 final Phone phone = PhoneFactory.getPhone(slotIndex);
2489 if (phone == null) {
2490 return PhoneConstants.PHONE_TYPE_NONE;
2491 } else {
2492 return phone.getPhoneType();
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
2499 /**
2500 * Returns the CDMA ERI icon index to display
2501 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002502 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002503 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2504 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2505 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002506 }
2507
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002509 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2510 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002512 mApp, subId, callingPackage, callingFeatureId,
2513 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002514 return -1;
2515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002516
2517 final long identity = Binder.clearCallingIdentity();
2518 try {
2519 final Phone phone = getPhone(subId);
2520 if (phone != null) {
2521 return phone.getCdmaEriIconIndex();
2522 } else {
2523 return -1;
2524 }
2525 } finally {
2526 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 }
2529
2530 /**
2531 * Returns the CDMA ERI icon mode,
2532 * 0 - ON
2533 * 1 - FLASHING
2534 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002535 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002536 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2537 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2538 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002539 }
2540
Sanket Padawe356d7632015-06-22 14:03:32 -07002541 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002542 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2543 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002545 mApp, subId, callingPackage, callingFeatureId,
2546 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002547 return -1;
2548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549
2550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 final Phone phone = getPhone(subId);
2553 if (phone != null) {
2554 return phone.getCdmaEriIconMode();
2555 } else {
2556 return -1;
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 }
2562
2563 /**
2564 * Returns the CDMA ERI text,
2565 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002566 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002567 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2568 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2569 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002570 }
2571
Sanket Padawe356d7632015-06-22 14:03:32 -07002572 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002573 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2574 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002576 mApp, subId, callingPackage, callingFeatureId,
2577 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002578 return null;
2579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580
2581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 final Phone phone = getPhone(subId);
2584 if (phone != null) {
2585 return phone.getCdmaEriText();
2586 } else {
2587 return null;
2588 }
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 }
2593
2594 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002595 * Returns the CDMA MDN.
2596 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002597 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002598 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2600 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601
2602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002605 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 return phone.getLine1Number();
2607 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 return null;
2610 }
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002613 }
2614 }
2615
2616 /**
2617 * Returns the CDMA MIN.
2618 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002619 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002620 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2622 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 final Phone phone = getPhone(subId);
2627 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2628 return phone.getCdmaMin();
2629 } else {
2630 return null;
2631 }
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002634 }
2635 }
2636
Hall Liud892bec2018-11-30 14:51:45 -08002637 @Override
2638 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2639 INumberVerificationCallback callback, String callingPackage) {
2640 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2641 != PERMISSION_GRANTED) {
2642 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2643 }
2644 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2645
2646 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2647 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2648 throw new SecurityException("Calling package must be configured in the device config");
2649 }
2650
2651 if (range == null) {
2652 throw new NullPointerException("Range must be non-null");
2653 }
2654
2655 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002656 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002657
2658 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2659 }
2660
Junda Liuca05d5d2014-08-14 22:36:34 -07002661 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 * Returns true if CDMA provisioning needs to run.
2663 */
2664 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002667 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 }
2672
2673 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002674 * Sets the voice mail number of a given subId.
2675 */
2676 @Override
2677 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002678 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2683 new Pair<String, String>(alphaTag, number), new Integer(subId));
2684 return success;
2685 } finally {
2686 Binder.restoreCallingIdentity(identity);
2687 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002688 }
2689
Ta-wei Yen87c49842016-05-13 21:19:52 -07002690 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002691 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002693 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2694 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002695 if (!TextUtils.equals(callingPackage, systemDialer)) {
2696 throw new SecurityException("caller must be system dialer");
2697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698
2699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2702 if (phoneAccountHandle == null) {
2703 return null;
2704 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002705 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 } finally {
2707 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002708 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002709 }
2710
2711 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002712 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2713 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002716 mApp, subId, callingPackage, callingFeatureId,
2717 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002718 return null;
2719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002721 final long identity = Binder.clearCallingIdentity();
2722 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002723 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002727 }
2728
2729 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002730 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2731 VisualVoicemailSmsFilterSettings settings) {
2732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733
2734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002737 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002741 }
2742
2743 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002744 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746
2747 final long identity = Binder.clearCallingIdentity();
2748 try {
2749 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002750 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751 } finally {
2752 Binder.restoreCallingIdentity(identity);
2753 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002754 }
2755
2756 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002757 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2758 String callingPackage, int subId) {
2759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002768 }
2769
2770 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002771 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002772 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773
2774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002777 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 } finally {
2779 Binder.restoreCallingIdentity(identity);
2780 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002781 }
2782
2783 @Override
2784 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2785 String number, int port, String text, PendingIntent sentIntent) {
2786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002787 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002788 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002789 SmsController smsController = PhoneFactory.getSmsController();
2790 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2791 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002792 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002793
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002794 /**
fionaxu0152e512016-11-14 13:36:14 -08002795 * Sets the voice activation state of a given subId.
2796 */
2797 @Override
2798 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2800 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 final Phone phone = getPhone(subId);
2805 if (phone != null) {
2806 phone.setVoiceActivationState(activationState);
2807 } else {
2808 loge("setVoiceActivationState fails with invalid subId: " + subId);
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002812 }
2813 }
2814
2815 /**
2816 * Sets the data activation state of a given subId.
2817 */
2818 @Override
2819 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2821 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone phone = getPhone(subId);
2826 if (phone != null) {
2827 phone.setDataActivationState(activationState);
2828 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002829 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002833 }
2834 }
2835
2836 /**
2837 * Returns the voice activation state of a given subId.
2838 */
2839 @Override
2840 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002841 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
fionaxu0152e512016-11-14 13:36:14 -08002843 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 if (phone != null) {
2847 return phone.getVoiceActivationState();
2848 } else {
2849 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002853 }
2854 }
2855
2856 /**
2857 * Returns the data activation state of a given subId.
2858 */
2859 @Override
2860 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
fionaxu0152e512016-11-14 13:36:14 -08002863 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 if (phone != null) {
2867 return phone.getDataActivationState();
2868 } else {
2869 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002873 }
2874 }
2875
2876 /**
Wink Saville36469e72014-06-11 15:17:00 -07002877 * Returns the unread count of voicemails for a subId
2878 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002880 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2881 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002882 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002883 mApp, subId, callingPackage, callingFeatureId,
2884 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002885 return 0;
2886 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 final Phone phone = getPhone(subId);
2890 if (phone != null) {
2891 return phone.getVoiceMessageCount();
2892 } else {
2893 return 0;
2894 }
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 }
2899
2900 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002901 * returns true, if the device is in a state where both voice and data
2902 * are supported simultaneously. This can change based on location or network condition.
2903 */
2904 @Override
2905 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 final Phone phone = getPhone(subId);
2909 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002913 }
2914
2915 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002916 * Send the dialer code if called from the current default dialer or the caller has
2917 * carrier privilege.
2918 * @param inputCode The dialer code to send
2919 */
2920 @Override
2921 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002922 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002923 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002924 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2925 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002926 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2928 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930
2931 final long identity = Binder.clearCallingIdentity();
2932 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002933 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 } finally {
2935 Binder.restoreCallingIdentity(identity);
2936 }
fionaxu235cc5e2017-03-06 22:25:57 -08002937 }
2938
Pengquan Menga1bb6272018-09-06 09:59:22 -07002939 @Override
2940 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002941 if (!isActiveSubscription(subId)) {
2942 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2943 }
2944
Pengquan Menga1bb6272018-09-06 09:59:22 -07002945 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2946 }
2947
Brad Ebinger35c841c2018-10-01 10:40:55 -07002948 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002949 public boolean isInEmergencySmsMode() {
2950 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 for (Phone phone : PhoneFactory.getPhones()) {
2954 if (phone.isInEmergencySmsMode()) {
2955 return true;
2956 }
2957 }
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
2960 }
2961 return false;
2962 }
2963
2964 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002965 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2966 throws RemoteException {
2967 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002968 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2969 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2970 "IMS not available on device.");
2971 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002972 final long token = Binder.clearCallingIdentity();
2973 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002975 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002976 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002977 } catch (ImsException e) {
2978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 } finally {
2980 Binder.restoreCallingIdentity(token);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2986 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002987 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2988 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2989 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002990 final long token = Binder.clearCallingIdentity();
2991 try {
2992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2993 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2994 .removeRegistrationCallbackForSubscription(c, subId);
2995 } catch (ImsException e) {
2996 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2997 + "is inactive, ignoring unregister.");
2998 // If the subscription is no longer active, just return, since the callback
2999 // will already have been removed internally.
3000 } finally {
3001 Binder.restoreCallingIdentity(token);
3002 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003003 }
3004
Brad Ebinger774ba362019-10-22 17:36:18 -07003005 /**
3006 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3007 */
3008 @Override
3009 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3010 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3011 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3012 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3013 "IMS not available on device.");
3014 }
3015 final long token = Binder.clearCallingIdentity();
3016 try {
3017 Phone phone = getPhone(subId);
3018 if (phone == null) {
3019 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3020 + subId + "'");
3021 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3022 }
3023 phone.getImsRegistrationState(regState -> {
3024 try {
3025 consumer.accept((regState == null)
3026 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3027 } catch (RemoteException e) {
3028 // Ignore if the remote process is no longer available to call back.
3029 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3030 }
3031 });
3032 } finally {
3033 Binder.restoreCallingIdentity(token);
3034 }
3035 }
3036
3037 /**
3038 * Get the transport type for the IMS service registration state.
3039 */
3040 @Override
3041 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3042 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3043 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3044 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3045 "IMS not available on device.");
3046 }
3047 final long token = Binder.clearCallingIdentity();
3048 try {
3049 Phone phone = getPhone(subId);
3050 if (phone == null) {
3051 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3052 + subId + "'");
3053 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3054 }
3055 phone.getImsRegistrationTech(regTech -> {
3056 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3057 int regTechConverted = (regTech == null)
3058 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3059 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3060 regTechConverted);
3061 try {
3062 consumer.accept(regTechConverted);
3063 } catch (RemoteException e) {
3064 // Ignore if the remote process is no longer available to call back.
3065 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3066 }
3067 });
3068 } finally {
3069 Binder.restoreCallingIdentity(token);
3070 }
3071 }
3072
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003074 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3075 throws RemoteException {
3076 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003077 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3078 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3079 "IMS not available on device.");
3080 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3082 final long token = Binder.clearCallingIdentity();
3083 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003084 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003085 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003086 } catch (ImsException e) {
3087 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003088 } finally {
3089 Binder.restoreCallingIdentity(token);
3090 }
3091 }
3092
3093 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003094 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3095 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003096 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3097 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3098 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003099
3100 final long token = Binder.clearCallingIdentity();
3101 try {
3102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3103 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003104 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003105 } catch (ImsException e) {
3106 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3107 + "is inactive, ignoring unregister.");
3108 // If the subscription is no longer active, just return, since the callback
3109 // will already have been removed internally.
3110 } finally {
3111 Binder.restoreCallingIdentity(token);
3112 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 }
3114
3115 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003116 public boolean isCapable(int subId, int capability, int regTech) {
3117 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003118 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3119 final long token = Binder.clearCallingIdentity();
3120 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003121 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003123 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3125 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003126 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003127 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3128 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003129 } finally {
3130 Binder.restoreCallingIdentity(token);
3131 }
3132 }
3133
3134 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003135 public boolean isAvailable(int subId, int capability, int regTech) {
3136 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 final long token = Binder.clearCallingIdentity();
3138 try {
3139 Phone phone = getPhone(subId);
3140 if (phone == null) return false;
3141 return phone.isImsCapabilityAvailable(capability, regTech);
3142 } finally {
3143 Binder.restoreCallingIdentity(token);
3144 }
3145 }
3146
Brad Ebinger77b832e2019-10-17 17:03:22 -07003147 /**
3148 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3149 * subscription.
3150 * @param subId The subscription to use to check the configuration.
3151 * @param callback The callback that will be used to send the result.
3152 * @param capability The MmTelFeature capability that will be used to send the result.
3153 * @param transportType The transport type of the MmTelFeature capability.
3154 */
3155 @Override
3156 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3157 int transportType) {
3158 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3159 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3160 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3161 "IMS not available on device.");
3162 }
3163 final long token = Binder.clearCallingIdentity();
3164 try {
3165 int slotId = getSlotIndex(subId);
3166 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3167 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3168 + subId + "'");
3169 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3170 }
3171 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3172 transportType, aBoolean -> {
3173 try {
3174 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3175 } catch (RemoteException e) {
3176 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3177 + "running. Ignore");
3178 }
3179 });
3180 } finally {
3181 Binder.restoreCallingIdentity(token);
3182 }
3183 }
3184
Brad Ebinger35c841c2018-10-01 10:40:55 -07003185 @Override
3186 public boolean isAdvancedCallingSettingEnabled(int subId) {
3187 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3188 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3189 final long token = Binder.clearCallingIdentity();
3190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003192 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003193 } catch (ImsException e) {
3194 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003195 } finally {
3196 Binder.restoreCallingIdentity(token);
3197 }
3198 }
3199
3200 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003201 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003203 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003209 } catch (ImsException e) {
3210 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
3214 }
3215
3216 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003217 public boolean isVtSettingEnabled(int subId) {
3218 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003222 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3223 } catch (ImsException e) {
3224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
3228 }
3229
3230 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003231 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003233 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003237 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003238 } catch (ImsException e) {
3239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
3243 }
3244
3245 @Override
3246 public boolean isVoWiFiSettingEnabled(int subId) {
3247 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003251 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003253 } catch (ImsException e) {
3254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 } finally {
3256 Binder.restoreCallingIdentity(identity);
3257 }
3258 }
3259
3260 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003261 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003263 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003267 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003268 } catch (ImsException e) {
3269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
3276 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3277 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003283 } catch (ImsException e) {
3284 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
3288 }
3289
3290 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003291 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003293 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003297 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003299 } catch (ImsException e) {
3300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
3304 }
3305
3306 @Override
3307 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3309 "setVoWiFiNonPersistent");
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003314 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003315 } catch (ImsException e) {
3316 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
3320 }
3321
3322 @Override
3323 public int getVoWiFiModeSetting(int subId) {
3324 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003328 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003329 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003330 } catch (ImsException e) {
3331 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
3335 }
3336
3337 @Override
3338 public void setVoWiFiModeSetting(int subId, int mode) {
3339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3340 "setVoWiFiModeSetting");
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003344 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003346 } catch (ImsException e) {
3347 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
3351 }
3352
3353 @Override
3354 public int getVoWiFiRoamingModeSetting(int subId) {
3355 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003359 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003361 } catch (ImsException e) {
3362 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
3366 }
3367
3368 @Override
3369 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3371 "setVoWiFiRoamingModeSetting");
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003375 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003376 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003377 } catch (ImsException e) {
3378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
3382 }
3383
3384 @Override
3385 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3387 "setRttCapabilityEnabled");
3388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003391 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3392 } catch (ImsException e) {
3393 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
3397 }
3398
3399 @Override
3400 public boolean isTtyOverVolteEnabled(int subId) {
3401 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003405 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003407 } catch (ImsException e) {
3408 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 } finally {
3410 Binder.restoreCallingIdentity(identity);
3411 }
3412 }
3413
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003414 @Override
3415 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3416 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003420 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003421 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003422 } catch (ImsException e) {
3423 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
3430 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3431 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3432 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003433 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3434 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3435 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003439 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003440 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003441 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3442 + "is inactive, ignoring unregister.");
3443 // If the subscription is no longer active, just return, since the callback will already
3444 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
3450 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003451 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3452 boolean isProvisioned) {
3453 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3454 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3455 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3456 }
3457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3458 "setProvisioningStatusForCapability");
3459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3462 Phone phone = getPhone(subId);
3463 if (phone == null) {
3464 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3465 + subId);
3466 return;
3467 }
3468 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3469 return;
3470 }
3471
3472 // this capability requires provisioning, route to the correct API.
3473 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3474 switch (capability) {
3475 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3476 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3477 ims.setVolteProvisioned(isProvisioned);
3478 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3479 ims.setWfcProvisioned(isProvisioned);
3480 }
3481 break;
3482 }
3483 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3484 // There is currently no difference in VT provisioning type.
3485 ims.setVtProvisioned(isProvisioned);
3486 break;
3487 }
3488 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3489 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3490 // change the capability of the feature instead if needed.
3491 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3492 == isProvisioned) {
3493 // No change in provisioning.
3494 return;
3495 }
3496 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3497 try {
3498 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003499 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003500 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3501 + ", Exception" + e.getMessage());
3502 }
3503 break;
3504 }
3505 default: {
3506 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3507 + capability + "', which does not require provisioning.");
3508 }
3509 }
3510
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
3514 }
3515
3516 @Override
3517 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3518 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3519 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3520 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3521 }
3522 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3526 Phone phone = getPhone(subId);
3527 if (phone == null) {
3528 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3529 + subId);
3530 // We will fail with "true" as the provisioning status because this is the default
3531 // if we do not require provisioning.
3532 return true;
3533 }
3534
3535 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3536 return true;
3537 }
3538
3539 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3540 switch (capability) {
3541 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3542 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3543 return ims.isVolteProvisionedOnDevice();
3544 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3545 return ims.isWfcProvisionedOnDevice();
3546 }
3547 // This should never happen, since we are checking tech above to make sure it
3548 // is either LTE or IWLAN.
3549 throw new IllegalArgumentException("Invalid radio technology for voice "
3550 + "capability.");
3551 }
3552 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3553 // There is currently no difference in VT provisioning type.
3554 return ims.isVtProvisionedOnDevice();
3555 }
3556 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3557 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3558 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3559 }
3560 default: {
3561 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3562 + capability + "', which does not require provisioning.");
3563 }
3564 }
3565
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
3568 }
3569 }
3570
3571 @Override
3572 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3573 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3574 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3575 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3576 }
3577 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3578 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3579 return (provisionedBits & capability) > 0;
3580 }
3581
3582 @Override
3583 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3584 boolean isProvisioned) {
3585 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3586 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3587 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3588 }
3589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3590 "setProvisioningStatusForCapability");
3591 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3592 // If the current provisioning status for capability already matches isProvisioned,
3593 // do nothing.
3594 if (((provisionedBits & capability) > 0) == isProvisioned) {
3595 return;
3596 }
3597 if (isProvisioned) {
3598 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3599 } else {
3600 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3601 }
3602 }
3603
3604 /**
3605 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3606 * technology. The bitfield should mirror the bitfield defined by
3607 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3608 */
3609 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3610 String key = getMmTelProvisioningKey(subId, tech);
3611 // Default is no capabilities are provisioned.
3612 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3613 }
3614
3615 /**
3616 * Sets the MmTel capability provisioning bitfield (defined by
3617 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3618 * technology specified.
3619 *
3620 * Note: This is a synchronous command and should not be called on UI thread.
3621 */
3622 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3623 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3624 String key = getMmTelProvisioningKey(subId, tech);
3625 editor.putInt(key, newField);
3626 editor.commit();
3627 }
3628
3629 private static String getMmTelProvisioningKey(int subId, int tech) {
3630 // resulting key is provision_ims_mmtel_{subId}_{tech}
3631 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3632 }
3633
3634 /**
3635 * Query CarrierConfig to see if the specified capability requires provisioning for the
3636 * carrier associated with the subscription id.
3637 */
3638 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3639 int capability) {
3640 CarrierConfigManager configManager = new CarrierConfigManager(context);
3641 PersistableBundle c = configManager.getConfigForSubId(subId);
3642 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003643 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003644 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3645 false);
3646 boolean requireVoiceVtProvisioning = c.getBoolean(
3647 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3648
3649 // First check to make sure that the capability requires provisioning.
3650 switch (capability) {
3651 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3652 // intentional fallthrough
3653 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3654 if (requireVoiceVtProvisioning) {
3655 // Voice and Video requires provisioning
3656 return true;
3657 }
3658 break;
3659 }
3660 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3661 if (requireUtProvisioning) {
3662 // UT requires provisioning
3663 return true;
3664 }
3665 break;
3666 }
3667 }
3668 return false;
3669 }
3670
3671 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003672 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003673 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3674 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3675 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003676 enforceReadPrivilegedPermission("getImsProvisioningInt");
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003680 int slotId = getSlotIndex(subId);
3681 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3682 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3683 + subId + "' for key:" + key);
3684 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3685 }
3686 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003687 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003688 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3689 + subId + "' for key:" + key);
3690 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
3694 }
3695
3696 @Override
3697 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003698 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3699 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3700 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003701 enforceReadPrivilegedPermission("getImsProvisioningString");
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003705 int slotId = getSlotIndex(subId);
3706 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3707 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3708 + subId + "' for key:" + key);
3709 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3710 }
3711 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003712 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003713 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3714 + subId + "' for key:" + key);
3715 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
3719 }
3720
3721 @Override
3722 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3724 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3725 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3727 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003731 int slotId = getSlotIndex(subId);
3732 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3733 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3734 + subId + "' for key:" + key);
3735 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3736 }
3737 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003738 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003739 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3740 + "' for key:" + key);
3741 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
3745 }
3746
3747 @Override
3748 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3750 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3751 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3753 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003757 int slotId = getSlotIndex(subId);
3758 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3759 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3760 + subId + "' for key:" + key);
3761 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3762 }
3763 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003764 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003765 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3766 + "' for key:" + key);
3767 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003768 } finally {
3769 Binder.restoreCallingIdentity(identity);
3770 }
3771 }
3772
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003773 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 int slotId = SubscriptionManager.getSlotIndex(subId);
3775 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003776 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3777 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003778 }
3779 return slotId;
3780 }
3781
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003782 private int getSlotIndex(int subId) {
3783 int slotId = SubscriptionManager.getSlotIndex(subId);
3784 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3785 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3786 }
3787 return slotId;
3788 }
3789
Wink Saville36469e72014-06-11 15:17:00 -07003790 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003791 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003792 */
3793 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003794 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3795 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003796 final int targetSdk = getTargetSdk(callingPackage);
3797 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003798 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003799 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003800 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003801 mApp, subId, callingPackage, callingFeatureId,
3802 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003803 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3804 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 final Phone phone = getPhone(subId);
3809 if (phone != null) {
3810 return phone.getServiceState().getDataNetworkType();
3811 } else {
3812 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3813 }
3814 } finally {
3815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003817 }
3818
3819 /**
3820 * Returns the data network type
3821 */
3822 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003823 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3824 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3825 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003826 }
3827
3828 /**
3829 * Returns the data network type for a subId
3830 */
3831 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003832 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3833 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003835 mApp, subId, callingPackage, callingFeatureId,
3836 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003837 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3838 }
3839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 final Phone phone = getPhone(subId);
3843 if (phone != null) {
3844 return phone.getServiceState().getDataNetworkType();
3845 } else {
3846 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3847 }
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003851 }
3852
3853 /**
Wink Saville36469e72014-06-11 15:17:00 -07003854 * Returns the Voice network type for a subId
3855 */
3856 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003857 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3858 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003860 mApp, subId, callingPackage, callingFeatureId,
3861 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003862 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3863 }
3864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 final Phone phone = getPhone(subId);
3868 if (phone != null) {
3869 return phone.getServiceState().getVoiceNetworkType();
3870 } else {
3871 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3872 }
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003876 }
3877
3878 /**
3879 * @return true if a ICC card is present
3880 */
3881 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003882 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003883 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3884 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003885 }
3886
3887 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003888 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003889 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003890 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003891 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 final Phone phone = PhoneFactory.getPhone(slotIndex);
3895 if (phone != null) {
3896 return phone.getIccCard().hasIccCard();
3897 } else {
3898 return false;
3899 }
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003903 }
3904
3905 /**
3906 * Return if the current radio is LTE on CDMA. This
3907 * is a tri-state return value as for a period of time
3908 * the mode may be unknown.
3909 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003910 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003912 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003913 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003914 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003915 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3916 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3917 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003918 }
3919
Sanket Padawe356d7632015-06-22 14:03:32 -07003920 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003921 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3922 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003924 mApp, subId, callingPackage, callingFeatureId,
3925 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003926 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3927 }
3928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 final Phone phone = getPhone(subId);
3932 if (phone == null) {
3933 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3934 } else {
3935 return phone.getLteOnCdmaMode();
3936 }
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003939 }
Wink Saville36469e72014-06-11 15:17:00 -07003940 }
3941
Wink Saville36469e72014-06-11 15:17:00 -07003942 /**
3943 * {@hide}
3944 * Returns Default subId, 0 in the case of single standby.
3945 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003946 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003947 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003948 }
3949
Shishir Agrawala9f32182016-04-12 12:00:16 -07003950 private int getSlotForDefaultSubscription() {
3951 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3952 }
3953
Wink Savilleb564aae2014-10-23 10:18:09 -07003954 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003955 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003956 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003957
Pengquan Menge92a50d2018-09-21 15:54:48 -07003958 private boolean isActiveSubscription(int subId) {
3959 return mSubscriptionController.isActiveSubId(subId);
3960 }
3961
Ihab Awadf2177b72013-11-25 13:33:23 -08003962 /**
3963 * @see android.telephony.TelephonyManager.WifiCallingChoices
3964 */
3965 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966 final long identity = Binder.clearCallingIdentity();
3967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003969 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3970 getWhenToMakeWifiCallsDefaultPreference());
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003974 }
3975
3976 /**
3977 * @see android.telephony.TelephonyManager.WifiCallingChoices
3978 */
3979 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 final long identity = Binder.clearCallingIdentity();
3981 try {
3982 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003983 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003988 }
3989
Sailesh Nepald1e68152013-12-12 19:08:02 -08003990 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003991 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003992 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003993 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003994
Jordan Liu4c733742019-02-28 12:03:40 -08003995 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3996 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3997 if (phoneId == -1) {
3998 throw new IllegalArgumentException("Given slot index: " + slotIndex
3999 + " does not correspond to an active phone");
4000 }
4001 return PhoneFactory.getPhone(phoneId);
4002 }
4003
Shishir Agrawal566b7612013-10-28 14:41:00 -07004004 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004005 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4006 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4008 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004010 if (DBG) {
4011 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4012 }
4013 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4014 p2);
4015 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004016
Jordan Liu4c733742019-02-28 12:03:40 -08004017
4018 @Override
4019 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4020 int slotIndex, String callingPackage, String aid, int p2) {
4021 enforceModifyPermission();
4022 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4023 if (DBG) {
4024 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4025 }
4026 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4027 callingPackage, aid, p2);
4028 }
4029
4030 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4031 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 if (TextUtils.equals(ISDR_AID, aid)) {
4035 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004036 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4037 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038 if (bestComponent == null
4039 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4040 loge("The calling package is not allowed to access ISD-R.");
4041 throw new SecurityException(
4042 "The calling package is not allowed to access ISD-R.");
4043 }
Derek Tan740e1672017-06-27 14:56:27 -07004044 }
Derek Tan740e1672017-06-27 14:56:27 -07004045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004047 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4048 null /* workSource */);
4049 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 return response;
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004054 }
4055
4056 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004057 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4059 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004060 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4061 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004063
Jordan Liu4c733742019-02-28 12:03:40 -08004064 @Override
4065 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4066 enforceModifyPermission();
4067 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4068 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4069 channel);
4070 }
4071
4072 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 final long identity = Binder.clearCallingIdentity();
4074 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075 if (channel < 0) {
4076 return false;
4077 }
Jordan Liu4c733742019-02-28 12:03:40 -08004078 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4079 null /* workSource */);
4080 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 return success;
4082 } finally {
4083 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004084 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004085 }
4086
4087 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004088 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004089 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4091 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004092 if (DBG) {
4093 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4094 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4095 + p3 + " data=" + data);
4096 }
4097 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4098 command, p1, p2, p3, data);
4099 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004100
Jordan Liu4c733742019-02-28 12:03:40 -08004101 @Override
4102 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4103 int command, int p1, int p2, int p3, String data) {
4104 enforceModifyPermission();
4105 if (DBG) {
4106 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4107 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4108 + p3 + " data=" + data);
4109 }
4110 return iccTransmitApduLogicalChannelWithPermission(
4111 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4112 data);
4113 }
4114
4115 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4116 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 final long identity = Binder.clearCallingIdentity();
4118 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004119 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 return "";
4121 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004124 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4125 null /* workSource */);
4126 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 // Append the returned status code to the end of the response payload.
4129 String s = Integer.toHexString(
4130 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4131 if (response.payload != null) {
4132 s = IccUtils.bytesToHexString(response.payload) + s;
4133 }
4134 return s;
4135 } finally {
4136 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004137 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004138 }
Jake Hambye994d462014-02-03 13:10:13 -08004139
Evan Charltonc66da362014-05-16 14:06:40 -07004140 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004141 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4142 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4144 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004146 if (DBG) {
4147 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4148 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4149 }
4150 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4151 cla, command, p1, p2, p3, data);
4152 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004153
Jordan Liu4c733742019-02-28 12:03:40 -08004154 @Override
4155 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4156 int command, int p1, int p2, int p3, String data) {
4157 enforceModifyPermission();
4158 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4159 if (DBG) {
4160 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4161 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4162 + " data=" + data);
4163 }
4164
4165 return iccTransmitApduBasicChannelWithPermission(
4166 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4167 p2, p3, data);
4168 }
4169
4170 // open APDU basic channel assuming the caller has sufficient permissions
4171 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4172 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4176 && TextUtils.equals(ISDR_AID, data)) {
4177 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004178 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4179 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 if (bestComponent == null
4181 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4182 loge("The calling package is not allowed to select ISD-R.");
4183 throw new SecurityException(
4184 "The calling package is not allowed to select ISD-R.");
4185 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004186 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004189 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4190 null /* workSource */);
4191 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 // Append the returned status code to the end of the response payload.
4194 String s = Integer.toHexString(
4195 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4196 if (response.payload != null) {
4197 s = IccUtils.bytesToHexString(response.payload) + s;
4198 }
4199 return s;
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004202 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004203 }
4204
4205 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004206 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004207 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4209 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
4213 if (DBG) {
4214 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4215 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4216 }
4217
4218 IccIoResult response =
4219 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4220 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4221 subId);
4222
4223 if (DBG) {
4224 log("Exchange SIM_IO [R]" + response);
4225 }
4226
4227 byte[] result = null;
4228 int length = 2;
4229 if (response.payload != null) {
4230 length = 2 + response.payload.length;
4231 result = new byte[length];
4232 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4233 } else {
4234 result = new byte[length];
4235 }
4236
4237 result[length - 1] = (byte) response.sw2;
4238 result[length - 2] = (byte) response.sw1;
4239 return result;
4240 } finally {
4241 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004242 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004243 }
4244
Nathan Haroldb3014052017-01-25 15:57:32 -08004245 /**
4246 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4247 * on a particular subscription
4248 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004249 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4250 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004252 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004253 return null;
4254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255
4256 final long identity = Binder.clearCallingIdentity();
4257 try {
4258 if (appType != TelephonyManager.APPTYPE_USIM
4259 && appType != TelephonyManager.APPTYPE_SIM) {
4260 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4261 return null;
4262 }
4263 Object response = sendRequest(
4264 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4265 if (response instanceof String[]) {
4266 return (String[]) response;
4267 }
yincheng zhaod698b842019-09-06 17:06:54 -07004268 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004270 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004273 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004274 }
4275
yincheng zhaod698b842019-09-06 17:06:54 -07004276 /**
4277 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4278 * subscription.
4279 *
4280 * @param subId the id of the subscription.
4281 * @param appType the uicc app type, must be USIM or SIM.
4282 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4283 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004284 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004285 * @return number of fplmns that is successfully written to the SIM.
4286 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004287 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4288 String callingFeatureId) {
4289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4290 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004291 if (DBG) logv("no permissions for setForbiddenplmns");
4292 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4293 }
4294 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4295 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4296 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4297 }
4298 if (fplmns == null) {
4299 throw new IllegalArgumentException("Fplmn List provided is null");
4300 }
4301 for (String fplmn : fplmns) {
4302 if (!CellIdentity.isValidPlmn(fplmn)) {
4303 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4304 }
4305 }
4306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 Object response = sendRequest(
4309 CMD_SET_FORBIDDEN_PLMNS,
4310 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4311 subId);
4312 return (int) response;
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 }
4317
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004318 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004319 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4321 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4326 if (response.payload == null) {
4327 return "";
4328 }
Evan Charltonc66da362014-05-16 14:06:40 -07004329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 // Append the returned status code to the end of the response payload.
4331 String s = Integer.toHexString(
4332 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4333 s = IccUtils.bytesToHexString(response.payload) + s;
4334 return s;
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
Evan Charltonc66da362014-05-16 14:06:40 -07004338 }
4339
Jake Hambye994d462014-02-03 13:10:13 -08004340 /**
4341 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4342 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4343 *
4344 * @param itemID the ID of the item to read
4345 * @return the NV item as a String, or null on error.
4346 */
4347 @Override
4348 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4351 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352
4353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004356 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4358 return value;
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
Jake Hambye994d462014-02-03 13:10:13 -08004362 }
4363
4364 /**
4365 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4366 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4367 *
4368 * @param itemID the ID of the item to read
4369 * @param itemValue the value to write, as a String
4370 * @return true on success; false on any failure
4371 */
4372 @Override
4373 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004374 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4376 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377
4378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4381 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004382 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4384 return success;
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
Jake Hambye994d462014-02-03 13:10:13 -08004388 }
4389
4390 /**
4391 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4392 * Used for device configuration by some CDMA operators.
4393 *
4394 * @param preferredRoamingList byte array containing the new PRL
4395 * @return true on success; false on any failure
4396 */
4397 @Override
4398 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4400 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401
4402 final long identity = Binder.clearCallingIdentity();
4403 try {
4404 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4405 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4406 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4407 return success;
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
Jake Hambye994d462014-02-03 13:10:13 -08004411 }
4412
4413 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004414 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004415 * Used for device configuration by some CDMA operators.
4416 *
chen xu6dac5ab2018-10-26 17:39:23 -07004417 * @param slotIndex - device slot.
4418 *
Jake Hambye994d462014-02-03 13:10:13 -08004419 * @return true on success; false on any failure
4420 */
4421 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004422 public boolean resetModemConfig(int slotIndex) {
4423 Phone phone = PhoneFactory.getPhone(slotIndex);
4424 if (phone != null) {
4425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427
chen xu6dac5ab2018-10-26 17:39:23 -07004428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4431 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4432 return success;
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 }
chen xu6dac5ab2018-10-26 17:39:23 -07004437 return false;
4438 }
4439
4440 /**
4441 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4442 *
4443 * @param slotIndex - device slot.
4444 *
4445 * @return true on success; false on any failure
4446 */
4447 @Override
4448 public boolean rebootModem(int slotIndex) {
4449 Phone phone = PhoneFactory.getPhone(slotIndex);
4450 if (phone != null) {
4451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4452 mApp, phone.getSubId(), "rebootModem");
4453
4454 final long identity = Binder.clearCallingIdentity();
4455 try {
4456 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4457 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4458 return success;
4459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
4462 }
4463 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004464 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004465
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004466 public String[] getPcscfAddress(String apnType, String callingPackage,
4467 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004468 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4470 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004471 return new String[0];
4472 }
4473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 final long identity = Binder.clearCallingIdentity();
4475 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004476 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
Wink Saville36469e72014-06-11 15:17:00 -07004480 }
4481
Brad Ebinger51f743a2017-01-23 13:50:20 -08004482 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004483 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4484 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004485 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004486 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488
4489 final long identity = Binder.clearCallingIdentity();
4490 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004491 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004492 // may happen if the device does not support IMS.
4493 return;
4494 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004495 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004499 }
4500
4501 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004502 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4503 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004504 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004505 public void disableIms(int slotId) {
4506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507
4508 final long identity = Binder.clearCallingIdentity();
4509 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004510 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004511 // may happen if the device does not support IMS.
4512 return;
4513 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004514 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 } finally {
4516 Binder.restoreCallingIdentity(identity);
4517 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004518 }
4519
4520 /**
4521 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4522 * feature or {@link null} if the service is not available. If the feature is available, the
4523 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4524 */
4525 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004526 IImsServiceFeatureCallback callback) {
4527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528
4529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004531 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004532 // may happen if the device does not support IMS.
4533 return null;
4534 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004535 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004539 }
4540
4541 /**
4542 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4543 * feature during emergency calling or {@link null} if the service is not available. If the
4544 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4545 * listener for feature updates.
4546 */
4547 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549
4550 final long identity = Binder.clearCallingIdentity();
4551 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004552 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004553 // may happen if the device does not support IMS.
4554 return null;
4555 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004556 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004560 }
4561
Brad Ebinger5f64b052017-12-14 14:26:15 -08004562 /**
4563 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004564 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004565 */
4566 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004571 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004572 // may happen if the device does not support IMS.
4573 return null;
4574 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004575 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004579 }
4580
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004581 /**
4582 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004583 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004584 */
4585 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4586 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004590 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004591 // may happen if the device does not support IMS.
4592 return null;
4593 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004594 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004598 }
4599
Brad Ebinger884c07b2018-02-15 16:17:40 -08004600 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004601 * Sets the ImsService Package Name that Telephony will bind to.
4602 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004603 * @param slotIndex the slot ID that the ImsService should bind for.
4604 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004605 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004606 * @param featureTypes An integer array of feature types associated with a packageName.
4607 * @param packageName The name of the package that the current configuration will be replaced
4608 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004609 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004610 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004611 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4612 int[] featureTypes, String packageName) {
4613 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4614 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4616 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004617 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 final long identity = Binder.clearCallingIdentity();
4620 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004621 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004622 // may happen if the device does not support IMS.
4623 return false;
4624 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004625 Map<Integer, String> featureConfig = new HashMap<>();
4626 for (int featureType : featureTypes) {
4627 featureConfig.put(featureType, packageName);
4628 }
4629 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4630 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004634 }
4635
4636 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004637 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004638 *
4639 * @param slotId The slot that the ImsService is associated with.
4640 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4641 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004642 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004643 * @return the package name of the ImsService configuration.
4644 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004645 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4646 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004647 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004648 TelephonyPermissions
4649 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4650 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4651 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 final long identity = Binder.clearCallingIdentity();
4654 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004655 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004656 // may happen if the device does not support IMS.
4657 return "";
4658 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004659 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004660 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4661 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004665 }
4666
Brad Ebinger77b832e2019-10-17 17:03:22 -07004667 /**
4668 * Get the MmTelFeature state associated with the requested subscription id.
4669 * @param subId The subscription that the MmTelFeature is associated with.
4670 * @param callback A callback with an integer containing the
4671 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4672 */
4673 @Override
4674 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4675 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4676 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4677 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4678 "IMS not available on device.");
4679 }
4680 final long token = Binder.clearCallingIdentity();
4681 try {
4682 int slotId = getSlotIndex(subId);
4683 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4684 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4685 + subId + "'");
4686 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4687 }
4688 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4689 try {
4690 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4691 } catch (RemoteException e) {
4692 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4693 + "Ignore");
4694 }
4695 });
4696 } finally {
4697 Binder.restoreCallingIdentity(token);
4698 }
4699 }
4700
Wink Saville36469e72014-06-11 15:17:00 -07004701 public void setImsRegistrationState(boolean registered) {
4702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004703
4704 final long identity = Binder.clearCallingIdentity();
4705 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004706 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707 } finally {
4708 Binder.restoreCallingIdentity(identity);
4709 }
Wink Saville36469e72014-06-11 15:17:00 -07004710 }
4711
4712 /**
Stuart Scott54788802015-03-30 13:18:01 -07004713 * Set the network selection mode to automatic.
4714 *
4715 */
4716 @Override
4717 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4719 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720
Pengquan Menge92a50d2018-09-21 15:54:48 -07004721 if (!isActiveSubscription(subId)) {
4722 return;
4723 }
4724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725 final long identity = Binder.clearCallingIdentity();
4726 try {
4727 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4728 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
Stuart Scott54788802015-03-30 13:18:01 -07004732 }
4733
Pengquan Mengea84e042018-09-20 14:57:26 -07004734 /**
4735 * Ask the radio to connect to the input network and change selection mode to manual.
4736 *
4737 * @param subId the id of the subscription.
4738 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4739 * the operator to attach to.
4740 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4741 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4742 * normal network selection next time.
4743 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004744 */
4745 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004746 public boolean setNetworkSelectionModeManual(
4747 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4749 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004750
4751 if (!isActiveSubscription(subId)) {
4752 return false;
4753 }
4754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004755 final long identity = Binder.clearCallingIdentity();
4756 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004757 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004759 if (DBG) {
4760 log("setNetworkSelectionModeManual: subId: " + subId
4761 + " operator: " + operatorInfo);
4762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4764 } finally {
4765 Binder.restoreCallingIdentity(identity);
4766 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004767 }
4768
4769 /**
4770 * Scans for available networks.
4771 */
4772 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004773 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4774 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4776 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004777 LocationAccessPolicy.LocationPermissionResult locationResult =
4778 LocationAccessPolicy.checkLocationPermission(mApp,
4779 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4780 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004781 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004782 .setCallingPid(Binder.getCallingPid())
4783 .setCallingUid(Binder.getCallingUid())
4784 .setMethod("getCellNetworkScanResults")
4785 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4786 .build());
4787 switch (locationResult) {
4788 case DENIED_HARD:
4789 throw new SecurityException("Not allowed to access scan results -- location");
4790 case DENIED_SOFT:
4791 return null;
4792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793
Pengquan Menga1bb6272018-09-06 09:59:22 -07004794 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 try {
4796 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004797 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004802 }
4803
4804 /**
yinxub1bed742017-04-17 11:45:04 -07004805 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004806 *
yinxub1bed742017-04-17 11:45:04 -07004807 * @param subId id of the subscription
4808 * @param request contains the radio access networks with bands/channels to scan
4809 * @param messenger callback messenger for scan results or errors
4810 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004811 * @return the id of the requested scan which can be used to stop the scan.
4812 */
4813 @Override
4814 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004815 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4817 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004818 LocationAccessPolicy.LocationPermissionResult locationResult =
4819 LocationAccessPolicy.checkLocationPermission(mApp,
4820 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4821 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004822 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004823 .setCallingPid(Binder.getCallingPid())
4824 .setCallingUid(Binder.getCallingUid())
4825 .setMethod("requestNetworkScan")
4826 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4827 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004828 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004829 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004830 if (e != null) {
4831 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4832 throw e;
4833 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004834 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004835 return TelephonyScanManager.INVALID_SCAN_ID;
4836 }
4837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 }
Hall Liu912dfd32019-04-25 14:02:26 -07004839 int callingUid = Binder.getCallingUid();
4840 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004841 final long identity = Binder.clearCallingIdentity();
4842 try {
4843 return mNetworkScanRequestTracker.startNetworkScan(
4844 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004845 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004846 } finally {
4847 Binder.restoreCallingIdentity(identity);
4848 }
yinxu504e1392017-04-12 16:03:22 -07004849 }
4850
Hall Liub2ac8ef2019-02-28 15:56:23 -08004851 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004852 NetworkScanRequest request, int subId) {
4853 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4854 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4855 boolean hasNetworkScanPermission =
4856 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4857 == PERMISSION_GRANTED;
4858
4859 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4860 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4861 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004862 }
4863
4864 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4865 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004866 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4867 return new SecurityException("Specific channels must not be"
4868 + " scanned without location access.");
4869 }
4870 }
4871 }
4872
Hall Liub2ac8ef2019-02-28 15:56:23 -08004873 return null;
4874 }
4875
yinxu504e1392017-04-12 16:03:22 -07004876 /**
4877 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004878 *
4879 * @param subId id of the subscription
4880 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004881 */
4882 @Override
4883 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4885 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886
Hall Liu912dfd32019-04-25 14:02:26 -07004887 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004890 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 } finally {
4892 Binder.restoreCallingIdentity(identity);
4893 }
yinxu504e1392017-04-12 16:03:22 -07004894 }
4895
4896 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004897 * Get the calculated preferred network type.
4898 * Used for debugging incorrect network type.
4899 *
4900 * @return the preferred network type, defined in RILConstants.java.
4901 */
4902 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004903 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004904 final Phone defaultPhone = getDefaultPhone();
4905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004906 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004907 return RILConstants.PREFERRED_NETWORK_MODE;
4908 }
4909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004913 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
Junda Liu84d15a22014-07-02 11:21:04 -07004917 }
4918
4919 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004920 * Get the preferred network type.
4921 * Used for device configuration by some CDMA operators.
4922 *
4923 * @return the preferred network type, defined in RILConstants.java.
4924 */
4925 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004926 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004927 TelephonyPermissions
4928 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4929 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 if (DBG) log("getPreferredNetworkType");
4934 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4935 int networkType = (result != null ? result[0] : -1);
4936 if (DBG) log("getPreferredNetworkType: " + networkType);
4937 return networkType;
4938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004941 }
4942
4943 /**
4944 * Set the preferred network type.
4945 * Used for device configuration by some CDMA operators.
4946 *
4947 * @param networkType the preferred network type, defined in RILConstants.java.
4948 * @return true on success; false on any failure.
4949 */
4950 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004951 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4953 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954
4955 final long identity = Binder.clearCallingIdentity();
4956 try {
4957 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4958 Boolean success = (Boolean) sendRequest(
4959 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4960 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4961 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004962 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4964 }
4965 return success;
4966 } finally {
4967 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004968 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004969 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004970
4971 /**
Miaoa84611c2019-03-15 09:21:10 +08004972 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004973 *
Miaoa84611c2019-03-15 09:21:10 +08004974 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004975 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004976 * @hide
4977 */
4978 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004979 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004982 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 try {
Miaoa84611c2019-03-15 09:21:10 +08004984 if (phone != null) {
4985 return phone.hasMatchedTetherApnSetting();
4986 } else {
4987 return false;
4988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004991 }
Junda Liu475951f2014-11-07 16:45:03 -08004992 }
4993
4994 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004995 * Set mobile data enabled
4996 * Used by the user through settings etc to turn on/off mobile data
4997 *
4998 * @param enable {@code true} turn turn data on, else {@code false}
4999 */
5000 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005001 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5003 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
5005 final long identity = Binder.clearCallingIdentity();
5006 try {
5007 int phoneId = mSubscriptionController.getPhoneId(subId);
5008 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5009 Phone phone = PhoneFactory.getPhone(phoneId);
5010 if (phone != null) {
5011 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005012 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005014 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015 }
5016 } finally {
5017 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005018 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005019 }
5020
5021 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005022 * Get the user enabled state of Mobile Data.
5023 *
5024 * TODO: remove and use isUserDataEnabled.
5025 * This can't be removed now because some vendor codes
5026 * calls through ITelephony directly while they should
5027 * use TelephonyManager.
5028 *
5029 * @return true on enabled
5030 */
5031 @Override
5032 public boolean getDataEnabled(int subId) {
5033 return isUserDataEnabled(subId);
5034 }
5035
5036 /**
5037 * Get whether mobile data is enabled per user setting.
5038 *
5039 * There are other factors deciding whether mobile data is actually enabled, but they are
5040 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005041 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005042 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005043 *
5044 * @return {@code true} if data is enabled else {@code false}
5045 */
5046 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005047 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005048 try {
5049 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5050 null);
5051 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5053 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055
5056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 int phoneId = mSubscriptionController.getPhoneId(subId);
5059 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5060 Phone phone = PhoneFactory.getPhone(phoneId);
5061 if (phone != null) {
5062 boolean retVal = phone.isUserDataEnabled();
5063 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5064 return retVal;
5065 } else {
5066 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5067 return false;
5068 }
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005071 }
5072 }
5073
5074 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005075 * Checks if the device is capable of mobile data by considering whether whether the
5076 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5077 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005078 *
Shuo Qian985d1232020-01-08 14:30:06 -08005079 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005080 */
5081 @Override
5082 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005083 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084
5085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 int phoneId = mSubscriptionController.getPhoneId(subId);
5088 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5089 Phone phone = PhoneFactory.getPhone(phoneId);
5090 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005091 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5093 return retVal;
5094 } else {
5095 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5096 return false;
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005100 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005101 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005102
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005103 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5104 Phone phone) {
5105 //load access rules from carrier configs, and check those as well: b/139133814
5106 SubscriptionController subController = SubscriptionController.getInstance();
5107 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5108 || subController == null) return privilegeFromSim;
5109
5110 int uid = Binder.getCallingUid();
5111 PackageManager pkgMgr = phone.getContext().getPackageManager();
5112 String[] packages = pkgMgr.getPackagesForUid(uid);
5113
5114 final long identity = Binder.clearCallingIdentity();
5115 try {
5116 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5117 SubscriptionManager subManager = (SubscriptionManager)
5118 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5119 for (String pkg : packages) {
5120 if (subManager.canManageSubscription(subInfo, pkg)) {
5121 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5122 }
5123 }
5124 return privilegeFromSim;
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
5128 }
5129
5130 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5131 String pkgName) {
5132 //load access rules from carrier configs, and check those as well: b/139133814
5133 SubscriptionController subController = SubscriptionController.getInstance();
5134 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5135 || subController == null) return privilegeFromSim;
5136
5137 final long identity = Binder.clearCallingIdentity();
5138 try {
5139 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5140 SubscriptionManager subManager = (SubscriptionManager)
5141 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5142 return subManager.canManageSubscription(subInfo, pkgName)
5143 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
5147 }
5148
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005149 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005150 public int getCarrierPrivilegeStatus(int subId) {
5151 final Phone phone = getPhone(subId);
5152 if (phone == null) {
5153 loge("getCarrierPrivilegeStatus: Invalid subId");
5154 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5155 }
5156 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005157 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005158 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005159 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5160 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005161
5162 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5163 card.getCarrierPrivilegeStatusForCurrentTransaction(
5164 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005165 }
Junda Liu29340342014-07-10 15:23:27 -07005166
5167 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005168 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5169 final Phone phone = getPhone(subId);
5170 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005171 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005172 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5173 }
5174 UiccProfile profile =
5175 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5176 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005177 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005178 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5179 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005180 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5181 profile.getCarrierPrivilegeStatusForUid(
5182 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005183 }
5184
5185 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005186 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5187 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005188 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005189 }
5190
5191 int phoneId = SubscriptionManager.getPhoneId(subId);
5192 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005193 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005194 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005195 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5196 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005197 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5198 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5199 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005200 }
5201
5202 @Override
5203 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005204 if (TextUtils.isEmpty(pkgName))
5205 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005206 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5207 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5208 UiccCard card = UiccController.getInstance().getUiccCard(i);
5209 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005210 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005211 continue;
5212 }
5213
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005214 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5215 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5216 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005217 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5218 break;
5219 }
5220 }
5221
5222 return result;
Junda Liu29340342014-07-10 15:23:27 -07005223 }
Derek Tan89e89d42014-07-08 17:00:10 -07005224
5225 @Override
Junda Liue64de782015-04-16 17:19:16 -07005226 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5227 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5228 loge("phoneId " + phoneId + " is not valid.");
5229 return null;
5230 }
5231 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005232 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005233 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005234 return null ;
5235 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005236 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005237 }
5238
Amith Yamasani6e118872016-02-19 12:53:51 -08005239 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005240 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005241 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005242 List<String> privilegedPackages = new ArrayList<>();
5243 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005244 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5245 // has UICC in that slot.
5246 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005247 if (card.hasCarrierPrivilegeRules()) {
5248 if (packages == null) {
5249 // Only check packages in user 0 for now
5250 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005251 PackageManager.MATCH_DISABLED_COMPONENTS
5252 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005253 | PackageManager.GET_SIGNING_CERTIFICATES,
5254 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005255 }
5256 for (int p = packages.size() - 1; p >= 0; p--) {
5257 PackageInfo pkgInfo = packages.get(p);
5258 if (pkgInfo != null && pkgInfo.packageName != null
5259 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005260 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005261 privilegedPackages.add(pkgInfo.packageName);
5262 }
5263 }
5264 }
5265 }
5266 return privilegedPackages;
5267 }
5268
chen xuf7e9fe82019-05-09 19:31:02 -07005269 @Override
5270 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005271 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5272
5273 final long identity = Binder.clearCallingIdentity();
5274
chen xuf7e9fe82019-05-09 19:31:02 -07005275 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005276 try {
5277 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5278 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5279 }
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005282 }
5283 return privilegedPackages;
5284 }
5285
Wink Savilleb564aae2014-10-23 10:18:09 -07005286 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005287 final Phone phone = getPhone(subId);
5288 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005289 if (card == null) {
5290 loge("getIccId: No UICC");
5291 return null;
5292 }
5293 String iccId = card.getIccId();
5294 if (TextUtils.isEmpty(iccId)) {
5295 loge("getIccId: ICC ID is null or empty.");
5296 return null;
5297 }
5298 return iccId;
5299 }
5300
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005301 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005302 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5303 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005304 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5305 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 final long identity = Binder.clearCallingIdentity();
5308 try {
5309 final String iccId = getIccId(subId);
5310 final Phone phone = getPhone(subId);
5311 if (phone == null) {
5312 return false;
5313 }
5314 final String subscriberId = phone.getSubscriberId();
5315
5316 if (DBG_MERGE) {
5317 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5318 + subscriberId + " to " + number);
5319 }
5320
5321 if (TextUtils.isEmpty(iccId)) {
5322 return false;
5323 }
5324
5325 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5326
5327 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5328 if (alphaTag == null) {
5329 editor.remove(alphaTagPrefKey);
5330 } else {
5331 editor.putString(alphaTagPrefKey, alphaTag);
5332 }
5333
5334 // Record both the line number and IMSI for this ICCID, since we need to
5335 // track all merged IMSIs based on line number
5336 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5337 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5338 if (number == null) {
5339 editor.remove(numberPrefKey);
5340 editor.remove(subscriberPrefKey);
5341 } else {
5342 editor.putString(numberPrefKey, number);
5343 editor.putString(subscriberPrefKey, subscriberId);
5344 }
5345
5346 editor.commit();
5347 return true;
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005350 }
Derek Tan7226c842014-07-02 17:42:23 -07005351 }
5352
5353 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005354 public String getLine1NumberForDisplay(int subId, String callingPackage,
5355 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005356 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005357 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005358 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005359 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005360 return null;
5361 }
Derek Tan97ebb422014-09-05 16:55:38 -07005362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 final long identity = Binder.clearCallingIdentity();
5364 try {
5365 String iccId = getIccId(subId);
5366 if (iccId != null) {
5367 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5368 if (DBG_MERGE) {
5369 log("getLine1NumberForDisplay returning "
5370 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5371 }
5372 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5375 return null;
5376 } finally {
5377 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005378 }
Derek Tan7226c842014-07-02 17:42:23 -07005379 }
5380
5381 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005382 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5383 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005385 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005386 return null;
5387 }
Derek Tan97ebb422014-09-05 16:55:38 -07005388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 String iccId = getIccId(subId);
5392 if (iccId != null) {
5393 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5394 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5395 }
5396 return null;
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005399 }
Derek Tan7226c842014-07-02 17:42:23 -07005400 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005401
5402 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005403 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5404 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005405 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5406 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005408 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005409 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005410 return null;
5411 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005412
Jordan Liub49b04b2019-05-06 14:45:15 -07005413 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5414 // the process, where TelephonyManager was instantiated.
5415 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005416 final long identity = Binder.clearCallingIdentity();
5417 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005418 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 final TelephonyManager tele = TelephonyManager.from(context);
5420 final SubscriptionManager sub = SubscriptionManager.from(context);
5421
5422 // Figure out what subscribers are currently active
5423 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424
Jordan Liub49b04b2019-05-06 14:45:15 -07005425 // Only consider subs which match the current subId
5426 // This logic can be simplified. See b/131189269 for progress.
5427 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005428 activeSubscriberIds.add(tele.getSubscriberId(subId));
5429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430
5431 // First pass, find a number override for an active subscriber
5432 String mergeNumber = null;
5433 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5434 for (String key : prefs.keySet()) {
5435 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5436 final String subscriberId = (String) prefs.get(key);
5437 if (activeSubscriberIds.contains(subscriberId)) {
5438 final String iccId = key.substring(
5439 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5440 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5441 mergeNumber = (String) prefs.get(numberKey);
5442 if (DBG_MERGE) {
5443 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5444 + " for active subscriber " + subscriberId);
5445 }
5446 if (!TextUtils.isEmpty(mergeNumber)) {
5447 break;
5448 }
5449 }
5450 }
5451 }
5452
5453 // Shortcut when no active merged subscribers
5454 if (TextUtils.isEmpty(mergeNumber)) {
5455 return null;
5456 }
5457
5458 // Second pass, find all subscribers under that line override
5459 final ArraySet<String> result = new ArraySet<>();
5460 for (String key : prefs.keySet()) {
5461 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5462 final String number = (String) prefs.get(key);
5463 if (mergeNumber.equals(number)) {
5464 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5465 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5466 final String subscriberId = (String) prefs.get(subscriberKey);
5467 if (!TextUtils.isEmpty(subscriberId)) {
5468 result.add(subscriberId);
5469 }
5470 }
5471 }
5472 }
5473
5474 final String[] resultArray = result.toArray(new String[result.size()]);
5475 Arrays.sort(resultArray);
5476 if (DBG_MERGE) {
5477 Slog.d(LOG_TAG,
5478 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5479 }
5480 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005483 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005484 }
5485
5486 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005487 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5488 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5489
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 final TelephonyManager telephonyManager = mApp.getSystemService(
5493 TelephonyManager.class);
5494 String subscriberId = telephonyManager.getSubscriberId(subId);
5495 if (subscriberId == null) {
5496 if (DBG) {
5497 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5498 + subId);
5499 }
5500 return null;
5501 }
5502
5503 final SubscriptionInfo info = SubscriptionController.getInstance()
5504 .getSubscriptionInfo(subId);
5505 final ParcelUuid groupUuid = info.getGroupUuid();
5506 // If it doesn't belong to any group, return just subscriberId of itself.
5507 if (groupUuid == null) {
5508 return new String[]{subscriberId};
5509 }
5510
5511 // Get all subscriberIds from the group.
5512 final List<String> mergedSubscriberIds = new ArrayList<>();
5513 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005514 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5515 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005516 for (SubscriptionInfo subInfo : groupInfos) {
5517 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5518 if (subscriberId != null) {
5519 mergedSubscriberIds.add(subscriberId);
5520 }
5521 }
5522
5523 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5524 } finally {
5525 Binder.restoreCallingIdentity(identity);
5526
5527 }
5528 }
5529
5530 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005531 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005532 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5533 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534
5535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 final Phone phone = getPhone(subId);
5538 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005542 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005543
5544 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005545 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005546 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5547 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005548 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549
5550 final long identity = Binder.clearCallingIdentity();
5551 try {
5552 final Phone phone = getPhone(subId);
5553 if (phone == null) {
5554 return false;
5555 }
5556 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5557 cdmaNonRoamingList);
5558 } finally {
5559 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005560 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005561 }
5562
5563 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005564 @Deprecated
5565 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5566 enforceModifyPermission();
5567
5568 int returnValue = 0;
5569 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005570 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005571 if(result.exception == null) {
5572 if (result.result != null) {
5573 byte[] responseData = (byte[])(result.result);
5574 if(responseData.length > oemResp.length) {
5575 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5576 responseData.length + "bytes. Buffer Size is " +
5577 oemResp.length + "bytes.");
5578 }
5579 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5580 returnValue = responseData.length;
5581 }
5582 } else {
5583 CommandException ex = (CommandException) result.exception;
5584 returnValue = ex.getCommandError().ordinal();
5585 if(returnValue > 0) returnValue *= -1;
5586 }
5587 } catch (RuntimeException e) {
5588 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5589 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5590 if(returnValue > 0) returnValue *= -1;
5591 }
5592
5593 return returnValue;
5594 }
5595
5596 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005597 public void setRadioCapability(RadioAccessFamily[] rafs) {
5598 try {
5599 ProxyController.getInstance().setRadioCapability(rafs);
5600 } catch (RuntimeException e) {
5601 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5602 }
5603 }
5604
5605 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005606 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005607 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005608 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005609 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005610 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
chen xub97461a2018-10-26 14:17:57 -07005614 TelephonyPermissions
5615 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5616 mApp, phone.getSubId(), "getRadioAccessFamily");
5617 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
chen xub97461a2018-10-26 14:17:57 -07005621 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005622 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005623
5624 @Override
5625 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005626 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
5629 final long identity = Binder.clearCallingIdentity();
5630 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005631 ImsManager.getInstance(defaultPhone.getContext(),
5632 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005636 }
5637
5638 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005639 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005640 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5642 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005643 return false;
5644 }
Svet Ganovb320e182015-04-16 12:30:10 -07005645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 // Check the user preference and the system-level IMS setting. Even if the user has
5649 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5650 // In the long run, we may instead need to check if there exists a connection service
5651 // which can support video calling.
5652 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005653 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 return imsManager.isVtEnabledByPlatform()
5655 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5656 && imsManager.isVtEnabledByUser();
5657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005660 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005661
Andrew Leea1239f22015-03-02 17:44:07 -08005662 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005663 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5664 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005666 mApp, subId, callingPackage, callingFeatureId,
5667 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 return false;
5669 }
5670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 CarrierConfigManager configManager =
5674 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005675 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
Andrew Leea1239f22015-03-02 17:44:07 -08005680 }
5681
5682 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005683 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005685 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 return false;
5687 }
5688
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 CarrierConfigManager configManager =
5692 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005693 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
Andrew Leea1239f22015-03-02 17:44:07 -08005698 }
5699
Andrew Lee9431b832015-03-09 18:46:45 -07005700 @Override
5701 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005702 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005703 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005704 }
5705
5706 @Override
5707 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 final long identity = Binder.clearCallingIdentity();
5709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005710 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
Andrew Lee9431b832015-03-09 18:46:45 -07005714 }
5715
Hall Liuf6668912018-10-31 17:05:23 -07005716 /**
5717 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5718 * support for the feature and device firmware support.
5719 *
5720 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5721 */
5722 @Override
5723 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 final Phone phone = getPhone(subscriptionId);
5726 if (phone == null) {
5727 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5728 return false;
5729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005731 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5733 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005734 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 return isCarrierSupported && isDeviceSupported;
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
Hall Liu98187582018-01-22 19:15:32 -08005739 }
5740
Hall Liuf6668912018-10-31 17:05:23 -07005741 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005742 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5743 * RTT setting, will return true if the device and carrier both support RTT.
5744 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005745 */
5746 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 final long identity = Binder.clearCallingIdentity();
5748 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005749 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005753 }
5754
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005755 @Deprecated
5756 @Override
5757 public String getDeviceId(String callingPackage) {
5758 return getDeviceIdWithFeature(callingPackage, null);
5759 }
5760
Sanket Padawe7310cc72015-01-14 09:53:20 -08005761 /**
5762 * Returns the unique device ID of phone, for example, the IMEI for
5763 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5764 *
5765 * <p>Requires Permission:
5766 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5767 */
5768 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005769 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005770 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005771 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005772 return null;
5773 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005774 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005775 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005776 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005777 return null;
5778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 return phone.getDeviceId();
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
5785 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005786 }
5787
Ping Sunc67b7c22016-03-02 19:16:45 +08005788 /**
5789 * {@hide}
5790 * Returns the IMS Registration Status on a particular subid
5791 *
5792 * @param subId
5793 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005794 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005795 Phone phone = getPhone(subId);
5796 if (phone != null) {
5797 return phone.isImsRegistered();
5798 } else {
5799 return false;
5800 }
5801 }
5802
Santos Cordon7a1885b2015-02-03 11:15:19 -08005803 @Override
5804 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005811 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005812
Tyler Gunnf70ed162019-04-03 15:28:53 -07005813 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005814 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005815 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07005816 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005817 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07005818 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5819 }
5820 final long identity = Binder.clearCallingIdentity();
5821 try {
5822 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
5826 }
5827
5828 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005829 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 Phone phone = getPhone(subscriptionId);
5833 if (phone == null) {
5834 return null;
5835 }
5836 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
5840 }
5841
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005842 /**
5843 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005844 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005845 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 final long identity = Binder.clearCallingIdentity();
5847 try {
5848 Phone phone = getPhone(subId);
5849 if (phone != null) {
5850 return phone.isWifiCallingEnabled();
5851 } else {
5852 return false;
5853 }
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005856 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005857 }
5858
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005859 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005860 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005861 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005862 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 Phone phone = getPhone(subId);
5866 if (phone != null) {
5867 return phone.isVideoEnabled();
5868 } else {
5869 return false;
5870 }
5871 } finally {
5872 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005873 }
5874 }
5875
5876 /**
5877 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5878 * defined in {@link ImsRegistrationImplBase}.
5879 */
5880 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 Phone phone = getPhone(subId);
5884 if (phone != null) {
5885 return phone.getImsRegistrationTech();
5886 } else {
5887 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5888 }
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005891 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005892 }
5893
Stuart Scott8eef64f2015-04-08 15:13:54 -07005894 @Override
5895 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005896 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005897 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5898 return;
5899 }
5900
Svet Ganovcc087f82015-05-12 20:35:54 -07005901 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005902
Svet Ganovcc087f82015-05-12 20:35:54 -07005903 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005904 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5905 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005906 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005907 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005908 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005909 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5910 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005911 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005912 // There has been issues when Sms raw table somehow stores orphan
5913 // fragments. They lead to garbled message when new fragments come
5914 // in and combined with those stale ones. In case this happens again,
5915 // user can reset all network settings which will clean up this table.
5916 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005917 // Clean up IMS settings as well here.
5918 int slotId = getSlotIndex(subId);
5919 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5920 ImsManager.getInstance(mApp, slotId).factoryReset();
5921 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005922
5923 // Erase modem config if erase modem on network setting is enabled.
5924 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5925 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5926 if (configValue != null && Boolean.parseBoolean(configValue)) {
5927 sendEraseModemConfig(getDefaultPhone());
5928 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005929 } finally {
5930 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005931 }
5932 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005933
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005934 private void cleanUpSmsRawTable(Context context) {
5935 ContentResolver resolver = context.getContentResolver();
5936 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5937 resolver.delete(uri, null, null);
5938 }
5939
Narayan Kamath1c496c22015-04-16 14:40:19 +01005940 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005941 public String getSimLocaleForSubscriber(int subId) {
5942 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5943 final Phone phone = getPhone(subId);
5944 if (phone == null) {
5945 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005946 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 final long identity = Binder.clearCallingIdentity();
5949 try {
chen xu5d3637b2019-01-21 23:31:38 -08005950 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005951 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08005952 if (info == null) {
5953 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5954 return null;
5955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 // Try and fetch the locale from the carrier properties or from the SIM language
5957 // preferences (EF-PL and EF-LI)...
5958 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005960 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5961 if (localeFromDefaultSim != null) {
5962 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5963 if (DBG) log("Using locale from subId: " + subId + " locale: "
5964 + localeFromDefaultSim);
5965 return localeFromDefaultSim.toLanguageTag();
5966 } else {
5967 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 }
5969 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 // The SIM language preferences only store a language (e.g. fr = French), not an
5972 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5973 // the SIM and carrier preferences does not include a country we add the country
5974 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08005975 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005977 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 return mccLocale.toLanguageTag();
5979 }
5980
5981 if (DBG) log("No locale found - returning null");
5982 return null;
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005986 }
5987
5988 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005989 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
5990 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01005991 }
5992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 /**
5994 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5995 */
5996 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005997 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
5998 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01005999 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006000
Chenjie Yu1ba97252018-01-11 18:16:20 -08006001 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006002 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006003
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006004 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006005 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6006 * representing the state of the modem.
6007 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006008 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6009 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006010 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006011 */
6012 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006013 public void requestModemActivityInfo(ResultReceiver result) {
6014 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006015 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016
6017 final long identity = Binder.clearCallingIdentity();
6018 try {
6019 ModemActivityInfo ret = null;
6020 synchronized (mLastModemActivityInfo) {
6021 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6022 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006023 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006024 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006026 int[] txTimeMs = info.getTransmitTimeMillis();
6027 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006029 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 }
6031 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006032 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6033 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 mLastModemActivityInfo.setIdleTimeMillis(
6035 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006036 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6037 mLastModemActivityInfo.setReceiveTimeMillis(
6038 info.getReceiveTimeMillis() + mLastModemActivityInfo
6039 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006040 }
Chen Xu13851032019-09-10 18:49:52 -07006041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6043 mLastModemActivityInfo.getSleepTimeMillis(),
6044 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006045 mLastModemActivityInfo.getTransmitTimeMillis(),
6046 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 Bundle bundle = new Bundle();
6049 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6050 result.send(0, bundle);
6051 } finally {
6052 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006053 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006054 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006055
Siddharth Rayb8114062018-06-17 15:02:38 -07006056 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6057 // less than total activity duration.
6058 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6059 if (info == null) {
6060 return false;
6061 }
6062 int activityDurationMs =
6063 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6064 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006065 int[] txTimeMs = info.getTransmitTimeMillis();
6066 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6067 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006068 }
6069 return (info.isValid()
6070 && (info.getSleepTimeMillis() <= activityDurationMs)
6071 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006072 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006073 && (totalTxTimeMs <= activityDurationMs));
6074 }
6075
Jack Yu85bd38a2015-11-09 11:34:32 -08006076 /**
6077 * {@hide}
6078 * Returns the service state information on specified subscription.
6079 */
6080 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006081 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6082 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006084 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006085 return null;
6086 }
6087
Hall Liuf19c44f2018-11-27 14:38:17 -08006088 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6089 LocationAccessPolicy.checkLocationPermission(mApp,
6090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6091 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006092 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006093 .setCallingPid(Binder.getCallingPid())
6094 .setCallingUid(Binder.getCallingUid())
6095 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006096 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006097 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6098 .build());
6099
6100 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6101 LocationAccessPolicy.checkLocationPermission(mApp,
6102 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6103 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006104 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006105 .setCallingPid(Binder.getCallingPid())
6106 .setCallingUid(Binder.getCallingUid())
6107 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006108 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006109 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6110 .build());
6111 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6112 boolean hasFinePermission =
6113 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6114 boolean hasCoarsePermission =
6115 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 final long identity = Binder.clearCallingIdentity();
6118 try {
6119 final Phone phone = getPhone(subId);
6120 if (phone == null) {
6121 return null;
6122 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006123
Hall Liuf19c44f2018-11-27 14:38:17 -08006124 ServiceState ss = phone.getServiceState();
6125
6126 // Scrub out the location info in ServiceState depending on what level of access
6127 // the caller has.
6128 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006129 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6130 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006134 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006135
6136 /**
6137 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6138 *
6139 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6140 * voicemail ringtone.
6141 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6142 * PhoneAccount.
6143 */
6144 @Override
6145 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006146 final long identity = Binder.clearCallingIdentity();
6147 try {
6148 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6149 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006150 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006157 }
6158
6159 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006160 * Sets the per-account voicemail ringtone.
6161 *
6162 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6163 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6164 *
6165 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6166 * voicemail ringtone.
6167 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6168 * PhoneAccount.
6169 */
6170 @Override
6171 public void setVoicemailRingtoneUri(String callingPackage,
6172 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006173 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006174 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006175 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6176 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6178 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6179 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181
6182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6185 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006186 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187 }
6188 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006191 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006192 }
6193
6194 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006195 * Returns whether vibration is set for voicemail notification in Phone settings.
6196 *
6197 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6198 * voicemail vibration setting.
6199 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6200 */
6201 @Override
6202 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 final long identity = Binder.clearCallingIdentity();
6204 try {
6205 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6206 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006207 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006214 }
6215
Youhan Wange64578a2016-05-02 15:32:42 -07006216 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006217 * Sets the per-account voicemail vibration.
6218 *
6219 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6220 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6221 *
6222 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6223 * voicemail vibration setting.
6224 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6225 * specific PhoneAccount.
6226 */
6227 @Override
6228 public void setVoicemailVibrationEnabled(String callingPackage,
6229 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006230 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006231 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006232 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6233 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6235 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6236 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006237 }
6238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6242 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006243 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 }
6245 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6246 } finally {
6247 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006248 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006249 }
6250
6251 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006252 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6253 *
6254 * @throws SecurityException if the caller does not have the required permission
6255 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006256 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006257 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006258 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006259 }
6260
6261 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006262 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6263 * permission.
6264 *
6265 * @throws SecurityException if the caller does not have the required permission
6266 */
6267 private void enforceSendSmsPermission() {
6268 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6269 }
6270
6271 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006272 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006273 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006274 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006275 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006276 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 final long identity = Binder.clearCallingIdentity();
6278 try {
6279 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006280 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 if (componentName == null) {
6282 throw new SecurityException(
6283 "Caller not current active visual voicemail package[null]");
6284 }
6285 String vvmPackage = componentName.getPackageName();
6286 if (!callingPackage.equals(vvmPackage)) {
6287 throw new SecurityException("Caller not current active visual voicemail package["
6288 + vvmPackage + "]");
6289 }
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006292 }
6293 }
6294
6295 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006296 * Return the application ID for the app type.
6297 *
6298 * @param subId the subscription ID that this request applies to.
6299 * @param appType the uicc app type.
6300 * @return Application ID for specificied app type, or null if no uicc.
6301 */
6302 @Override
6303 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006304 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006305 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306
6307 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006308 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 if (phone == null) {
6310 return null;
6311 }
6312 String aid = null;
6313 try {
6314 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6315 .getApplicationByType(appType).getAid();
6316 } catch (Exception e) {
6317 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6318 }
6319 return aid;
6320 } finally {
6321 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006322 }
Youhan Wange64578a2016-05-02 15:32:42 -07006323 }
6324
Youhan Wang4001d252016-05-11 10:29:41 -07006325 /**
6326 * Return the Electronic Serial Number.
6327 *
6328 * @param subId the subscription ID that this request applies to.
6329 * @return ESN or null if error.
6330 */
6331 @Override
6332 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006333 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006334 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335
6336 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006337 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 if (phone == null) {
6339 return null;
6340 }
6341 String esn = null;
6342 try {
6343 esn = phone.getEsn();
6344 } catch (Exception e) {
6345 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6346 }
6347 return esn;
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006350 }
Youhan Wang4001d252016-05-11 10:29:41 -07006351 }
6352
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006353 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006354 * Return the Preferred Roaming List Version.
6355 *
6356 * @param subId the subscription ID that this request applies to.
6357 * @return PRLVersion or null if error.
6358 */
6359 @Override
6360 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006361 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006362 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006365 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366 if (phone == null) {
6367 return null;
6368 }
6369 String cdmaPrlVersion = null;
6370 try {
6371 cdmaPrlVersion = phone.getCdmaPrlVersion();
6372 } catch (Exception e) {
6373 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6374 }
6375 return cdmaPrlVersion;
6376 } finally {
6377 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006378 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006379 }
6380
6381 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006382 * Get snapshot of Telephony histograms
6383 * @return List of Telephony histograms
6384 * @hide
6385 */
6386 @Override
6387 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6389 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390
6391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 return RIL.getTelephonyRILTimingHistograms();
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006397 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006398
6399 /**
6400 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006401 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6402 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006403 * Require system privileges. In the future we may add this to carrier APIs.
6404 *
Michele Berionne482f8202018-11-27 18:57:59 -08006405 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006406 */
6407 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006408 @TelephonyManager.SetCarrierRestrictionResult
6409 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006410 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006411 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006412
Michele Berionne482f8202018-11-27 18:57:59 -08006413 if (carrierRestrictionRules == null) {
6414 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006415 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 final long identity = Binder.clearCallingIdentity();
6418 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006419 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006420 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006424 }
6425
6426 /**
6427 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006428 * Get the allowed carrier list and the excluded carrier list, including the priority between
6429 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006430 * Require system privileges. In the future we may add this to carrier APIs.
6431 *
Michele Berionne482f8202018-11-27 18:57:59 -08006432 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006433 */
6434 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006435 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006436 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006437 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438
6439 final long identity = Binder.clearCallingIdentity();
6440 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006441 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6442 if (response instanceof CarrierRestrictionRules) {
6443 return (CarrierRestrictionRules) response;
6444 }
6445 // Response is an Exception of some kind,
6446 // which is signalled to the user as a NULL retval
6447 return null;
6448 } catch (Exception e) {
6449 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6450 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006454 }
6455
fionaxu59545b42016-05-25 15:53:37 -07006456 /**
6457 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6458 * @param subId the subscription ID that this action applies to.
6459 * @param enabled control enable or disable metered apns.
6460 * {@hide}
6461 */
6462 @Override
6463 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6464 enforceModifyPermission();
6465 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006466
6467 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006468 if (phone == null) {
6469 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6470 return;
6471 }
6472 try {
6473 phone.carrierActionSetMeteredApnsEnabled(enabled);
6474 } catch (Exception e) {
6475 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476 } finally {
6477 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006478 }
6479 }
6480
6481 /**
6482 * Action set from carrier signalling broadcast receivers to enable/disable radio
6483 * @param subId the subscription ID that this action applies to.
6484 * @param enabled control enable or disable radio.
6485 * {@hide}
6486 */
6487 @Override
6488 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6489 enforceModifyPermission();
6490 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491
6492 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006493 if (phone == null) {
6494 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6495 return;
6496 }
6497 try {
6498 phone.carrierActionSetRadioEnabled(enabled);
6499 } catch (Exception e) {
6500 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 } finally {
6502 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006503 }
6504 }
6505
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006506 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006507 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6508 * network status based on which carrier apps could apply actions accordingly,
6509 * enable/disable default url handler for example.
6510 *
6511 * @param subId the subscription ID that this action applies to.
6512 * @param report control start/stop reporting the default network status.
6513 * {@hide}
6514 */
6515 @Override
6516 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6517 enforceModifyPermission();
6518 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519
6520 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006521 if (phone == null) {
6522 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6523 return;
6524 }
6525 try {
6526 phone.carrierActionReportDefaultNetworkStatus(report);
6527 } catch (Exception e) {
6528 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006531 }
6532 }
6533
6534 /**
fionaxud9622282017-07-17 17:51:30 -07006535 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6536 * @param subId the subscription ID that this action applies to.
6537 * {@hide}
6538 */
6539 @Override
6540 public void carrierActionResetAll(int subId) {
6541 enforceModifyPermission();
6542 final Phone phone = getPhone(subId);
6543 if (phone == null) {
6544 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6545 return;
6546 }
6547 try {
6548 phone.carrierActionResetAll();
6549 } catch (Exception e) {
6550 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6551 }
6552 }
6553
6554 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006555 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6556 * bug report is being generated.
6557 */
6558 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006559 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006560 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6561 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006562 writer.println("Permission Denial: can't dump Phone from pid="
6563 + Binder.getCallingPid()
6564 + ", uid=" + Binder.getCallingUid()
6565 + "without permission "
6566 + android.Manifest.permission.DUMP);
6567 return;
6568 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006569 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006570 }
Jack Yueb89b242016-06-22 13:27:47 -07006571
Brad Ebingerdac2f002018-04-03 15:17:52 -07006572 @Override
6573 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6574 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6575 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006576 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6577 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006578 }
6579
Jack Yueb89b242016-06-22 13:27:47 -07006580 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006581 * Get aggregated video call data usage since boot.
6582 *
6583 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6584 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006585 * {@hide}
6586 */
6587 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006588 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006589 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6590 null);
6591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 final long identity = Binder.clearCallingIdentity();
6593 try {
6594 // NetworkStatsService keeps tracking the active network interface and identity. It
6595 // records the delta with the corresponding network identity.
6596 // We just return the total video call data usage snapshot since boot.
6597 Phone phone = getPhone(subId);
6598 if (phone != null) {
6599 return phone.getVtDataUsage(perUidStats);
6600 }
6601 return null;
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006604 }
Jack Yueb89b242016-06-22 13:27:47 -07006605 }
Jack Yu75ab2952016-07-08 14:29:33 -07006606
6607 /**
6608 * Policy control of data connection. Usually used when data limit is passed.
6609 * @param enabled True if enabling the data, otherwise disabling.
6610 * @param subId Subscription index
6611 * {@hide}
6612 */
6613 @Override
6614 public void setPolicyDataEnabled(boolean enabled, int subId) {
6615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 Phone phone = getPhone(subId);
6620 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006621 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 }
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006625 }
6626 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006627
6628 /**
6629 * Get Client request stats
6630 * @return List of Client Request Stats
6631 * @hide
6632 */
6633 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006634 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6635 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006637 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006638 return null;
6639 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006640 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642 final long identity = Binder.clearCallingIdentity();
6643 try {
6644 if (phone != null) {
6645 return phone.getClientRequestStats();
6646 }
6647
6648 return null;
6649 } finally {
6650 Binder.restoreCallingIdentity(identity);
6651 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006652 }
6653
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006654 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006655 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006656 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006657 }
Jack Yueb4124c2017-02-16 15:32:43 -08006658
6659 /**
Grace Chen70990072017-03-24 17:21:30 -07006660 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006661 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006662 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006663 * @param state State of SIM (power down, power up, pass through)
6664 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6665 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6666 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006667 *
6668 **/
6669 @Override
Grace Chen70990072017-03-24 17:21:30 -07006670 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006671 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006672 Phone phone = PhoneFactory.getPhone(slotIndex);
6673
vagdeviaf9a5b92018-08-15 16:01:53 -07006674 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676 final long identity = Binder.clearCallingIdentity();
6677 try {
6678 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006679 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 }
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006683 }
6684 }
Shuo Qiandd210312017-04-12 22:11:33 +00006685
Tyler Gunn65d45c22017-06-05 11:22:26 -07006686 private boolean isUssdApiAllowed(int subId) {
6687 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006688 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006689 if (configManager == null) {
6690 return false;
6691 }
6692 PersistableBundle pb = configManager.getConfigForSubId(subId);
6693 if (pb == null) {
6694 return false;
6695 }
6696 return pb.getBoolean(
6697 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6698 }
6699
Shuo Qiandd210312017-04-12 22:11:33 +00006700 /**
6701 * Check if phone is in emergency callback mode
6702 * @return true if phone is in emergency callback mode
6703 * @param subId sub id
6704 */
goneil9c5f4872017-12-05 14:07:56 -08006705 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006706 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006707 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006708 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006709
6710 final long identity = Binder.clearCallingIdentity();
6711 try {
6712 if (phone != null) {
6713 return phone.isInEcm();
6714 } else {
6715 return false;
6716 }
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006719 }
6720 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006721
6722 /**
6723 * Get the current signal strength information for the given subscription.
6724 * Because this information is not updated when the device is in a low power state
6725 * it should not be relied-upon to be current.
6726 * @param subId Subscription index
6727 * @return the most recent cached signal strength info from the modem
6728 */
6729 @Override
6730 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 Phone p = getPhone(subId);
6734 if (p == null) {
6735 return null;
6736 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 return p.getSignalStrength();
6739 } finally {
6740 Binder.restoreCallingIdentity(identity);
6741 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006742 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006743
Pengquan Meng77b7f132018-08-22 14:49:57 -07006744 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006745 * Get the current modem radio state for the given slot.
6746 * @param slotIndex slot index.
6747 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006748 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006749 * @return the current radio power state from the modem
6750 */
6751 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006752 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006753 Phone phone = PhoneFactory.getPhone(slotIndex);
6754 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6756 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006757 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6758 }
6759
6760 final long identity = Binder.clearCallingIdentity();
6761 try {
6762 return phone.getRadioPowerState();
6763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
6766 }
6767 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6768 }
6769
6770 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006771 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6772 *
6773 * <p>Requires one of the following permissions:
6774 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6775 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6776 * privileges.
6777 *
6778 * @param subId subscription id
6779 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6780 * {@code false}.
6781 */
6782 @Override
6783 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006784 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6785 null /* message */);
6786
Pengquan Menga1bb6272018-09-06 09:59:22 -07006787 boolean isEnabled = false;
6788 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006789 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006790 Phone phone = getPhone(subId);
6791 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006792 } catch (Exception e) {
6793 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6794 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006795 } finally {
6796 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006797 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006798 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006799 }
6800
6801
6802 /**
6803 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6804 *
6805 * <p> Requires permission:
6806 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6807 * privileges.
6808 *
6809 * @param subId subscription id
6810 * @param isEnabled {@code true} means enable, {@code false} means disable.
6811 */
6812 @Override
6813 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6815 mApp, subId, "setDataRoamingEnabled");
6816
Pengquan Menga1bb6272018-09-06 09:59:22 -07006817 final long identity = Binder.clearCallingIdentity();
6818 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006819 Phone phone = getPhone(subId);
6820 if (phone != null) {
6821 phone.setDataRoamingEnabled(isEnabled);
6822 }
6823 } finally {
6824 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006825 }
6826 }
6827
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006828 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006829 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006830 TelephonyPermissions
6831 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006832 mApp, subId, "isManualNetworkSelectionAllowed");
6833
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006834 boolean isAllowed = true;
6835 final long identity = Binder.clearCallingIdentity();
6836 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006837 Phone phone = getPhone(subId);
6838 if (phone != null) {
6839 isAllowed = phone.isCspPlmnEnabled();
6840 }
6841 } finally {
6842 Binder.restoreCallingIdentity(identity);
6843 }
6844 return isAllowed;
6845 }
6846
6847 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006848 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006849 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006850 try {
6851 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006852 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006853 } catch (SecurityException e) {
6854 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6855 // has carrier privileges on an active UICC
6856 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6857 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006858 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006859 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006860 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006861
6862 final long identity = Binder.clearCallingIdentity();
6863 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006864 UiccController uiccController = UiccController.getInstance();
6865 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006866 if (hasReadPermission) {
6867 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006868 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006869
6870 // Remove private info if the caller doesn't have access
6871 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6872 for (UiccCardInfo cardInfo : cardInfos) {
6873 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6874 // is available
6875 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6876 if (card == null || card.getUiccProfile() == null) {
6877 // assume no access if the card or profile is unavailable
6878 filteredInfos.add(cardInfo.getUnprivileged());
6879 continue;
6880 }
6881 UiccProfile profile = card.getUiccProfile();
6882 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6883 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6884 filteredInfos.add(cardInfo);
6885 } else {
6886 filteredInfos.add(cardInfo.getUnprivileged());
6887 }
6888 }
6889 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006890 } finally {
6891 Binder.restoreCallingIdentity(identity);
6892 }
6893 }
6894
6895 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006896 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006897 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899 final long identity = Binder.clearCallingIdentity();
6900 try {
6901 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6902 if (slots == null) {
6903 Rlog.i(LOG_TAG, "slots is null.");
6904 return null;
6905 }
6906
6907 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6908 for (int i = 0; i < slots.length; i++) {
6909 UiccSlot slot = slots[i];
6910 if (slot == null) {
6911 continue;
6912 }
6913
Jordan Liu7be7e652019-05-06 18:55:02 +00006914 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 UiccCard card = slot.getUiccCard();
6916 if (card != null) {
6917 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006918 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006919 cardId = slot.getEid();
6920 if (TextUtils.isEmpty(cardId)) {
6921 cardId = slot.getIccId();
6922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 }
6924
Jordan Liu857451f2019-05-09 16:35:35 -07006925 if (cardId != null) {
6926 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6927 // if cardId is an EID, it's all digits so this is fine
6928 cardId = IccUtils.stripTrailingFs(cardId);
6929 }
6930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 int cardState = 0;
6932 switch (slot.getCardState()) {
6933 case CARDSTATE_ABSENT:
6934 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6935 break;
6936 case CARDSTATE_PRESENT:
6937 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6938 break;
6939 case CARDSTATE_ERROR:
6940 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6941 break;
6942 case CARDSTATE_RESTRICTED:
6943 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6944 break;
6945 default:
6946 break;
6947
6948 }
6949
6950 infos[i] = new UiccSlotInfo(
6951 slot.isActive(),
6952 slot.isEuicc(),
6953 cardId,
6954 cardState,
6955 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006956 slot.isExtendedApduSupported(),
6957 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 }
6959 return infos;
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006962 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006963 }
6964
6965 @Override
6966 public boolean switchSlots(int[] physicalSlots) {
6967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968
6969 final long identity = Binder.clearCallingIdentity();
6970 try {
6971 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6972 } finally {
6973 Binder.restoreCallingIdentity(identity);
6974 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006975 }
Jack Yu4c988042018-02-27 15:30:01 -08006976
6977 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006978 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006979 final long identity = Binder.clearCallingIdentity();
6980 try {
6981 return UiccController.getInstance().getCardIdForDefaultEuicc();
6982 } finally {
6983 Binder.restoreCallingIdentity(identity);
6984 }
6985 }
6986
6987 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006988 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6989 enforceModifyPermission();
6990 final Phone phone = getPhone(subId);
6991 if (phone == null) {
6992 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6993 return;
6994 }
6995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 phone.setRadioIndicationUpdateMode(filters, mode);
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
Jack Yu4c988042018-02-27 15:30:01 -08007002 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007003
7004 /**
goneil47ffb6e2018-04-06 15:40:58 -07007005 * A test API to reload the UICC profile.
7006 *
7007 * <p>Requires that the calling app has permission
7008 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7009 * @hide
7010 */
7011 @Override
7012 public void refreshUiccProfile(int subId) {
7013 enforceModifyPermission();
7014
7015 final long identity = Binder.clearCallingIdentity();
7016 try {
7017 Phone phone = getPhone(subId);
7018 if (phone == null) {
7019 return;
7020 }
7021 UiccCard uiccCard = phone.getUiccCard();
7022 if (uiccCard == null) {
7023 return;
7024 }
7025 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7026 if (uiccProfile == null) {
7027 return;
7028 }
7029 uiccProfile.refresh();
7030 } finally {
7031 Binder.restoreCallingIdentity(identity);
7032 }
7033 }
7034
7035 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007036 * Returns false if the mobile data is disabled by default, otherwise return true.
7037 */
7038 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007039 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007040 }
7041
7042 /**
7043 * Returns true if the data roaming is enabled by default, i.e the system property
7044 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7045 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7046 */
7047 private boolean getDefaultDataRoamingEnabled(int subId) {
7048 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007049 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007050 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007051 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7052 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7053 return isDataRoamingEnabled;
7054 }
7055
7056 /**
7057 * Returns the default network type for the given {@code subId}, if the default network type is
7058 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7059 */
7060 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007061 List<Integer> list = TelephonyProperties.default_network();
7062 int phoneId = mSubscriptionController.getPhoneId(subId);
7063 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7064 return list.get(phoneId);
7065 }
7066 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007067 }
fionaxua13278b2018-03-21 00:08:13 -07007068
7069 @Override
7070 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007071 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007072 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 final Phone phone = getPhone(subId);
7077 if (phone == null) {
7078 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7079 return;
7080 }
chen xueaba88a2019-03-15 13:15:10 -07007081 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7082 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 } finally {
7084 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007085 }
fionaxua13278b2018-03-21 00:08:13 -07007086 }
7087
7088 @Override
7089 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007090 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 final Phone phone = getPhone(subId);
7095 if (phone == null) {
7096 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7097 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7098 }
7099 return phone.getCarrierIdListVersion();
7100 } finally {
7101 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007102 }
fionaxua13278b2018-03-21 00:08:13 -07007103 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007104
7105 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007106 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7107 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007109 mApp, subId, callingPackage, callingFeatureId,
7110 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007111 return -1;
7112 }
7113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7117 } finally {
7118 Binder.restoreCallingIdentity(identity);
7119 }
7120 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007121
7122 @Override
7123 public int getCdmaRoamingMode(int subId) {
7124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7125 mApp, subId, "getCdmaRoamingMode");
7126
7127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7130 } finally {
7131 Binder.restoreCallingIdentity(identity);
7132 }
7133 }
7134
7135 @Override
7136 public boolean setCdmaRoamingMode(int subId, int mode) {
7137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7138 mApp, subId, "setCdmaRoamingMode");
7139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145 }
7146 }
7147
7148 @Override
7149 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7151 mApp, subId, "setCdmaSubscriptionMode");
7152
7153 final long identity = Binder.clearCallingIdentity();
7154 try {
7155 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7156 } finally {
7157 Binder.restoreCallingIdentity(identity);
7158 }
7159 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007160
sqianc5eccab2018-10-19 18:46:41 -07007161 @Override
sqian8c685422019-02-22 15:55:18 -08007162 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007163 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007165 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7166 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007167 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7168 }
7169 final long identity = Binder.clearCallingIdentity();
7170 try {
sqian854d44b2018-12-12 16:48:18 -08007171 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7172 for (Phone phone: PhoneFactory.getPhones()) {
7173 if (phone.getEmergencyNumberTracker() != null
7174 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7175 emergencyNumberListInternal.put(
7176 phone.getSubId(),
7177 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7178 }
sqian11b7a0e2018-12-05 18:48:28 -08007179 }
sqian854d44b2018-12-12 16:48:18 -08007180 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007181 } finally {
7182 Binder.restoreCallingIdentity(identity);
7183 }
sqianc5eccab2018-10-19 18:46:41 -07007184 }
7185
7186 @Override
sqian8c685422019-02-22 15:55:18 -08007187 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007188 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007189 if (!exactMatch) {
7190 TelephonyPermissions
7191 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007192 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007193 }
7194 final long identity = Binder.clearCallingIdentity();
7195 try {
sqian854d44b2018-12-12 16:48:18 -08007196 for (Phone phone: PhoneFactory.getPhones()) {
7197 if (phone.getEmergencyNumberTracker() != null
7198 && phone.getEmergencyNumberTracker() != null) {
7199 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7200 number, exactMatch)) {
7201 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007202 }
7203 }
sqian11b7a0e2018-12-05 18:48:28 -08007204 }
7205 return false;
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
7209 }
7210
sqianf4ca7ed2019-01-15 18:32:07 -08007211 /**
7212 * Update emergency number list for test mode.
7213 */
7214 @Override
7215 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7216 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7217 "updateEmergencyNumberListTestMode");
7218
7219 final long identity = Binder.clearCallingIdentity();
7220 try {
7221 for (Phone phone: PhoneFactory.getPhones()) {
7222 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7223 if (tracker != null) {
7224 tracker.executeEmergencyNumberTestModeCommand(action, num);
7225 }
7226 }
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
7230 }
7231
7232 /**
7233 * Get the full emergency number list for test mode.
7234 */
7235 @Override
7236 public List<String> getEmergencyNumberListTestMode() {
7237 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7238 "getEmergencyNumberListTestMode");
7239
7240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 Set<String> emergencyNumbers = new HashSet<>();
7243 for (Phone phone: PhoneFactory.getPhones()) {
7244 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7245 if (tracker != null) {
7246 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7247 emergencyNumbers.add(num.getNumber());
7248 }
7249 }
7250 }
7251 return new ArrayList<>(emergencyNumbers);
7252 } finally {
7253 Binder.restoreCallingIdentity(identity);
7254 }
7255 }
7256
chen xud6b45bd2018-10-30 22:27:10 -07007257 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007258 public int getEmergencyNumberDbVersion(int subId) {
7259 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7260
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 final Phone phone = getPhone(subId);
7264 if (phone == null) {
7265 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7266 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7267 }
7268 return phone.getEmergencyNumberDbVersion();
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
7272 }
7273
7274 @Override
7275 public void notifyOtaEmergencyNumberDbInstalled() {
7276 enforceModifyPermission();
7277
7278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 for (Phone phone: PhoneFactory.getPhones()) {
7281 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7282 if (tracker != null) {
7283 tracker.updateOtaEmergencyNumberDatabase();
7284 }
7285 }
7286 } finally {
7287 Binder.restoreCallingIdentity(identity);
7288 }
7289 }
7290
7291 @Override
7292 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7293 enforceActiveEmergencySessionPermission();
7294
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 for (Phone phone: PhoneFactory.getPhones()) {
7298 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7299 if (tracker != null) {
7300 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7301 }
7302 }
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
7306 }
7307
7308 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007309 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7310 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7311 Phone phone = getPhone(subId);
7312 if (phone == null) {
7313 return null;
7314 }
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 UiccProfile profile = UiccController.getInstance()
7318 .getUiccProfileForPhone(phone.getPhoneId());
7319 if (profile != null) {
7320 return profile.getCertsFromCarrierPrivilegeAccessRules();
7321 }
7322 } finally {
7323 Binder.restoreCallingIdentity(identity);
7324 }
7325 return null;
7326 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007327
7328 /**
7329 * Enable or disable a modem stack.
7330 */
7331 @Override
7332 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7333 enforceModifyPermission();
7334
7335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 Phone phone = PhoneFactory.getPhone(slotIndex);
7338 if (phone == null) {
7339 return false;
7340 } else {
7341 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7342 }
7343 } finally {
7344 Binder.restoreCallingIdentity(identity);
7345 }
7346 }
Michelecea4cf22018-12-21 15:00:11 -08007347
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007348 /**
7349 * Whether a modem stack is enabled or not.
7350 */
7351 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007352 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7353 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007354 Phone phone = PhoneFactory.getPhone(slotIndex);
7355 if (phone == null) return false;
7356
7357 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007358 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7359 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007360 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7361 }
7362
7363 final long identity = Binder.clearCallingIdentity();
7364 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007365 try {
7366 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7367 } catch (NoSuchElementException ex) {
7368 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7369 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007370 } finally {
7371 Binder.restoreCallingIdentity(identity);
7372 }
7373 }
7374
Michelecea4cf22018-12-21 15:00:11 -08007375 @Override
Michele0ea7d782019-03-19 14:58:42 -07007376 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007377 enforceModifyPermission();
7378
7379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007382 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007383 .commit();
7384 } finally {
7385 Binder.restoreCallingIdentity(identity);
7386 }
7387 }
7388
7389 @Override
Michele0ea7d782019-03-19 14:58:42 -07007390 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007391 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007392 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007393 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7394 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007395 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007396 }
Michelecea4cf22018-12-21 15:00:11 -08007397
7398 final long identity = Binder.clearCallingIdentity();
7399 try {
Michele0ea7d782019-03-19 14:58:42 -07007400 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007401 } finally {
7402 Binder.restoreCallingIdentity(identity);
7403 }
7404 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007405
Michele0ea7d782019-03-19 14:58:42 -07007406 @TelephonyManager.IsMultiSimSupportedResult
7407 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007408 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7409 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7410 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007411 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7412 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007413 }
7414 // Check if the hardware supports multisim functionality. If usage of multisim is not
7415 // supported by the modem, indicate that it is restricted.
7416 PhoneCapability staticCapability =
7417 mPhoneConfigurationManager.getStaticPhoneCapability();
7418 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007419 loge("isMultiSimSupportedInternal: no static configuration available");
7420 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007421 }
7422 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007423 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7424 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007425 }
7426 // Check if support of multiple SIMs is restricted by carrier
7427 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007428 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007429 }
7430
Michele0ea7d782019-03-19 14:58:42 -07007431 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007432 }
7433
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007434 /**
7435 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007436 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7437 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7438 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007439 * @param numOfSims number of active sims we want to switch to
7440 */
7441 @Override
7442 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007443 if (numOfSims == 1) {
7444 enforceModifyPermission();
7445 } else {
7446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7447 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7448 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007449 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007450
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007451 try {
Michele30b57b22019-03-01 12:01:14 -08007452 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007453 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007454 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7455 return;
7456 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007457 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
7460 }
7461 }
7462
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007463 @Override
7464 public boolean isApplicationOnUicc(int subId, int appType) {
7465 enforceReadPrivilegedPermission("isApplicationOnUicc");
7466 Phone phone = getPhone(subId);
7467 if (phone == null) {
7468 return false;
7469 }
7470 final long identity = Binder.clearCallingIdentity();
7471 try {
7472 UiccCard uiccCard = phone.getUiccCard();
7473 if (uiccCard == null) {
7474 return false;
7475 }
7476 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7477 if (uiccProfile == null) {
7478 return false;
7479 }
7480 if (TelephonyManager.APPTYPE_SIM <= appType
7481 && appType <= TelephonyManager.APPTYPE_ISIM) {
7482 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7483 }
7484 return false;
7485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
7488 }
7489
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007490 /**
chen xub4baa772019-04-03 10:23:41 -07007491 * Get whether making changes to modem configurations will trigger reboot.
7492 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007493 */
7494 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007495 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7496 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007498 mApp, subId, callingPackage, callingFeatureId,
7499 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007500 return false;
7501 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7505 } finally {
7506 Binder.restoreCallingIdentity(identity);
7507 }
7508 }
7509
Nathan Harold29f5f052019-02-15 13:41:57 -08007510 private void updateModemStateMetrics() {
7511 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7512 // TODO: check the state for each modem if the api is ready.
7513 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7514 }
7515
Pengquan Meng3889a572019-01-23 11:16:29 -08007516 @Override
7517 public int[] getSlotsMapping() {
7518 enforceReadPrivilegedPermission("getSlotsMapping");
7519
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7523 // All logical slots should have a mapping to a physical slot.
7524 int[] logicalSlotsMapping = new int[phoneCount];
7525 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7526 for (int i = 0; i < slotInfos.length; i++) {
7527 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7528 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7529 }
7530 }
7531 return logicalSlotsMapping;
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
7535 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007536
7537 /**
7538 * Get the IRadio HAL Version
7539 */
7540 @Override
7541 public int getRadioHalVersion() {
7542 Phone phone = getDefaultPhone();
7543 if (phone == null) return -1;
7544 HalVersion hv = phone.getHalVersion();
7545 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7546 return hv.major * 100 + hv.minor;
7547 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007548
7549 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007550 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7551 * corresponding network requests on a subId.
7552 *
7553 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007554 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007555 * 2) APN is un-metered for this subscription, or
7556 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7557 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7558 *
7559 * @return whether data is allowed for a apn type.
7560 *
7561 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007562 */
7563 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007564 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007565 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7566 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007567
7568 // Now that all security checks passes, perform the operation as ourselves.
7569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 Phone phone = getPhone(subId);
7572 if (phone == null) return false;
7573
Jack Yu41407ee2019-05-13 16:54:09 -07007574 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007575 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7576 } finally {
7577 Binder.restoreCallingIdentity(identity);
7578 }
7579 }
7580
7581 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007582 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007583 enforceReadPrivilegedPermission("isApnMetered");
7584
7585 // Now that all security checks passes, perform the operation as ourselves.
7586 final long identity = Binder.clearCallingIdentity();
7587 try {
7588 Phone phone = getPhone(subId);
7589 if (phone == null) return true; // By default return true.
7590
Jack Yu41407ee2019-05-13 16:54:09 -07007591 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
7595 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007596
7597 @Override
7598 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7599 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7600 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7601 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7602 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7603 }
7604 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7605 Intent intent = new Intent();
7606 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7607 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7608 // Bring up choose default SMS subscription dialog right now
7609 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7610 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7611 mApp.startActivity(intent);
7612 }
chen xud5ca2d52019-05-28 15:20:57 -07007613
7614 @Override
7615 public String getMmsUAProfUrl(int subId) {
7616 //TODO investigate if this API should require proper permission check in R b/133791609
7617 final long identity = Binder.clearCallingIdentity();
7618 try {
7619 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7620 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
7625
7626 @Override
7627 public String getMmsUserAgent(int subId) {
7628 //TODO investigate if this API should require proper permission check in R b/133791609
7629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7632 .getString(com.android.internal.R.string.config_mms_user_agent);
7633 } finally {
7634 Binder.restoreCallingIdentity(identity);
7635 }
7636 }
Jack Yub07d4972019-05-28 16:12:25 -07007637
7638 @Override
7639 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7640 enforceModifyPermission();
7641
7642 // Now that all security checks passes, perform the operation as ourselves.
7643 final long identity = Binder.clearCallingIdentity();
7644 try {
7645 Phone phone = getPhone(subId);
7646 if (phone == null) return false;
7647
7648 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7649 } finally {
7650 Binder.restoreCallingIdentity(identity);
7651 }
7652 }
7653
7654 @Override
7655 public boolean isDataAllowedInVoiceCall(int subId) {
7656 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7657
7658 // Now that all security checks passes, perform the operation as ourselves.
7659 final long identity = Binder.clearCallingIdentity();
7660 try {
7661 Phone phone = getPhone(subId);
7662 if (phone == null) return false;
7663
7664 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
7668 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007669
7670 /**
7671 * Updates whether conference event pacakge handling is enabled.
7672 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7673 * otherwise.
7674 */
7675 @Override
7676 public void setCepEnabled(boolean isCepEnabled) {
7677 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7678
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7682 for (Phone phone : PhoneFactory.getPhones()) {
7683 Phone defaultPhone = phone.getImsPhone();
7684 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7685 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7686 ImsPhoneCallTracker imsPhoneCallTracker =
7687 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7688 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7689 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7690 + imsPhone.getMsisdn());
7691 }
7692 }
7693 } finally {
7694 Binder.restoreCallingIdentity(identity);
7695 }
7696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007697}