blob: a8bb287a0d49ad0de980bc497aa5cb85ea604796 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070066import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080067import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070068import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070070import android.telephony.CellInfoGsm;
71import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070072import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070074import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070075import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080076import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070077import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080078import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070079import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080080import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080081import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070082import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080083import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080086import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080087import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070089import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080092import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000093import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070094import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080097import android.telephony.data.ApnSetting;
98import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700102import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700104import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsMmTelFeature;
106import android.telephony.ims.aidl.IImsRcsFeature;
107import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800109import android.telephony.ims.feature.MmTelFeature;
110import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800111import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800113import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800115import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800117
Andrew Lee312e8172014-10-23 17:01:36 -0700118import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800119import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700121import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700122import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800123import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700124import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800127import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700128import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800129import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800131import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700132import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100133import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700134import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700135import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700137import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800138import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700139import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700140import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700141import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700142import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700143import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700144import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700145import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700146import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800147import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800148import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700149import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800150import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700151import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800152import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700153import com.android.internal.telephony.imsphone.ImsPhone;
154import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800155import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700156import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.uicc.IccIoResult;
158import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800159import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700160import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800163import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000164import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700165import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700167import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700168import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800169import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700171import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800172
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700173import java.io.FileDescriptor;
174import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800176import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800177import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800179import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100180import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700182import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184
185/**
186 * Implementation of the ITelephony interface.
187 */
Santos Cordon117fee72014-05-16 17:56:12 -0700188public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189 private static final String LOG_TAG = "PhoneInterfaceManager";
190 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
191 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800192 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
194 // Message codes used with mMainThreadHandler
195 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700196 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
197 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198 private static final int CMD_OPEN_CHANNEL = 9;
199 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
200 private static final int CMD_CLOSE_CHANNEL = 11;
201 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800202 private static final int CMD_NV_READ_ITEM = 13;
203 private static final int EVENT_NV_READ_ITEM_DONE = 14;
204 private static final int CMD_NV_WRITE_ITEM = 15;
205 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
206 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
207 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700208 private static final int CMD_RESET_MODEM_CONFIG = 19;
209 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800210 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
211 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
212 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
213 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800214 private static final int CMD_SEND_ENVELOPE = 25;
215 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000216 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
217 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700218 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
219 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
220 private static final int CMD_EXCHANGE_SIM_IO = 31;
221 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800222 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
223 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700224 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
225 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700226 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
227 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700228 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
229 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
230 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
231 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700232 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
233 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
234 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
235 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700236 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800237 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
238 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000239 private static final int CMD_SWITCH_SLOTS = 50;
240 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700241 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
242 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
243 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
244 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
245 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
246 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
247 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
248 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700249 private static final int CMD_GET_ALL_CELL_INFO = 60;
250 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
251 private static final int CMD_GET_CELL_LOCATION = 62;
252 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700253 private static final int CMD_MODEM_REBOOT = 64;
254 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700255 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
256 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800257 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
258 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700259 private static final int CMD_GET_MODEM_STATUS = 70;
260 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700261 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
262 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700263
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800264 // Parameters of select command.
265 private static final int SELECT_COMMAND = 0xA4;
266 private static final int SELECT_P1 = 0x04;
267 private static final int SELECT_P2 = 0;
268 private static final int SELECT_P3 = 0x10;
269
Pengquan Meng85728fb2018-03-12 16:31:21 -0700270 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
271 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
272 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
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;
Stuart Scott981d8582015-04-21 14:09:50 -0700279 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private AppOpsManager mAppOps;
281 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800282 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700284 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285
Derek Tan97ebb422014-09-05 16:55:38 -0700286 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
287 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800288 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800289 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700290
Michelecea4cf22018-12-21 15:00:11 -0800291 // String to store multi SIM allowed
292 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
293
Derek Tan740e1672017-06-27 14:56:27 -0700294 // The AID of ISD-R.
295 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
296
yinxub1bed742017-04-17 11:45:04 -0700297 private NetworkScanRequestTracker mNetworkScanRequestTracker;
298
David Kelly5e06a7f2018-03-12 14:10:59 +0000299 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
300 private static final int MANUFACTURER_CODE_LENGTH = 8;
301
Derek Tan89e89d42014-07-08 17:00:10 -0700302 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700303 * A request object to use for transmitting data to an ICC.
304 */
305 private static final class IccAPDUArgument {
306 public int channel, cla, command, p1, p2, p3;
307 public String data;
308
309 public IccAPDUArgument(int channel, int cla, int command,
310 int p1, int p2, int p3, String data) {
311 this.channel = channel;
312 this.cla = cla;
313 this.command = command;
314 this.p1 = p1;
315 this.p2 = p2;
316 this.p3 = p3;
317 this.data = data;
318 }
319 }
320
321 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700322 * A request object to use for transmitting data to an ICC.
323 */
324 private static final class ManualNetworkSelectionArgument {
325 public OperatorInfo operatorInfo;
326 public boolean persistSelection;
327
328 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
329 this.operatorInfo = operatorInfo;
330 this.persistSelection = persistSelection;
331 }
332 }
333
334 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
336 * request after sending. The main thread will notify the request when it is complete.
337 */
338 private static final class MainThreadRequest {
339 /** The argument to use for the request */
340 public Object argument;
341 /** The result of the request that is run on the main thread */
342 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800343 // The subscriber id that this request applies to. Defaults to
344 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
345 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346
Nathan Harold92bed182018-10-12 18:16:49 -0700347 // In cases where subId is unavailable, the caller needs to specify the phone.
348 public Phone phone;
349
vagdeviaf9a5b92018-08-15 16:01:53 -0700350 public WorkSource workSource;
351
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 public MainThreadRequest(Object argument) {
353 this.argument = argument;
354 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800355
Nathan Harold92bed182018-10-12 18:16:49 -0700356 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
357 this.argument = argument;
358 if (phone != null) {
359 this.phone = phone;
360 }
361 this.workSource = workSource;
362 }
363
vagdeviaf9a5b92018-08-15 16:01:53 -0700364 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800366 if (subId != null) {
367 this.subId = subId;
368 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700369 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 }
372
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800373 private static final class IncomingThirdPartyCallArgs {
374 public final ComponentName component;
375 public final String callId;
376 public final String callerDisplayName;
377
378 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
379 String callerDisplayName) {
380 this.component = component;
381 this.callId = callId;
382 this.callerDisplayName = callerDisplayName;
383 }
384 }
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 /**
387 * A handler that processes messages on the main thread in the phone process. Since many
388 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
389 * inbound binder threads to the main thread in the phone process. The Binder thread
390 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
391 * on, which will be notified when the operation completes and will contain the result of the
392 * request.
393 *
394 * <p>If a MainThreadRequest object is provided in the msg.obj field,
395 * note that request.result must be set to something non-null for the calling thread to
396 * unblock.
397 */
398 private final class MainThreadHandler extends Handler {
399 @Override
400 public void handleMessage(Message msg) {
401 MainThreadRequest request;
402 Message onCompleted;
403 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800404 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700405 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800406 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407
408 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700409 case CMD_HANDLE_USSD_REQUEST: {
410 request = (MainThreadRequest) msg.obj;
411 final Phone phone = getPhoneFromRequest(request);
412 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
413 String ussdRequest = ussdObject.first;
414 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700415
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 if (!isUssdApiAllowed(request.subId)) {
417 // Carrier does not support use of this API, return failure.
418 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
419 UssdResponse response = new UssdResponse(ussdRequest, null);
420 Bundle returnData = new Bundle();
421 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
422 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 request.result = true;
425 notifyRequester(request);
426 return;
427 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700428
Pengquan Menga1bb6272018-09-06 09:59:22 -0700429 try {
430 request.result = phone != null
431 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
432 } catch (CallStateException cse) {
433 request.result = false;
434 }
435 // Wake up the requesting thread
436 notifyRequester(request);
437 break;
pkanwar32d516d2016-10-14 19:37:38 -0700438 }
439
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700442 final Phone phone = getPhoneFromRequest(request);
443 request.result = phone != null ?
444 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
445 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800454 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700455 if (uiccCard == null) {
456 loge("iccTransmitApduLogicalChannel: No UICC");
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700459 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
461 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 iccArgument.channel, iccArgument.cla, iccArgument.command,
464 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 break;
468
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700470 ar = (AsyncResult) msg.obj;
471 request = (MainThreadRequest) ar.userObj;
472 if (ar.exception == null && ar.result != null) {
473 request.result = ar.result;
474 } else {
475 request.result = new IccIoResult(0x6F, 0, (byte[])null);
476 if (ar.result == null) {
477 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800478 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800480 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 } else {
482 loge("iccTransmitApduLogicalChannel: Unknown exception");
483 }
484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 break;
487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
489 request = (MainThreadRequest) msg.obj;
490 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800491 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 if (uiccCard == null) {
493 loge("iccTransmitApduBasicChannel: No UICC");
494 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 } else {
497 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
498 request);
499 uiccCard.iccTransmitApduBasicChannel(
500 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
501 iccArgument.p3, iccArgument.data, onCompleted);
502 }
503 break;
504
505 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduBasicChannel: Empty response");
514 } else if (ar.exception instanceof CommandException) {
515 loge("iccTransmitApduBasicChannel: CommandException: " +
516 ar.exception);
517 } else {
518 loge("iccTransmitApduBasicChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 break;
523
524 case CMD_EXCHANGE_SIM_IO:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccExchangeSimIO: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
534 request);
535 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
536 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
537 iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_EXCHANGE_SIM_IO_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6f, 0, (byte[])null);
548 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 break;
551
Derek Tan4d5e5c12014-02-04 11:54:58 -0800552 case CMD_SEND_ENVELOPE:
553 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 if (uiccCard == null) {
556 loge("sendEnvelopeWithStatus: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
561 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
562 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 break;
564
565 case EVENT_SEND_ENVELOPE_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
572 if (ar.result == null) {
573 loge("sendEnvelopeWithStatus: Empty response");
574 } else if (ar.exception instanceof CommandException) {
575 loge("sendEnvelopeWithStatus: CommandException: " +
576 ar.exception);
577 } else {
578 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
579 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 break;
583
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 case CMD_OPEN_CHANNEL:
585 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800586 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800587 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 if (uiccCard == null) {
589 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800590 request.result = new IccOpenLogicalChannelResponse(-1,
591 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
594 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800595 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
596 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 break;
599
600 case EVENT_OPEN_CHANNEL_DONE:
601 ar = (AsyncResult) msg.obj;
602 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 int[] result = (int[]) ar.result;
606 int channelId = result[0];
607 byte[] selectResponse = null;
608 if (result.length > 1) {
609 selectResponse = new byte[result.length - 1];
610 for (int i = 1; i < result.length; ++i) {
611 selectResponse[i - 1] = (byte) result[i];
612 }
613 }
614 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 if (ar.result == null) {
618 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 if (ar.exception != null) {
621 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
622 }
623
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700625 if (ar.exception instanceof CommandException) {
626 CommandException.Error error =
627 ((CommandException) (ar.exception)).getCommandError();
628 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700630 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 }
633 }
634 openChannelResp = new IccOpenLogicalChannelResponse(
635 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700637 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 break;
640
641 case CMD_CLOSE_CHANNEL:
642 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800643 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 if (uiccCard == null) {
645 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900646 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 } else {
649 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
650 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
651 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 break;
653
654 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800655 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
656 break;
657
658 case CMD_NV_READ_ITEM:
659 request = (MainThreadRequest) msg.obj;
660 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800661 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
662 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800663 break;
664
665 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 ar = (AsyncResult) msg.obj;
667 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800668 if (ar.exception == null && ar.result != null) {
669 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800671 request.result = "";
672 if (ar.result == null) {
673 loge("nvReadItem: Empty response");
674 } else if (ar.exception instanceof CommandException) {
675 loge("nvReadItem: CommandException: " +
676 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 }
680 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
Jake Hambye994d462014-02-03 13:10:13 -0800684 case CMD_NV_WRITE_ITEM:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
687 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800688 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700689 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800690 break;
691
692 case EVENT_NV_WRITE_ITEM_DONE:
693 handleNullReturnEvent(msg, "nvWriteItem");
694 break;
695
696 case CMD_NV_WRITE_CDMA_PRL:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_WRITE_CDMA_PRL_DONE:
703 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
704 break;
705
chen xu6dac5ab2018-10-26 17:39:23 -0700706 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800707 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700708 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800709 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
chen xu6dac5ab2018-10-26 17:39:23 -0700712 case EVENT_RESET_MODEM_CONFIG_DONE:
713 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800714 break;
715
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 case CMD_GET_PREFERRED_NETWORK_TYPE:
717 request = (MainThreadRequest) msg.obj;
718 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700719 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 break;
721
722 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
725 if (ar.exception == null && ar.result != null) {
726 request.result = ar.result; // Integer
727 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800728 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 if (ar.result == null) {
730 loge("getPreferredNetworkType: Empty response");
731 } else if (ar.exception instanceof CommandException) {
732 loge("getPreferredNetworkType: CommandException: " +
733 ar.exception);
734 } else {
735 loge("getPreferredNetworkType: Unknown exception");
736 }
737 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 break;
740
741 case CMD_SET_PREFERRED_NETWORK_TYPE:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
744 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700745 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
749 handleNullReturnEvent(msg, "setPreferredNetworkType");
750 break;
751
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000752 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
753 request = (MainThreadRequest)msg.obj;
754 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800755 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000756 break;
757
758 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
759 ar = (AsyncResult)msg.obj;
760 request = (MainThreadRequest)ar.userObj;
761 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800765 case CMD_SET_VOICEMAIL_NUMBER:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
768 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800769 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
770 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800771 break;
772
773 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
774 handleNullReturnEvent(msg, "setVoicemailNumber");
775 break;
776
Stuart Scott54788802015-03-30 13:18:01 -0700777 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
780 request);
781 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
782 break;
783
784 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
785 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
786 break;
787
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 case CMD_PERFORM_NETWORK_SCAN:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
791 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
792 break;
793
794 case EVENT_PERFORM_NETWORK_SCAN_DONE:
795 ar = (AsyncResult) msg.obj;
796 request = (MainThreadRequest) ar.userObj;
797 CellNetworkScanResult cellScanResult;
798 if (ar.exception == null && ar.result != null) {
799 cellScanResult = new CellNetworkScanResult(
800 CellNetworkScanResult.STATUS_SUCCESS,
801 (List<OperatorInfo>) ar.result);
802 } else {
803 if (ar.result == null) {
804 loge("getCellNetworkScanResults: Empty response");
805 }
806 if (ar.exception != null) {
807 loge("getCellNetworkScanResults: Exception: " + ar.exception);
808 }
809 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
810 if (ar.exception instanceof CommandException) {
811 CommandException.Error error =
812 ((CommandException) (ar.exception)).getCommandError();
813 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
814 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
815 } else if (error == CommandException.Error.GENERIC_FAILURE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
817 }
818 }
819 cellScanResult = new CellNetworkScanResult(errorCode, null);
820 }
821 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700822 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 break;
824
825 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
826 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700827 ManualNetworkSelectionArgument selArg =
828 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700829 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
830 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700831 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
832 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
835 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null) {
839 request.result = true;
840 } else {
841 request.result = false;
842 loge("setNetworkSelectionModeManual " + ar.exception);
843 }
844 notifyRequester(request);
845 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700846 break;
847
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 case CMD_GET_MODEM_ACTIVITY_INFO:
849 request = (MainThreadRequest) msg.obj;
850 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700851 if (defaultPhone != null) {
852 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
853 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700854 break;
855
856 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
857 ar = (AsyncResult) msg.obj;
858 request = (MainThreadRequest) ar.userObj;
859 if (ar.exception == null && ar.result != null) {
860 request.result = ar.result;
861 } else {
862 if (ar.result == null) {
863 loge("queryModemActivityInfo: Empty response");
864 } else if (ar.exception instanceof CommandException) {
865 loge("queryModemActivityInfo: CommandException: " +
866 ar.exception);
867 } else {
868 loge("queryModemActivityInfo: Unknown exception");
869 }
870 }
Amit Mahajand4766222016-01-28 15:28:28 -0800871 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
872 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700873 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800874 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700875 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700876 break;
877
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 case CMD_SET_ALLOWED_CARRIERS:
879 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800880 CarrierRestrictionRules argument =
881 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800883 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 break;
885
886 case EVENT_SET_ALLOWED_CARRIERS_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result;
891 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800892 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
893 if (ar.exception instanceof CommandException) {
894 loge("setAllowedCarriers: CommandException: " + ar.exception);
895 CommandException.Error error =
896 ((CommandException) (ar.exception)).getCommandError();
897 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
898 request.result =
899 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
900 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 } else {
902 loge("setAllowedCarriers: Unknown exception");
903 }
904 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700905 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700906 break;
907
908 case CMD_GET_ALLOWED_CARRIERS:
909 request = (MainThreadRequest) msg.obj;
910 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800911 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 break;
913
914 case EVENT_GET_ALLOWED_CARRIERS_DONE:
915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null && ar.result != null) {
918 request.result = ar.result;
919 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800920 request.result = new IllegalStateException(
921 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700922 if (ar.result == null) {
923 loge("getAllowedCarriers: Empty response");
924 } else if (ar.exception instanceof CommandException) {
925 loge("getAllowedCarriers: CommandException: " +
926 ar.exception);
927 } else {
928 loge("getAllowedCarriers: Unknown exception");
929 }
930 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700931 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700932 break;
933
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 if (ar.exception == null && ar.result != null) {
938 request.result = ar.result;
939 } else {
940 request.result = new IllegalArgumentException(
941 "Failed to retrieve Forbidden Plmns");
942 if (ar.result == null) {
943 loge("getForbiddenPlmns: Empty response");
944 } else {
945 loge("getForbiddenPlmns: Unknown exception");
946 }
947 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700948 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800949 break;
950
951 case CMD_GET_FORBIDDEN_PLMNS:
952 request = (MainThreadRequest) msg.obj;
953 uiccCard = getUiccCardFromRequest(request);
954 if (uiccCard == null) {
955 loge("getForbiddenPlmns() UiccCard is null");
956 request.result = new IllegalArgumentException(
957 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960 }
961 Integer appType = (Integer) request.argument;
962 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
963 if (uiccApp == null) {
964 loge("getForbiddenPlmns() no app with specified type -- "
965 + appType);
966 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700967 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800968 break;
969 } else {
970 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
971 + " specified type -- " + appType);
972 }
973 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
974 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
975 onCompleted);
976 break;
977
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000978 case CMD_SWITCH_SLOTS:
979 request = (MainThreadRequest) msg.obj;
980 int[] physicalSlots = (int[]) request.argument;
981 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
982 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
983 break;
984
985 case EVENT_SWITCH_SLOTS_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700989 notifyRequester(request);
990 break;
991 case CMD_GET_NETWORK_SELECTION_MODE:
992 request = (MainThreadRequest) msg.obj;
993 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
994 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
995 break;
996
997 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception != null) {
1001 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1002 } else {
1003 int mode = ((int[]) ar.result)[0];
1004 if (mode == 0) {
1005 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1006 } else {
1007 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1008 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001009 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001010 notifyRequester(request);
1011 break;
1012 case CMD_GET_CDMA_ROAMING_MODE:
1013 request = (MainThreadRequest) msg.obj;
1014 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1015 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1016 break;
1017 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception != null) {
1021 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1022 } else {
1023 request.result = ((int[]) ar.result)[0];
1024 }
1025 notifyRequester(request);
1026 break;
1027 case CMD_SET_CDMA_ROAMING_MODE:
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1030 int mode = (int) request.argument;
1031 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1032 break;
1033 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
1036 request.result = ar.exception == null;
1037 notifyRequester(request);
1038 break;
1039 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1040 request = (MainThreadRequest) msg.obj;
1041 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1042 int subscriptionMode = (int) request.argument;
1043 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1044 break;
1045 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1046 ar = (AsyncResult) msg.obj;
1047 request = (MainThreadRequest) ar.userObj;
1048 request.result = ar.exception == null;
1049 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001050 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 case CMD_GET_ALL_CELL_INFO:
1052 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001054 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 case EVENT_GET_ALL_CELL_INFO_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001059 // If a timeout occurs, the response will be null
1060 request.result = (ar.exception == null && ar.result != null)
1061 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 synchronized (request) {
1063 request.notifyAll();
1064 }
1065 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 case CMD_REQUEST_CELL_INFO_UPDATE:
1067 request = (MainThreadRequest) msg.obj;
1068 request.phone.requestCellInfoUpdate(request.workSource,
1069 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1070 break;
1071 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
1074 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1075 try {
1076 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001078 cb.onError(
1079 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1080 ar.exception.getClass().getName(),
1081 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001084 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 } else {
1086 // use the result as returned
1087 cb.onCellInfo((List<CellInfo>) ar.result);
1088 }
1089 } catch (RemoteException re) {
1090 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1091 }
1092 break;
1093 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001094 request = (MainThreadRequest) msg.obj;
1095 WorkSource ws = (WorkSource) request.argument;
1096 Phone phone = getPhoneFromRequest(request);
1097 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1098 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001099 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001100 ar = (AsyncResult) msg.obj;
1101 request = (MainThreadRequest) ar.userObj;
1102 if (ar.exception == null) {
1103 request.result = ar.result;
1104 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001105 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001106 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1107 ? new CdmaCellLocation() : new GsmCellLocation();
1108 }
1109
1110 synchronized (request) {
1111 request.notifyAll();
1112 }
1113 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001114 case CMD_MODEM_REBOOT:
1115 request = (MainThreadRequest) msg.obj;
1116 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001117 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001118 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001119 case EVENT_CMD_MODEM_REBOOT_DONE:
1120 handleNullReturnEvent(msg, "rebootModem");
1121 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001122 case CMD_REQUEST_ENABLE_MODEM:
1123 request = (MainThreadRequest) msg.obj;
1124 boolean enable = (boolean) request.argument;
1125 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001126 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001127 PhoneConfigurationManager.getInstance()
1128 .enablePhone(request.phone, enable, onCompleted);
1129 break;
1130 case EVENT_ENABLE_MODEM_DONE:
1131 ar = (AsyncResult) msg.obj;
1132 request = (MainThreadRequest) ar.userObj;
1133 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001134 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001135 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001136 if ((boolean) request.result) {
1137 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1138 updateModemStateMetrics();
1139 } else {
1140 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1141 + ar.exception);
1142 }
1143 notifyRequester(request);
1144 break;
1145 case CMD_GET_MODEM_STATUS:
1146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1148 PhoneConfigurationManager.getInstance()
1149 .getPhoneStatusFromModem(request.phone, onCompleted);
1150 break;
1151 case EVENT_GET_MODEM_STATUS_DONE:
1152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 int id = request.phone.getPhoneId();
1155 if (ar.exception == null && ar.result != null) {
1156 request.result = ar.result;
1157 //update the cache as modem status has changed
1158 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1159 (boolean) request.result);
1160 } else {
1161 // Return true if modem status cannot be retrieved. For most cases,
1162 // modem status is on. And for older version modems, GET_MODEM_STATUS
1163 // and disable modem are not supported. Modem is always on.
1164 // TODO: this should be fixed in R to support a third
1165 // status UNKNOWN b/131631629
1166 request.result = true;
1167 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1168 + ar.exception);
1169 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001170 notifyRequester(request);
1171 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001172 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1173 ar = (AsyncResult) msg.obj;
1174 request = (MainThreadRequest) ar.userObj;
1175 if (ar.exception == null && ar.result != null) {
1176 request.result = ar.result;
1177 } else {
1178 request.result = -1;
1179 loge("Failed to set Forbidden Plmns");
1180 if (ar.result == null) {
1181 loge("setForbidenPlmns: Empty response");
1182 } else if (ar.exception != null) {
1183 loge("setForbiddenPlmns: Exception: " + ar.exception);
1184 request.result = -1;
1185 } else {
1186 loge("setForbiddenPlmns: Unknown exception");
1187 }
1188 }
1189 notifyRequester(request);
1190 break;
1191 case CMD_SET_FORBIDDEN_PLMNS:
1192 request = (MainThreadRequest) msg.obj;
1193 uiccCard = getUiccCardFromRequest(request);
1194 if (uiccCard == null) {
1195 loge("setForbiddenPlmns: UiccCard is null");
1196 request.result = -1;
1197 notifyRequester(request);
1198 break;
1199 }
1200 Pair<Integer, List<String>> setFplmnsArgs =
1201 (Pair<Integer, List<String>>) request.argument;
1202 appType = setFplmnsArgs.first;
1203 List<String> fplmns = setFplmnsArgs.second;
1204 uiccApp = uiccCard.getApplicationByType(appType);
1205 if (uiccApp == null) {
1206 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1207 request.result = -1;
1208 loge("Failed to get UICC App");
1209 notifyRequester(request);
1210 } else {
1211 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1212 ((SIMRecords) uiccApp.getIccRecords())
1213 .setForbiddenPlmns(onCompleted, fplmns);
1214 }
1215 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 default:
1217 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1218 break;
1219 }
1220 }
Jake Hambye994d462014-02-03 13:10:13 -08001221
Pengquan Menga1bb6272018-09-06 09:59:22 -07001222 private void notifyRequester(MainThreadRequest request) {
1223 synchronized (request) {
1224 request.notifyAll();
1225 }
1226 }
1227
Jake Hambye994d462014-02-03 13:10:13 -08001228 private void handleNullReturnEvent(Message msg, String command) {
1229 AsyncResult ar = (AsyncResult) msg.obj;
1230 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1231 if (ar.exception == null) {
1232 request.result = true;
1233 } else {
1234 request.result = false;
1235 if (ar.exception instanceof CommandException) {
1236 loge(command + ": CommandException: " + ar.exception);
1237 } else {
1238 loge(command + ": Unknown exception");
1239 }
1240 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 }
1244
1245 /**
1246 * Posts the specified command to be executed on the main thread,
1247 * waits for the request to complete, and returns the result.
1248 * @see #sendRequestAsync
1249 */
1250 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001251 return sendRequest(
1252 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001253 }
1254
1255 /**
1256 * Posts the specified command to be executed on the main thread,
1257 * waits for the request to complete, and returns the result.
1258 * @see #sendRequestAsync
1259 */
1260 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1261 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001262 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
1265 /**
1266 * Posts the specified command to be executed on the main thread,
1267 * waits for the request to complete, and returns the result.
1268 * @see #sendRequestAsync
1269 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001270 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001271 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001272 }
1273
1274 /**
1275 * Posts the specified command to be executed on the main thread,
1276 * waits for the request to complete, and returns the result.
1277 * @see #sendRequestAsync
1278 */
Nathan Harold92bed182018-10-12 18:16:49 -07001279 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1280 return sendRequest(command, argument, subId, null, workSource);
1281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
1288 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1289 return sendRequest(
1290 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1291 }
1292
1293 /**
1294 * Posts the specified command to be executed on the main thread,
1295 * waits for the request to complete, and returns the result.
1296 * @see #sendRequestAsync
1297 */
1298 private Object sendRequest(
1299 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1301 throw new RuntimeException("This method will deadlock if called from the main thread.");
1302 }
1303
Nathan Harold92bed182018-10-12 18:16:49 -07001304 MainThreadRequest request = null;
1305 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1306 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1307 } else if (phone != null) {
1308 request = new MainThreadRequest(argument, phone, workSource);
1309 } else {
1310 request = new MainThreadRequest(argument, subId, workSource);
1311 }
1312
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 Message msg = mMainThreadHandler.obtainMessage(command, request);
1314 msg.sendToTarget();
1315
1316 // Wait for the request to complete
1317 synchronized (request) {
1318 while (request.result == null) {
1319 try {
1320 request.wait();
1321 } catch (InterruptedException e) {
1322 // Do nothing, go back and wait until the request is complete
1323 }
1324 }
1325 }
1326 return request.result;
1327 }
1328
1329 /**
1330 * Asynchronous ("fire and forget") version of sendRequest():
1331 * Posts the specified command to be executed on the main thread, and
1332 * returns immediately.
1333 * @see #sendRequest
1334 */
1335 private void sendRequestAsync(int command) {
1336 mMainThreadHandler.sendEmptyMessage(command);
1337 }
1338
1339 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001340 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001341 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001342 */
1343 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001344 sendRequestAsync(command, argument, null, null);
1345 }
1346
1347 /**
1348 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1349 * @see {@link #sendRequest(int,Object)}
1350 */
1351 private void sendRequestAsync(
1352 int command, Object argument, Phone phone, WorkSource workSource) {
1353 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001354 Message msg = mMainThreadHandler.obtainMessage(command, request);
1355 msg.sendToTarget();
1356 }
1357
1358 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 * Initialize the singleton PhoneInterfaceManager instance.
1360 * This is only done once, at startup, from PhoneApp.onCreate().
1361 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001362 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 synchronized (PhoneInterfaceManager.class) {
1364 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001365 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 } else {
1367 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1368 }
1369 return sInstance;
1370 }
1371 }
1372
1373 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001374 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001377 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1379 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001380 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 mTelephonySharedPreferences =
1382 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001383 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001384 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 publish();
1387 }
1388
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private Phone getDefaultPhone() {
1390 Phone thePhone = getPhone(getDefaultSubscription());
1391 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1392 }
1393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 private void publish() {
1395 if (DBG) log("publish: " + this);
1396
1397 ServiceManager.addService("phone", this);
1398 }
1399
Stuart Scott584921c2015-01-15 17:10:34 -08001400 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001401 if (request.phone != null) {
1402 return request.phone;
1403 } else {
1404 return getPhoneFromSubId(request.subId);
1405 }
1406 }
1407
1408 private Phone getPhoneFromSubId(int subId) {
1409 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1410 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001411 }
1412
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001413 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1414 Phone phone = getPhoneFromRequest(request);
1415 return phone == null ? null :
1416 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1417 }
1418
Wink Saville36469e72014-06-11 15:17:00 -07001419 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001420 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001421 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423
1424 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001425 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001426 }
1427
Wink Savilleb564aae2014-10-23 10:18:09 -07001428 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 if (DBG) log("dial: " + number);
1430 // No permission check needed here: This is just a wrapper around the
1431 // ACTION_DIAL intent, which is available to any app since it puts up
1432 // the UI before it does anything.
1433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001434 final long identity = Binder.clearCallingIdentity();
1435 try {
1436 String url = createTelUrl(number);
1437 if (url == null) {
1438 return;
1439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001441 // PENDING: should we just silently fail if phone is offhook or ringing?
1442 PhoneConstants.State state = mCM.getState(subId);
1443 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1444 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1445 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1446 mApp.startActivity(intent);
1447 }
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 }
1451 }
1452
1453 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 if (DBG) log("call: " + number);
1459
1460 // This is just a wrapper around the ACTION_CALL intent, but we still
1461 // need to do a permission check since we're calling startActivity()
1462 // from the context of the phone app.
1463 enforceCallPermission();
1464
Jordan Liu1617b712019-07-10 15:06:26 -07001465 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 != AppOpsManager.MODE_ALLOWED) {
1467 return;
1468 }
1469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470 final long identity = Binder.clearCallingIdentity();
1471 try {
1472 String url = createTelUrl(number);
1473 if (url == null) {
1474 return;
1475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001477 boolean isValid = false;
1478 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1479 if (slist != null) {
1480 for (SubscriptionInfo subInfoRecord : slist) {
1481 if (subInfoRecord.getSubscriptionId() == subId) {
1482 isValid = true;
1483 break;
1484 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001485 }
Wink Saville08874612014-08-31 19:19:58 -07001486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001487 if (!isValid) {
1488 return;
1489 }
Wink Saville08874612014-08-31 19:19:58 -07001490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001491 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1492 intent.putExtra(SUBSCRIPTION_KEY, subId);
1493 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1494 mApp.startActivity(intent);
1495 } finally {
1496 Binder.restoreCallingIdentity(identity);
1497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001501 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
Wink Savilleb564aae2014-10-23 10:18:09 -07001504 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001506 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1507 }
1508
1509 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001510 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001511 }
1512
Wink Savilleb564aae2014-10-23 10:18:09 -07001513 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001514 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001515 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1516 }
1517
1518 /** {@hide} */
1519 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001520 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001521 }
1522
Wink Savilleb564aae2014-10-23 10:18:09 -07001523 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001525
1526 final long identity = Binder.clearCallingIdentity();
1527 try {
1528 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1529 checkSimPin.start();
1530 return checkSimPin.unlockSim(null, pin);
1531 } finally {
1532 Binder.restoreCallingIdentity(identity);
1533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535
Wink Saville9de0f752013-10-22 19:04:03 -07001536 /** {@hide} */
1537 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001539 }
1540
Wink Savilleb564aae2014-10-23 10:18:09 -07001541 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001543
1544 final long identity = Binder.clearCallingIdentity();
1545 try {
1546 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1547 checkSimPuk.start();
1548 return checkSimPuk.unlockSim(puk, pin);
1549 } finally {
1550 Binder.restoreCallingIdentity(identity);
1551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 }
1553
1554 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001555 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 * a synchronous one.
1557 */
1558 private static class UnlockSim extends Thread {
1559
1560 private final IccCard mSimCard;
1561
1562 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001563 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1564 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565
1566 // For replies from SimCard interface
1567 private Handler mHandler;
1568
1569 // For async handler to identify request type
1570 private static final int SUPPLY_PIN_COMPLETE = 100;
1571
1572 public UnlockSim(IccCard simCard) {
1573 mSimCard = simCard;
1574 }
1575
1576 @Override
1577 public void run() {
1578 Looper.prepare();
1579 synchronized (UnlockSim.this) {
1580 mHandler = new Handler() {
1581 @Override
1582 public void handleMessage(Message msg) {
1583 AsyncResult ar = (AsyncResult) msg.obj;
1584 switch (msg.what) {
1585 case SUPPLY_PIN_COMPLETE:
1586 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1587 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001588 mRetryCount = msg.arg1;
1589 if (ar.exception != null) {
1590 if (ar.exception instanceof CommandException &&
1591 ((CommandException)(ar.exception)).getCommandError()
1592 == CommandException.Error.PASSWORD_INCORRECT) {
1593 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1594 } else {
1595 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1596 }
1597 } else {
1598 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 mDone = true;
1601 UnlockSim.this.notifyAll();
1602 }
1603 break;
1604 }
1605 }
1606 };
1607 UnlockSim.this.notifyAll();
1608 }
1609 Looper.loop();
1610 }
1611
1612 /*
1613 * Use PIN or PUK to unlock SIM card
1614 *
1615 * If PUK is null, unlock SIM card with PIN
1616 *
1617 * If PUK is not null, unlock SIM card with PUK and set PIN code
1618 */
Wink Saville9de0f752013-10-22 19:04:03 -07001619 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620
1621 while (mHandler == null) {
1622 try {
1623 wait();
1624 } catch (InterruptedException e) {
1625 Thread.currentThread().interrupt();
1626 }
1627 }
1628 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1629
1630 if (puk == null) {
1631 mSimCard.supplyPin(pin, callback);
1632 } else {
1633 mSimCard.supplyPuk(puk, pin, callback);
1634 }
1635
1636 while (!mDone) {
1637 try {
1638 Log.d(LOG_TAG, "wait for done");
1639 wait();
1640 } catch (InterruptedException e) {
1641 // Restore the interrupted status
1642 Thread.currentThread().interrupt();
1643 }
1644 }
1645 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001646 int[] resultArray = new int[2];
1647 resultArray[0] = mResult;
1648 resultArray[1] = mRetryCount;
1649 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651 }
1652
1653 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001654 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001655
1656 }
1657
Wink Savilleb564aae2014-10-23 10:18:09 -07001658 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 // No permission check needed here: this call is harmless, and it's
1660 // needed for the ServiceState.requestStateUpdate() call (which is
1661 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 final Phone phone = getPhone(subId);
1665 if (phone != null) {
1666 phone.updateServiceLocation();
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001673 @Override
1674 public boolean isRadioOn(String callingPackage) {
1675 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001678 @Override
1679 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001681 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001682 return false;
1683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 return isRadioOnForSubscriber(subId);
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
1690 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001691 }
1692
1693 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1699 } else {
1700 return false;
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
1707 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001708 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 }
Wink Saville36469e72014-06-11 15:17:00 -07001710
Wink Savilleb564aae2014-10-23 10:18:09 -07001711 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1719 }
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 }
Wink Saville36469e72014-06-11 15:17:00 -07001723 }
1724
1725 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001726 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001727 }
1728
Wink Savilleb564aae2014-10-23 10:18:09 -07001729 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731
1732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 final Phone phone = getPhone(subId);
1735 if (phone == null) {
1736 return false;
1737 }
1738 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1739 toggleRadioOnOffForSubscriber(subId);
1740 }
1741 return true;
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
Wink Saville36469e72014-06-11 15:17:00 -07001746
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001747 public boolean needMobileRadioShutdown() {
1748 /*
1749 * If any of the Radios are available, it will need to be
1750 * shutdown. So return true if any Radio is available.
1751 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752 final long identity = Binder.clearCallingIdentity();
1753 try {
1754 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1755 Phone phone = PhoneFactory.getPhone(i);
1756 if (phone != null && phone.isRadioAvailable()) return true;
1757 }
1758 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1759 return false;
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001762 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001763 }
1764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001766 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 enforceModifyPermission();
1768
1769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1772 logv("Shutting down Phone " + i);
1773 shutdownRadioUsingPhoneId(i);
1774 }
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001777 }
1778 }
1779
1780 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001781 Phone phone = PhoneFactory.getPhone(phoneId);
1782 if (phone != null && phone.isRadioAvailable()) {
1783 phone.shutdownRadio();
1784 }
1785 }
1786
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001788 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001789
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1793 if (defaultPhone != null) {
1794 defaultPhone.setRadioPower(turnOn);
1795 return true;
1796 } else {
1797 loge("There's no default phone.");
1798 return false;
1799 }
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001802 }
Wink Saville36469e72014-06-11 15:17:00 -07001803 }
1804
Wink Savilleb564aae2014-10-23 10:18:09 -07001805 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001807
1808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 final Phone phone = getPhone(subId);
1811 if (phone != null) {
1812 phone.setRadioPower(turnOn);
1813 return true;
1814 } else {
1815 return false;
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
Wink Saville36469e72014-06-11 15:17:00 -07001822 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 public boolean enableDataConnectivity() {
1825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001826
1827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 int subId = mSubscriptionController.getDefaultDataSubId();
1830 final Phone phone = getPhone(subId);
1831 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001832 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833 return true;
1834 } else {
1835 return false;
1836 }
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
Wink Saville36469e72014-06-11 15:17:00 -07001842 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001843 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 public boolean disableDataConnectivity() {
1845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001846
1847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 int subId = mSubscriptionController.getDefaultDataSubId();
1850 final Phone phone = getPhone(subId);
1851 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001852 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001853 return true;
1854 } else {
1855 return false;
1856 }
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
Sanket Padawe356d7632015-06-22 14:03:32 -07001862 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001863 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001864 final long identity = Binder.clearCallingIdentity();
1865 try {
1866 final Phone phone = getPhone(subId);
1867 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001868 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001869 } else {
1870 return false;
1871 }
1872 } finally {
1873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
1877 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001878 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001879 }
1880
pkanwarae03a6b2016-11-06 20:37:09 -08001881 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 enforceCallPermission();
1883
1884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1887 return;
1888 }
1889 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1890 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
pkanwar32d516d2016-10-14 19:37:38 -07001894 };
1895
Wink Savilleb564aae2014-10-23 10:18:09 -07001896 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898
1899 final long identity = Binder.clearCallingIdentity();
1900 try {
1901 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1902 return false;
1903 }
1904 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001911 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001914 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 final long identity = Binder.clearCallingIdentity();
1916 try {
1917 Phone phone = PhoneFactory.getPhone(slotIndex);
1918 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1919 PhoneConstantConversions.convertCallState(phone.getState());
1920 } finally {
1921 Binder.restoreCallingIdentity(identity);
1922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001926 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001927 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1928 }
1929
1930 @Override
1931 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932 final long identity = Binder.clearCallingIdentity();
1933 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001934 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001935 if (phone != null) {
1936 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1937 } else {
1938 return PhoneConstantConversions.convertDataState(
1939 PhoneConstants.DataState.DISCONNECTED);
1940 }
1941 } finally {
1942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 }
1945
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001947 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001948 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1949 }
1950
1951 @Override
1952 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 final long identity = Binder.clearCallingIdentity();
1954 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001955 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956 if (phone != null) {
1957 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1958 } else {
1959 return TelephonyManager.DATA_ACTIVITY_NONE;
1960 }
1961 } finally {
1962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
1965
1966 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001967 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001968 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001969 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001970
1971 LocationAccessPolicy.LocationPermissionResult locationResult =
1972 LocationAccessPolicy.checkLocationPermission(mApp,
1973 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1974 .setCallingPackage(callingPackage)
1975 .setCallingPid(Binder.getCallingPid())
1976 .setCallingUid(Binder.getCallingUid())
1977 .setMethod("getCellLocation")
1978 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1979 .build());
1980 switch (locationResult) {
1981 case DENIED_HARD:
1982 throw new SecurityException("Not allowed to access cell location");
1983 case DENIED_SOFT:
1984 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 }
1986
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 final long identity = Binder.clearCallingIdentity();
1989 try {
1990 if (DBG_LOC) log("getCellLocation: is active user");
1991 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001992 int subId = mSubscriptionController.getDefaultDataSubId();
1993 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1994 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001995 return data;
1996 } finally {
1997 Binder.restoreCallingIdentity(identity);
1998 }
Svetoslav64fad262015-04-14 14:35:21 -07001999 }
2000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 @Override
Jack Yu1e81ccd2019-09-26 11:48:33 -07002002 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2003 if (!TextUtils.isEmpty(callingPackage)) {
2004 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2006 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2007 return "";
2008 }
2009 }
2010
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002011 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2012 // registered cell info, so return a NULL country instead.
2013 final long identity = Binder.clearCallingIdentity();
2014 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002015 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2016 // Get default phone in this case.
2017 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2018 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002019 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002020 // Todo: fix this when we can get the actual cellular network info when the device
2021 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002022 if (TelephonyManager.NETWORK_TYPE_IWLAN
2023 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2024 return "";
2025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002026 Phone phone = PhoneFactory.getPhone(phoneId);
2027 if (phone != null) {
2028 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002029 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030 if (sst != null) {
2031 LocaleTracker lt = sst.getLocaleTracker();
2032 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002033 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2034 return lt.getCurrentCountry();
2035 } else if (emergencyNumberTracker != null) {
2036 return emergencyNumberTracker.getEmergencyCountryIso();
2037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 }
2039 }
2040 }
2041 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002045 }
2046
2047 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002049 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002050 }
2051
Sanket Padawe356d7632015-06-22 14:03:32 -07002052 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002053 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 mApp.enforceCallingOrSelfPermission(
2055 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002056
2057 final long identity = Binder.clearCallingIdentity();
2058 try {
2059 final Phone phone = getPhone(subId);
2060 if (phone != null) {
2061 phone.enableLocationUpdates();
2062 }
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067
2068 @Override
2069 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002070 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002071 }
2072
Sanket Padawe356d7632015-06-22 14:03:32 -07002073 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002074 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 mApp.enforceCallingOrSelfPermission(
2076 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002077
2078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 final Phone phone = getPhone(subId);
2081 if (phone != null) {
2082 phone.disableLocationUpdates();
2083 }
2084 } finally {
2085 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 }
2088
Nathan Harold31d7ff32018-10-15 20:20:30 -07002089 /**
2090 * Returns the target SDK version number for a given package name.
2091 *
Nathan Haroldec184742019-07-10 17:04:16 -07002092 * This call MUST be invoked before clearing the calling UID.
2093 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002094 * @return target SDK if the package is found or INT_MAX.
2095 */
2096 private int getTargetSdk(String packageName) {
2097 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002098 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002099 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002100 if (ai != null) return ai.targetSdkVersion;
2101 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002102 loge("Failed to get package info for pkg="
2103 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002104 }
2105 return Integer.MAX_VALUE;
2106 }
2107
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 @Override
2109 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002110 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2111 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002112 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2113 throw new SecurityException(
2114 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2115 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002116
Jordan Liu1617b712019-07-10 15:06:26 -07002117 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2119 return null;
2120 }
Svetoslav64fad262015-04-14 14:35:21 -07002121
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002122 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123
Nathan Haroldf180aac2018-06-01 18:43:55 -07002124 List<CellInfo> info = getAllCellInfo(callingPackage);
2125 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126
Nathan Haroldf180aac2018-06-01 18:43:55 -07002127 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2128 for (CellInfo ci : info) {
2129 if (ci instanceof CellInfoGsm) {
2130 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2131 } else if (ci instanceof CellInfoWcdma) {
2132 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002135 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 }
2137
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002138 private List<CellInfo> getCachedCellInfo() {
2139 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2140 for (Phone phone : PhoneFactory.getPhones()) {
2141 List<CellInfo> info = phone.getAllCellInfo();
2142 if (info != null) cellInfos.addAll(info);
2143 }
2144 return cellInfos;
2145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146
2147 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002148 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002149 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002150 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002151
2152 LocationAccessPolicy.LocationPermissionResult locationResult =
2153 LocationAccessPolicy.checkLocationPermission(mApp,
2154 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2155 .setCallingPackage(callingPackage)
2156 .setCallingPid(Binder.getCallingPid())
2157 .setCallingUid(Binder.getCallingUid())
2158 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002159 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002160 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2161 .build());
2162 switch (locationResult) {
2163 case DENIED_HARD:
2164 throw new SecurityException("Not allowed to access cell info");
2165 case DENIED_SOFT:
2166 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002169 final int targetSdk = getTargetSdk(callingPackage);
2170 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2171 return getCachedCellInfo();
2172 }
2173
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002174 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002175 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2179 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002180 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002181 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182 if (info != null) cellInfos.addAll(info);
2183 }
2184 return cellInfos;
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 }
2188 }
2189
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002190 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002191 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2192 requestCellInfoUpdateInternal(
2193 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2194 }
2195
2196 @Override
2197 public void requestCellInfoUpdateWithWorkSource(
2198 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2199 enforceModifyPermission();
2200 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2201 }
2202
2203 private void requestCellInfoUpdateInternal(
2204 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002205 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002206 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002207
2208 LocationAccessPolicy.LocationPermissionResult locationResult =
2209 LocationAccessPolicy.checkLocationPermission(mApp,
2210 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2211 .setCallingPackage(callingPackage)
2212 .setCallingPid(Binder.getCallingPid())
2213 .setCallingUid(Binder.getCallingUid())
2214 .setMethod("requestCellInfoUpdate")
2215 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2216 .build());
2217 switch (locationResult) {
2218 case DENIED_HARD:
2219 throw new SecurityException("Not allowed to access cell info");
2220 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002221 try {
2222 cb.onCellInfo(new ArrayList<CellInfo>());
2223 } catch (RemoteException re) {
2224 // Drop without consequences
2225 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002226 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002227 }
2228
Nathan Harolda939a962019-05-09 10:13:47 -07002229
2230 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002231 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2232
2233 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2234 }
2235
2236 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002238 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002239 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240
2241 final long identity = Binder.clearCallingIdentity();
2242 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002243 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244 } finally {
2245 Binder.restoreCallingIdentity(identity);
2246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 }
2248
Shishir Agrawala9f32182016-04-12 12:00:16 -07002249 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002250 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002251 Phone phone = PhoneFactory.getPhone(slotIndex);
2252 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002253 return null;
2254 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002255 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002256 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2257 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002258 return null;
2259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260
2261 final long identity = Binder.clearCallingIdentity();
2262 try {
2263 return phone.getImei();
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002267 }
2268
2269 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002270 public String getTypeAllocationCodeForSlot(int slotIndex) {
2271 Phone phone = PhoneFactory.getPhone(slotIndex);
2272 String tac = null;
2273 if (phone != null) {
2274 String imei = phone.getImei();
2275 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2276 }
2277 return tac;
2278 }
2279
2280 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002281 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002282 Phone phone = PhoneFactory.getPhone(slotIndex);
2283 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002284 return null;
2285 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002286
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,
2289 callingPackage, "getMeidForSlot")) {
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.getMeid();
2296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
Jack Yu2af8d712017-03-15 17:14:14 -07002299 }
2300
2301 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002302 public String getManufacturerCodeForSlot(int slotIndex) {
2303 Phone phone = PhoneFactory.getPhone(slotIndex);
2304 String manufacturerCode = null;
2305 if (phone != null) {
2306 String meid = phone.getMeid();
2307 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2308 }
2309 return manufacturerCode;
2310 }
2311
2312 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002313 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002314 Phone phone = PhoneFactory.getPhone(slotIndex);
2315 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002316 return null;
2317 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002318 int subId = phone.getSubId();
2319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2320 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2321 return null;
2322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002323
2324 final long identity = Binder.clearCallingIdentity();
2325 try {
2326 return phone.getDeviceSvn();
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
2329 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002330 }
2331
fionaxu43304da2017-11-27 22:51:16 -08002332 @Override
2333 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334 final long identity = Binder.clearCallingIdentity();
2335 try {
2336 final Phone phone = getPhone(subId);
2337 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
2340 }
fionaxu43304da2017-11-27 22:51:16 -08002341 }
2342
2343 @Override
2344 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 final Phone phone = getPhone(subId);
2348 return phone == null ? null : phone.getCarrierName();
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
fionaxu43304da2017-11-27 22:51:16 -08002352 }
2353
calvinpanffe225e2018-11-01 19:43:06 +08002354 @Override
chen xu0026ca62019-03-06 15:28:50 -08002355 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 final Phone phone = getPhone(subId);
2359 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002360 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002361 } finally {
2362 Binder.restoreCallingIdentity(identity);
2363 }
2364 }
2365
2366 @Override
chen xu0026ca62019-03-06 15:28:50 -08002367 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002371 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
2375 }
2376
chen xu651eec72018-11-11 19:03:44 -08002377 @Override
chen xu864e11c2018-12-06 22:10:03 -08002378 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2379 if (!isSubscriptionMccMnc) {
2380 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2381 }
chen xu651eec72018-11-11 19:03:44 -08002382 final Phone phone = PhoneFactory.getPhone(slotIndex);
2383 if (phone == null) {
2384 return TelephonyManager.UNKNOWN_CARRIER_ID;
2385 }
2386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2389 } finally {
2390 Binder.restoreCallingIdentity(identity);
2391 }
2392 }
2393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 //
2395 // Internal helper methods.
2396 //
2397
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002398 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2400 *
2401 * @throws SecurityException if the caller does not have the required permission
2402 */
2403 private void enforceModifyPermission() {
2404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2405 }
2406
2407 /**
2408 * Make sure the caller has the CALL_PHONE permission.
2409 *
2410 * @throws SecurityException if the caller does not have the required permission
2411 */
2412 private void enforceCallPermission() {
2413 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2414 }
2415
Stuart Scott8eef64f2015-04-08 15:13:54 -07002416 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002417 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002418 "ConnectivityService");
2419 }
2420
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 private String createTelUrl(String number) {
2422 if (TextUtils.isEmpty(number)) {
2423 return null;
2424 }
2425
Jake Hambye994d462014-02-03 13:10:13 -08002426 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
2428
Ihab Awadf9e92732013-12-05 18:02:52 -08002429 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2431 }
2432
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002433 private static void logv(String msg) {
2434 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2435 }
2436
Ihab Awadf9e92732013-12-05 18:02:52 -08002437 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2439 }
2440
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002441 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002443 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002444 }
2445
Sanket Padawe356d7632015-06-22 14:03:32 -07002446 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002447 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 final Phone phone = PhoneFactory.getPhone(slotIndex);
2451 if (phone == null) {
2452 return PhoneConstants.PHONE_TYPE_NONE;
2453 } else {
2454 return phone.getPhoneType();
2455 }
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 }
2460
2461 /**
2462 * Returns the CDMA ERI icon index to display
2463 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002464 @Override
2465 public int getCdmaEriIconIndex(String callingPackage) {
2466 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Sanket Padawe356d7632015-06-22 14:03:32 -07002469 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002470 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002472 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002473 return -1;
2474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475
2476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 final Phone phone = getPhone(subId);
2479 if (phone != null) {
2480 return phone.getCdmaEriIconIndex();
2481 } else {
2482 return -1;
2483 }
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
2489 /**
2490 * Returns the CDMA ERI icon mode,
2491 * 0 - ON
2492 * 1 - FLASHING
2493 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002494 @Override
2495 public int getCdmaEriIconMode(String callingPackage) {
2496 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002497 }
2498
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002500 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002502 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002503 return -1;
2504 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = getPhone(subId);
2509 if (phone != null) {
2510 return phone.getCdmaEriIconMode();
2511 } else {
2512 return -1;
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
2520 * Returns the CDMA ERI text,
2521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 @Override
2523 public String getCdmaEriText(String callingPackage) {
2524 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002525 }
2526
Sanket Padawe356d7632015-06-22 14:03:32 -07002527 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002528 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002530 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 return null;
2532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 final Phone phone = getPhone(subId);
2537 if (phone != null) {
2538 return phone.getCdmaEriText();
2539 } else {
2540 return null;
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
2547 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002548 * Returns the CDMA MDN.
2549 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002550 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002551 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2553 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002558 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 return phone.getLine1Number();
2560 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002561 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 return null;
2563 }
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002566 }
2567 }
2568
2569 /**
2570 * Returns the CDMA MIN.
2571 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002572 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002573 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2575 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(subId);
2580 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2581 return phone.getCdmaMin();
2582 } else {
2583 return null;
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002587 }
2588 }
2589
Hall Liud892bec2018-11-30 14:51:45 -08002590 @Override
2591 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2592 INumberVerificationCallback callback, String callingPackage) {
2593 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2594 != PERMISSION_GRANTED) {
2595 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2596 }
2597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2598
2599 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2600 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2601 throw new SecurityException("Calling package must be configured in the device config");
2602 }
2603
2604 if (range == null) {
2605 throw new NullPointerException("Range must be non-null");
2606 }
2607
2608 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002609 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002610
2611 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2612 }
2613
Junda Liuca05d5d2014-08-14 22:36:34 -07002614 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615 * Returns true if CDMA provisioning needs to run.
2616 */
2617 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002620 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 }
2625
2626 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002627 * Sets the voice mail number of a given subId.
2628 */
2629 @Override
2630 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2636 new Pair<String, String>(alphaTag, number), new Integer(subId));
2637 return success;
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002641 }
2642
Ta-wei Yen87c49842016-05-13 21:19:52 -07002643 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002644 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002646 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002647 if (!TextUtils.equals(callingPackage, systemDialer)) {
2648 throw new SecurityException("caller must be system dialer");
2649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650
2651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2654 if (phoneAccountHandle == null) {
2655 return null;
2656 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002657 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 } finally {
2659 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002660 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002661 }
2662
2663 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002664 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002667 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002668 return null;
2669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002671 final long identity = Binder.clearCallingIdentity();
2672 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002673 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002677 }
2678
2679 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002680 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2681 VisualVoicemailSmsFilterSettings settings) {
2682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002687 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002691 }
2692
2693 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002694 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002700 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002704 }
2705
2706 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002707 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2708 String callingPackage, int subId) {
2709 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710
2711 final long identity = Binder.clearCallingIdentity();
2712 try {
2713 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002714 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 } finally {
2716 Binder.restoreCallingIdentity(identity);
2717 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002718 }
2719
2720 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002721 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002722 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723
2724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002727 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728 } finally {
2729 Binder.restoreCallingIdentity(identity);
2730 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002731 }
2732
2733 @Override
2734 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2735 String number, int port, String text, PendingIntent sentIntent) {
2736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002737 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002738 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002739 SmsController smsController = PhoneFactory.getSmsController();
2740 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2741 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002742 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002743
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002744 /**
fionaxu0152e512016-11-14 13:36:14 -08002745 * Sets the voice activation state of a given subId.
2746 */
2747 @Override
2748 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2750 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 final Phone phone = getPhone(subId);
2755 if (phone != null) {
2756 phone.setVoiceActivationState(activationState);
2757 } else {
2758 loge("setVoiceActivationState fails with invalid subId: " + subId);
2759 }
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002762 }
2763 }
2764
2765 /**
2766 * Sets the data activation state of a given subId.
2767 */
2768 @Override
2769 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2771 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772
2773 final long identity = Binder.clearCallingIdentity();
2774 try {
2775 final Phone phone = getPhone(subId);
2776 if (phone != null) {
2777 phone.setDataActivationState(activationState);
2778 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002779 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780 }
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002783 }
2784 }
2785
2786 /**
2787 * Returns the voice activation state of a given subId.
2788 */
2789 @Override
2790 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002791 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792
fionaxu0152e512016-11-14 13:36:14 -08002793 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 if (phone != null) {
2797 return phone.getVoiceActivationState();
2798 } else {
2799 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2800 }
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002803 }
2804 }
2805
2806 /**
2807 * Returns the data activation state of a given subId.
2808 */
2809 @Override
2810 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002811 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812
fionaxu0152e512016-11-14 13:36:14 -08002813 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 final long identity = Binder.clearCallingIdentity();
2815 try {
2816 if (phone != null) {
2817 return phone.getDataActivationState();
2818 } else {
2819 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2820 }
2821 } finally {
2822 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002823 }
2824 }
2825
2826 /**
Wink Saville36469e72014-06-11 15:17:00 -07002827 * Returns the unread count of voicemails for a subId
2828 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002830 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2832 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2833 return 0;
2834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 final Phone phone = getPhone(subId);
2838 if (phone != null) {
2839 return phone.getVoiceMessageCount();
2840 } else {
2841 return 0;
2842 }
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847
2848 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002849 * returns true, if the device is in a state where both voice and data
2850 * are supported simultaneously. This can change based on location or network condition.
2851 */
2852 @Override
2853 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 final Phone phone = getPhone(subId);
2857 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
2860 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002861 }
2862
2863 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002864 * Send the dialer code if called from the current default dialer or the caller has
2865 * carrier privilege.
2866 * @param inputCode The dialer code to send
2867 */
2868 @Override
2869 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002871 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002872 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2873 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002874 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2876 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002881 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
fionaxu235cc5e2017-03-06 22:25:57 -08002885 }
2886
Pengquan Menga1bb6272018-09-06 09:59:22 -07002887 @Override
2888 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002889 if (!isActiveSubscription(subId)) {
2890 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2891 }
2892
Pengquan Menga1bb6272018-09-06 09:59:22 -07002893 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2894 }
2895
Brad Ebinger35c841c2018-10-01 10:40:55 -07002896 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002897 public boolean isInEmergencySmsMode() {
2898 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 for (Phone phone : PhoneFactory.getPhones()) {
2902 if (phone.isInEmergencySmsMode()) {
2903 return true;
2904 }
2905 }
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
2909 return false;
2910 }
2911
2912 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002913 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2914 throws RemoteException {
2915 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002916 final long token = Binder.clearCallingIdentity();
2917 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002919 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002920 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002921 } catch (ImsException e) {
2922 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002923 } finally {
2924 Binder.restoreCallingIdentity(token);
2925 }
2926 }
2927
2928 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002929 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2930 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2932 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2933 }
Meng Wangafbc5852019-09-19 17:37:13 -07002934 final long token = Binder.clearCallingIdentity();
2935 try {
2936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2937 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2938 .removeRegistrationCallbackForSubscription(c, subId);
2939 } catch (ImsException e) {
2940 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2941 + "is inactive, ignoring unregister.");
2942 // If the subscription is no longer active, just return, since the callback
2943 // will already have been removed internally.
2944 } finally {
2945 Binder.restoreCallingIdentity(token);
2946 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002947 }
2948
2949 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002950 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2951 throws RemoteException {
2952 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2954 final long token = Binder.clearCallingIdentity();
2955 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002958 } catch (ImsException e) {
2959 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002960 } finally {
2961 Binder.restoreCallingIdentity(token);
2962 }
2963 }
2964
2965 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002966 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2967 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002968 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2969 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2970 }
Meng Wangafbc5852019-09-19 17:37:13 -07002971
2972 final long token = Binder.clearCallingIdentity();
2973 try {
2974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2975 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002976 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07002977 } catch (ImsException e) {
2978 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2979 + "is inactive, ignoring unregister.");
2980 // If the subscription is no longer active, just return, since the callback
2981 // will already have been removed internally.
2982 } finally {
2983 Binder.restoreCallingIdentity(token);
2984 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 }
2986
2987 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002988 public boolean isCapable(int subId, int capability, int regTech) {
2989 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2991 final long token = Binder.clearCallingIdentity();
2992 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002993 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002995 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2997 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002998 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002999 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3000 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003001 } finally {
3002 Binder.restoreCallingIdentity(token);
3003 }
3004 }
3005
3006 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003007 public boolean isAvailable(int subId, int capability, int regTech) {
3008 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 final long token = Binder.clearCallingIdentity();
3010 try {
3011 Phone phone = getPhone(subId);
3012 if (phone == null) return false;
3013 return phone.isImsCapabilityAvailable(capability, regTech);
3014 } finally {
3015 Binder.restoreCallingIdentity(token);
3016 }
3017 }
3018
3019 @Override
3020 public boolean isAdvancedCallingSettingEnabled(int subId) {
3021 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3023 final long token = Binder.clearCallingIdentity();
3024 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003025 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003026 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003027 } catch (ImsException e) {
3028 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003029 } finally {
3030 Binder.restoreCallingIdentity(token);
3031 }
3032 }
3033
3034 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003035 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003037 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003042 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003043 } catch (ImsException e) {
3044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
3048 }
3049
3050 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003051 public boolean isVtSettingEnabled(int subId) {
3052 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003056 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3057 } catch (ImsException e) {
3058 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
3062 }
3063
3064 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003065 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003067 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003071 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003072 } catch (ImsException e) {
3073 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
3077 }
3078
3079 @Override
3080 public boolean isVoWiFiSettingEnabled(int subId) {
3081 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003085 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003086 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003087 } catch (ImsException e) {
3088 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
3092 }
3093
3094 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003095 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003097 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003101 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003102 } catch (ImsException e) {
3103 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
3107 }
3108
3109 @Override
3110 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3111 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003115 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003116 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003117 } catch (ImsException e) {
3118 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003125 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003127 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003131 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003133 } catch (ImsException e) {
3134 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003135 } finally {
3136 Binder.restoreCallingIdentity(identity);
3137 }
3138 }
3139
3140 @Override
3141 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3143 "setVoWiFiNonPersistent");
3144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003147 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003148 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003149 } catch (ImsException e) {
3150 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
3154 }
3155
3156 @Override
3157 public int getVoWiFiModeSetting(int subId) {
3158 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003162 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003164 } catch (ImsException e) {
3165 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003166 } finally {
3167 Binder.restoreCallingIdentity(identity);
3168 }
3169 }
3170
3171 @Override
3172 public void setVoWiFiModeSetting(int subId, int mode) {
3173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3174 "setVoWiFiModeSetting");
3175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003178 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003179 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003180 } catch (ImsException e) {
3181 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
3185 }
3186
3187 @Override
3188 public int getVoWiFiRoamingModeSetting(int subId) {
3189 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003194 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003195 } catch (ImsException e) {
3196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
3200 }
3201
3202 @Override
3203 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3205 "setVoWiFiRoamingModeSetting");
3206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 } catch (ImsException e) {
3212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
3216 }
3217
3218 @Override
3219 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3221 "setRttCapabilityEnabled");
3222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003225 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3226 } catch (ImsException e) {
3227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
3231 }
3232
3233 @Override
3234 public boolean isTtyOverVolteEnabled(int subId) {
3235 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003241 } catch (ImsException e) {
3242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003248 @Override
3249 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3250 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3251 final long identity = Binder.clearCallingIdentity();
3252 try {
3253 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003254 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003255 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003256 } catch (ImsException e) {
3257 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
3261 }
3262
3263 @Override
3264 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3265 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3266 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003267 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3268 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3269 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003270 try {
3271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003272 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003273 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003274 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003275 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3276 + "is inactive, ignoring unregister.");
3277 // If the subscription is no longer active, just return, since the callback will already
3278 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
3282 }
3283
3284 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003285 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3286 boolean isProvisioned) {
3287 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3288 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3289 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3290 }
3291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3292 "setProvisioningStatusForCapability");
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3296 Phone phone = getPhone(subId);
3297 if (phone == null) {
3298 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3299 + subId);
3300 return;
3301 }
3302 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3303 return;
3304 }
3305
3306 // this capability requires provisioning, route to the correct API.
3307 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3308 switch (capability) {
3309 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3310 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3311 ims.setVolteProvisioned(isProvisioned);
3312 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3313 ims.setWfcProvisioned(isProvisioned);
3314 }
3315 break;
3316 }
3317 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3318 // There is currently no difference in VT provisioning type.
3319 ims.setVtProvisioned(isProvisioned);
3320 break;
3321 }
3322 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3323 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3324 // change the capability of the feature instead if needed.
3325 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3326 == isProvisioned) {
3327 // No change in provisioning.
3328 return;
3329 }
3330 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3331 try {
3332 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003334 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3335 + ", Exception" + e.getMessage());
3336 }
3337 break;
3338 }
3339 default: {
3340 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3341 + capability + "', which does not require provisioning.");
3342 }
3343 }
3344
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
3348 }
3349
3350 @Override
3351 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3352 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3353 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3354 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3355 }
3356 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3360 Phone phone = getPhone(subId);
3361 if (phone == null) {
3362 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3363 + subId);
3364 // We will fail with "true" as the provisioning status because this is the default
3365 // if we do not require provisioning.
3366 return true;
3367 }
3368
3369 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3370 return true;
3371 }
3372
3373 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3374 switch (capability) {
3375 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3376 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3377 return ims.isVolteProvisionedOnDevice();
3378 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3379 return ims.isWfcProvisionedOnDevice();
3380 }
3381 // This should never happen, since we are checking tech above to make sure it
3382 // is either LTE or IWLAN.
3383 throw new IllegalArgumentException("Invalid radio technology for voice "
3384 + "capability.");
3385 }
3386 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3387 // There is currently no difference in VT provisioning type.
3388 return ims.isVtProvisionedOnDevice();
3389 }
3390 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3391 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3392 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3393 }
3394 default: {
3395 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3396 + capability + "', which does not require provisioning.");
3397 }
3398 }
3399
3400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
3403 }
3404
3405 @Override
3406 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3407 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3408 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3409 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3410 }
3411 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3412 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3413 return (provisionedBits & capability) > 0;
3414 }
3415
3416 @Override
3417 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3418 boolean isProvisioned) {
3419 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3420 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3421 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3422 }
3423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3424 "setProvisioningStatusForCapability");
3425 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3426 // If the current provisioning status for capability already matches isProvisioned,
3427 // do nothing.
3428 if (((provisionedBits & capability) > 0) == isProvisioned) {
3429 return;
3430 }
3431 if (isProvisioned) {
3432 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3433 } else {
3434 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3435 }
3436 }
3437
3438 /**
3439 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3440 * technology. The bitfield should mirror the bitfield defined by
3441 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3442 */
3443 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3444 String key = getMmTelProvisioningKey(subId, tech);
3445 // Default is no capabilities are provisioned.
3446 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3447 }
3448
3449 /**
3450 * Sets the MmTel capability provisioning bitfield (defined by
3451 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3452 * technology specified.
3453 *
3454 * Note: This is a synchronous command and should not be called on UI thread.
3455 */
3456 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3457 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3458 String key = getMmTelProvisioningKey(subId, tech);
3459 editor.putInt(key, newField);
3460 editor.commit();
3461 }
3462
3463 private static String getMmTelProvisioningKey(int subId, int tech) {
3464 // resulting key is provision_ims_mmtel_{subId}_{tech}
3465 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3466 }
3467
3468 /**
3469 * Query CarrierConfig to see if the specified capability requires provisioning for the
3470 * carrier associated with the subscription id.
3471 */
3472 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3473 int capability) {
3474 CarrierConfigManager configManager = new CarrierConfigManager(context);
3475 PersistableBundle c = configManager.getConfigForSubId(subId);
3476 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003477 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003478 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3479 false);
3480 boolean requireVoiceVtProvisioning = c.getBoolean(
3481 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3482
3483 // First check to make sure that the capability requires provisioning.
3484 switch (capability) {
3485 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3486 // intentional fallthrough
3487 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3488 if (requireVoiceVtProvisioning) {
3489 // Voice and Video requires provisioning
3490 return true;
3491 }
3492 break;
3493 }
3494 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3495 if (requireUtProvisioning) {
3496 // UT requires provisioning
3497 return true;
3498 }
3499 break;
3500 }
3501 }
3502 return false;
3503 }
3504
3505 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003506 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003507 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3508 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3509 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003510 enforceReadPrivilegedPermission("getImsProvisioningInt");
3511 final long identity = Binder.clearCallingIdentity();
3512 try {
3513 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003514 int slotId = getSlotIndex(subId);
3515 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3516 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3517 + subId + "' for key:" + key);
3518 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3519 }
3520 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003521 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003522 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3523 + subId + "' for key:" + key);
3524 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
3528 }
3529
3530 @Override
3531 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003532 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3533 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3534 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003535 enforceReadPrivilegedPermission("getImsProvisioningString");
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003539 int slotId = getSlotIndex(subId);
3540 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3541 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3542 + subId + "' for key:" + key);
3543 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3544 }
3545 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003546 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003547 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3548 + subId + "' for key:" + key);
3549 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
3553 }
3554
3555 @Override
3556 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003557 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3558 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3559 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3561 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003565 int slotId = getSlotIndex(subId);
3566 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3567 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3568 + subId + "' for key:" + key);
3569 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3570 }
3571 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003572 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003573 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3574 + "' for key:" + key);
3575 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
3579 }
3580
3581 @Override
3582 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003583 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3584 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3585 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3587 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003591 int slotId = getSlotIndex(subId);
3592 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3593 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3594 + subId + "' for key:" + key);
3595 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3596 }
3597 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003598 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003599 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3600 + "' for key:" + key);
3601 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003602 } finally {
3603 Binder.restoreCallingIdentity(identity);
3604 }
3605 }
3606
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003607 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 int slotId = SubscriptionManager.getSlotIndex(subId);
3609 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003610 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3611 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003612 }
3613 return slotId;
3614 }
3615
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003616 private int getSlotIndex(int subId) {
3617 int slotId = SubscriptionManager.getSlotIndex(subId);
3618 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3619 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3620 }
3621 return slotId;
3622 }
3623
Wink Saville36469e72014-06-11 15:17:00 -07003624 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003625 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003626 */
3627 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003628 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003629 final int targetSdk = getTargetSdk(callingPackage);
3630 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3631 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3632 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003633 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3634 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003635 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3636 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 final Phone phone = getPhone(subId);
3641 if (phone != null) {
3642 return phone.getServiceState().getDataNetworkType();
3643 } else {
3644 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3645 }
3646 } finally {
3647 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 }
3650
3651 /**
3652 * Returns the data network type
3653 */
3654 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003655 public int getDataNetworkType(String callingPackage) {
3656 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003657 }
3658
3659 /**
3660 * Returns the data network type for a subId
3661 */
3662 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003663 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003665 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003666 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3667 }
3668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 final Phone phone = getPhone(subId);
3672 if (phone != null) {
3673 return phone.getServiceState().getDataNetworkType();
3674 } else {
3675 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3676 }
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003680 }
3681
3682 /**
Wink Saville36469e72014-06-11 15:17:00 -07003683 * Returns the Voice network type for a subId
3684 */
3685 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003686 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003688 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003689 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3690 }
3691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 final Phone phone = getPhone(subId);
3695 if (phone != null) {
3696 return phone.getServiceState().getVoiceNetworkType();
3697 } else {
3698 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3699 }
3700 } finally {
3701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003703 }
3704
3705 /**
3706 * @return true if a ICC card is present
3707 */
3708 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003709 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003710 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3711 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003712 }
3713
3714 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003715 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003716 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003717 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003718 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 final Phone phone = PhoneFactory.getPhone(slotIndex);
3722 if (phone != null) {
3723 return phone.getIccCard().hasIccCard();
3724 } else {
3725 return false;
3726 }
3727 } finally {
3728 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003730 }
3731
3732 /**
3733 * Return if the current radio is LTE on CDMA. This
3734 * is a tri-state return value as for a period of time
3735 * the mode may be unknown.
3736 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003737 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003738 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003739 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003740 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003741 @Override
3742 public int getLteOnCdmaMode(String callingPackage) {
3743 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003744 }
3745
Sanket Padawe356d7632015-06-22 14:03:32 -07003746 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003747 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003749 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003750 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3751 }
3752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 final Phone phone = getPhone(subId);
3756 if (phone == null) {
3757 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3758 } else {
3759 return phone.getLteOnCdmaMode();
3760 }
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003763 }
Wink Saville36469e72014-06-11 15:17:00 -07003764 }
3765
Wink Saville36469e72014-06-11 15:17:00 -07003766 /**
3767 * {@hide}
3768 * Returns Default subId, 0 in the case of single standby.
3769 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003770 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003771 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003772 }
3773
Shishir Agrawala9f32182016-04-12 12:00:16 -07003774 private int getSlotForDefaultSubscription() {
3775 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3776 }
3777
Wink Savilleb564aae2014-10-23 10:18:09 -07003778 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003779 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003780 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003781
Pengquan Menge92a50d2018-09-21 15:54:48 -07003782 private boolean isActiveSubscription(int subId) {
3783 return mSubscriptionController.isActiveSubId(subId);
3784 }
3785
Ihab Awadf2177b72013-11-25 13:33:23 -08003786 /**
3787 * @see android.telephony.TelephonyManager.WifiCallingChoices
3788 */
3789 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003792 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3794 getWhenToMakeWifiCallsDefaultPreference());
3795 } finally {
3796 Binder.restoreCallingIdentity(identity);
3797 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003798 }
3799
3800 /**
3801 * @see android.telephony.TelephonyManager.WifiCallingChoices
3802 */
3803 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003807 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
3811 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003812 }
3813
Sailesh Nepald1e68152013-12-12 19:08:02 -08003814 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003815 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003816 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003817 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003818
Jordan Liu4c733742019-02-28 12:03:40 -08003819 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3820 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3821 if (phoneId == -1) {
3822 throw new IllegalArgumentException("Given slot index: " + slotIndex
3823 + " does not correspond to an active phone");
3824 }
3825 return PhoneFactory.getPhone(phoneId);
3826 }
3827
Shishir Agrawal566b7612013-10-28 14:41:00 -07003828 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003829 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3830 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3832 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003834 if (DBG) {
3835 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3836 }
3837 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3838 p2);
3839 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003840
Jordan Liu4c733742019-02-28 12:03:40 -08003841
3842 @Override
3843 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3844 int slotIndex, String callingPackage, String aid, int p2) {
3845 enforceModifyPermission();
3846 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3847 if (DBG) {
3848 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3849 }
3850 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3851 callingPackage, aid, p2);
3852 }
3853
3854 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3855 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 if (TextUtils.equals(ISDR_AID, aid)) {
3859 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003860 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3861 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003862 if (bestComponent == null
3863 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3864 loge("The calling package is not allowed to access ISD-R.");
3865 throw new SecurityException(
3866 "The calling package is not allowed to access ISD-R.");
3867 }
Derek Tan740e1672017-06-27 14:56:27 -07003868 }
Derek Tan740e1672017-06-27 14:56:27 -07003869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003871 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3872 null /* workSource */);
3873 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 return response;
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003878 }
3879
3880 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003881 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3883 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003884 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3885 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3886 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003887
Jordan Liu4c733742019-02-28 12:03:40 -08003888 @Override
3889 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3890 enforceModifyPermission();
3891 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3892 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3893 channel);
3894 }
3895
3896 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 if (channel < 0) {
3900 return false;
3901 }
Jordan Liu4c733742019-02-28 12:03:40 -08003902 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3903 null /* workSource */);
3904 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 return success;
3906 } finally {
3907 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003908 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003909 }
3910
3911 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003912 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003913 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3915 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003916 if (DBG) {
3917 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3918 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3919 + p3 + " data=" + data);
3920 }
3921 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3922 command, p1, p2, p3, data);
3923 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003924
Jordan Liu4c733742019-02-28 12:03:40 -08003925 @Override
3926 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3927 int command, int p1, int p2, int p3, String data) {
3928 enforceModifyPermission();
3929 if (DBG) {
3930 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3931 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3932 + p3 + " data=" + data);
3933 }
3934 return iccTransmitApduLogicalChannelWithPermission(
3935 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3936 data);
3937 }
3938
3939 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3940 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 final long identity = Binder.clearCallingIdentity();
3942 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003943 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 return "";
3945 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003948 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3949 null /* workSource */);
3950 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 // Append the returned status code to the end of the response payload.
3953 String s = Integer.toHexString(
3954 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3955 if (response.payload != null) {
3956 s = IccUtils.bytesToHexString(response.payload) + s;
3957 }
3958 return s;
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003961 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003962 }
Jake Hambye994d462014-02-03 13:10:13 -08003963
Evan Charltonc66da362014-05-16 14:06:40 -07003964 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003965 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3966 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3968 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003969 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003970 if (DBG) {
3971 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3972 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3973 }
3974 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3975 cla, command, p1, p2, p3, data);
3976 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003977
Jordan Liu4c733742019-02-28 12:03:40 -08003978 @Override
3979 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3980 int command, int p1, int p2, int p3, String data) {
3981 enforceModifyPermission();
3982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3983 if (DBG) {
3984 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3985 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3986 + " data=" + data);
3987 }
3988
3989 return iccTransmitApduBasicChannelWithPermission(
3990 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3991 p2, p3, data);
3992 }
3993
3994 // open APDU basic channel assuming the caller has sufficient permissions
3995 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3996 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4000 && TextUtils.equals(ISDR_AID, data)) {
4001 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004002 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4003 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 if (bestComponent == null
4005 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4006 loge("The calling package is not allowed to select ISD-R.");
4007 throw new SecurityException(
4008 "The calling package is not allowed to select ISD-R.");
4009 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004010 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004012 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004013 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4014 null /* workSource */);
4015 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 // Append the returned status code to the end of the response payload.
4018 String s = Integer.toHexString(
4019 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4020 if (response.payload != null) {
4021 s = IccUtils.bytesToHexString(response.payload) + s;
4022 }
4023 return s;
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004026 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004027 }
4028
4029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004030 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004031 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4033 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 if (DBG) {
4038 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4039 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4040 }
4041
4042 IccIoResult response =
4043 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4044 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4045 subId);
4046
4047 if (DBG) {
4048 log("Exchange SIM_IO [R]" + response);
4049 }
4050
4051 byte[] result = null;
4052 int length = 2;
4053 if (response.payload != null) {
4054 length = 2 + response.payload.length;
4055 result = new byte[length];
4056 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4057 } else {
4058 result = new byte[length];
4059 }
4060
4061 result[length - 1] = (byte) response.sw2;
4062 result[length - 2] = (byte) response.sw1;
4063 return result;
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004066 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004067 }
4068
Nathan Haroldb3014052017-01-25 15:57:32 -08004069 /**
4070 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4071 * on a particular subscription
4072 */
sqianb6e41952018-03-12 14:54:01 -07004073 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4075 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4076 return null;
4077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078
4079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 if (appType != TelephonyManager.APPTYPE_USIM
4082 && appType != TelephonyManager.APPTYPE_SIM) {
4083 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4084 return null;
4085 }
4086 Object response = sendRequest(
4087 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4088 if (response instanceof String[]) {
4089 return (String[]) response;
4090 }
yincheng zhao2737e882019-09-06 17:06:54 -07004091 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004093 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 } finally {
4095 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004096 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004097 }
4098
yincheng zhao2737e882019-09-06 17:06:54 -07004099 /**
4100 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4101 * subscription.
4102 *
4103 * @param subId the id of the subscription.
4104 * @param appType the uicc app type, must be USIM or SIM.
4105 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4106 * @param callingPackage the op Package name.
4107 * @return number of fplmns that is successfully written to the SIM.
4108 */
4109 public int setForbiddenPlmns(
4110 int subId, int appType, List<String> fplmns, String callingPackage) {
4111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4112 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4113 if (DBG) logv("no permissions for setForbiddenplmns");
4114 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4115 }
4116 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4117 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4118 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4119 }
4120 if (fplmns == null) {
4121 throw new IllegalArgumentException("Fplmn List provided is null");
4122 }
4123 for (String fplmn : fplmns) {
4124 if (!CellIdentity.isValidPlmn(fplmn)) {
4125 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4126 }
4127 }
4128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 Object response = sendRequest(
4131 CMD_SET_FORBIDDEN_PLMNS,
4132 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4133 subId);
4134 return (int) response;
4135 } finally {
4136 Binder.restoreCallingIdentity(identity);
4137 }
4138 }
4139
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004140 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004141 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4143 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4148 if (response.payload == null) {
4149 return "";
4150 }
Evan Charltonc66da362014-05-16 14:06:40 -07004151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 // Append the returned status code to the end of the response payload.
4153 String s = Integer.toHexString(
4154 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4155 s = IccUtils.bytesToHexString(response.payload) + s;
4156 return s;
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
Evan Charltonc66da362014-05-16 14:06:40 -07004160 }
4161
Jake Hambye994d462014-02-03 13:10:13 -08004162 /**
4163 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4164 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4165 *
4166 * @param itemID the ID of the item to read
4167 * @return the NV item as a String, or null on error.
4168 */
4169 @Override
4170 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004171 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4173 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174
4175 final long identity = Binder.clearCallingIdentity();
4176 try {
4177 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004178 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4180 return value;
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Jake Hambye994d462014-02-03 13:10:13 -08004184 }
4185
4186 /**
4187 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4188 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4189 *
4190 * @param itemID the ID of the item to read
4191 * @param itemValue the value to write, as a String
4192 * @return true on success; false on any failure
4193 */
4194 @Override
4195 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004196 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4198 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199
4200 final long identity = Binder.clearCallingIdentity();
4201 try {
4202 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4203 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004204 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4206 return success;
4207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
Jake Hambye994d462014-02-03 13:10:13 -08004210 }
4211
4212 /**
4213 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4214 * Used for device configuration by some CDMA operators.
4215 *
4216 * @param preferredRoamingList byte array containing the new PRL
4217 * @return true on success; false on any failure
4218 */
4219 @Override
4220 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4222 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223
4224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4227 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4228 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4229 return success;
4230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
Jake Hambye994d462014-02-03 13:10:13 -08004233 }
4234
4235 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004236 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004237 * Used for device configuration by some CDMA operators.
4238 *
chen xu6dac5ab2018-10-26 17:39:23 -07004239 * @param slotIndex - device slot.
4240 *
Jake Hambye994d462014-02-03 13:10:13 -08004241 * @return true on success; false on any failure
4242 */
4243 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004244 public boolean resetModemConfig(int slotIndex) {
4245 Phone phone = PhoneFactory.getPhone(slotIndex);
4246 if (phone != null) {
4247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4248 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249
chen xu6dac5ab2018-10-26 17:39:23 -07004250 final long identity = Binder.clearCallingIdentity();
4251 try {
4252 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4253 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4254 return success;
4255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 }
chen xu6dac5ab2018-10-26 17:39:23 -07004259 return false;
4260 }
4261
4262 /**
4263 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4264 *
4265 * @param slotIndex - device slot.
4266 *
4267 * @return true on success; false on any failure
4268 */
4269 @Override
4270 public boolean rebootModem(int slotIndex) {
4271 Phone phone = PhoneFactory.getPhone(slotIndex);
4272 if (phone != null) {
4273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4274 mApp, phone.getSubId(), "rebootModem");
4275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4279 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4280 return success;
4281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
4284 }
4285 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004286 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004287
Svet Ganovb320e182015-04-16 12:30:10 -07004288 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004289 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004291 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004292 return new String[0];
4293 }
4294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004297 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
Wink Saville36469e72014-06-11 15:17:00 -07004301 }
4302
Brad Ebinger51f743a2017-01-23 13:50:20 -08004303 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004304 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4305 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004306 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004307 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004308 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004312 ImsResolver resolver = PhoneFactory.getImsResolver();
4313 if (resolver == null) {
4314 // may happen if the device does not support IMS.
4315 return;
4316 }
4317 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004321 }
4322
4323 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004324 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4325 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004326 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004327 public void disableIms(int slotId) {
4328 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329
4330 final long identity = Binder.clearCallingIdentity();
4331 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004332 ImsResolver resolver = PhoneFactory.getImsResolver();
4333 if (resolver == null) {
4334 // may happen if the device does not support IMS.
4335 return;
4336 }
4337 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004341 }
4342
4343 /**
4344 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4345 * feature or {@link null} if the service is not available. If the feature is available, the
4346 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4347 */
4348 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004349 IImsServiceFeatureCallback callback) {
4350 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351
4352 final long identity = Binder.clearCallingIdentity();
4353 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004354 ImsResolver resolver = PhoneFactory.getImsResolver();
4355 if (resolver == null) {
4356 // may happen if the device does not support IMS.
4357 return null;
4358 }
4359 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004363 }
4364
4365 /**
4366 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4367 * feature during emergency calling or {@link null} if the service is not available. If the
4368 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4369 * listener for feature updates.
4370 */
4371 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4372 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373
4374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004376 ImsResolver resolver = PhoneFactory.getImsResolver();
4377 if (resolver == null) {
4378 // may happen if the device does not support IMS.
4379 return null;
4380 }
4381 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004385 }
4386
Brad Ebinger5f64b052017-12-14 14:26:15 -08004387 /**
4388 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004389 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004390 */
4391 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4392 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393
4394 final long identity = Binder.clearCallingIdentity();
4395 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004396 ImsResolver resolver = PhoneFactory.getImsResolver();
4397 if (resolver == null) {
4398 // may happen if the device does not support IMS.
4399 return null;
4400 }
4401 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004405 }
4406
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004407 /**
4408 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004409 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004410 */
4411 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4412 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413
4414 final long identity = Binder.clearCallingIdentity();
4415 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004416 ImsResolver resolver = PhoneFactory.getImsResolver();
4417 if (resolver == null) {
4418 // may happen if the device does not support IMS.
4419 return null;
4420 }
4421 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004425 }
4426
Brad Ebinger884c07b2018-02-15 16:17:40 -08004427 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004428 * Sets the ImsService Package Name that Telephony will bind to.
4429 *
4430 * @param slotId the slot ID that the ImsService should bind for.
4431 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4432 * ImsService is the device default ImsService.
4433 * @param packageName The package name of the application that contains the ImsService to bind
4434 * to.
4435 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4436 * @hide
4437 */
4438 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004439 int[] subIds = SubscriptionManager.getSubId(slotId);
4440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4441 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4442 "setImsService");
4443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004446 ImsResolver resolver = PhoneFactory.getImsResolver();
4447 if (resolver == null) {
4448 // may happen if the device does not support IMS.
4449 return false;
4450 }
4451 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4452 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004456 }
4457
4458 /**
4459 * Return the ImsService configuration.
4460 *
4461 * @param slotId The slot that the ImsService is associated with.
4462 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4463 * the device default.
4464 * @return the package name of the ImsService configuration.
4465 */
4466 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004467 int[] subIds = SubscriptionManager.getSubId(slotId);
4468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4469 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4470 "getImsService");
4471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 final long identity = Binder.clearCallingIdentity();
4473 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004474 ImsResolver resolver = PhoneFactory.getImsResolver();
4475 if (resolver == null) {
4476 // may happen if the device does not support IMS.
4477 return "";
4478 }
4479 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004483 }
4484
Wink Saville36469e72014-06-11 15:17:00 -07004485 public void setImsRegistrationState(boolean registered) {
4486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487
4488 final long identity = Binder.clearCallingIdentity();
4489 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004490 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
Wink Saville36469e72014-06-11 15:17:00 -07004494 }
4495
4496 /**
Stuart Scott54788802015-03-30 13:18:01 -07004497 * Set the network selection mode to automatic.
4498 *
4499 */
4500 @Override
4501 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4503 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504
Pengquan Menge92a50d2018-09-21 15:54:48 -07004505 if (!isActiveSubscription(subId)) {
4506 return;
4507 }
4508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 final long identity = Binder.clearCallingIdentity();
4510 try {
4511 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4512 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
Stuart Scott54788802015-03-30 13:18:01 -07004516 }
4517
Pengquan Mengea84e042018-09-20 14:57:26 -07004518 /**
4519 * Ask the radio to connect to the input network and change selection mode to manual.
4520 *
4521 * @param subId the id of the subscription.
4522 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4523 * the operator to attach to.
4524 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4525 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4526 * normal network selection next time.
4527 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004528 */
4529 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004530 public boolean setNetworkSelectionModeManual(
4531 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4533 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004534
4535 if (!isActiveSubscription(subId)) {
4536 return false;
4537 }
4538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 final long identity = Binder.clearCallingIdentity();
4540 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004541 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004542 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004543 if (DBG) {
4544 log("setNetworkSelectionModeManual: subId: " + subId
4545 + " operator: " + operatorInfo);
4546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004547 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4548 } finally {
4549 Binder.restoreCallingIdentity(identity);
4550 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004551 }
4552
4553 /**
4554 * Scans for available networks.
4555 */
4556 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004557 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4559 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004560 LocationAccessPolicy.LocationPermissionResult locationResult =
4561 LocationAccessPolicy.checkLocationPermission(mApp,
4562 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4563 .setCallingPackage(callingPackage)
4564 .setCallingPid(Binder.getCallingPid())
4565 .setCallingUid(Binder.getCallingUid())
4566 .setMethod("getCellNetworkScanResults")
4567 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4568 .build());
4569 switch (locationResult) {
4570 case DENIED_HARD:
4571 throw new SecurityException("Not allowed to access scan results -- location");
4572 case DENIED_SOFT:
4573 return null;
4574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575
Pengquan Menga1bb6272018-09-06 09:59:22 -07004576 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577 try {
4578 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004579 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004584 }
4585
4586 /**
yinxub1bed742017-04-17 11:45:04 -07004587 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004588 *
yinxub1bed742017-04-17 11:45:04 -07004589 * @param subId id of the subscription
4590 * @param request contains the radio access networks with bands/channels to scan
4591 * @param messenger callback messenger for scan results or errors
4592 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004593 * @return the id of the requested scan which can be used to stop the scan.
4594 */
4595 @Override
4596 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004597 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4599 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004600 LocationAccessPolicy.LocationPermissionResult locationResult =
4601 LocationAccessPolicy.checkLocationPermission(mApp,
4602 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4603 .setCallingPackage(callingPackage)
4604 .setCallingPid(Binder.getCallingPid())
4605 .setCallingUid(Binder.getCallingUid())
4606 .setMethod("requestNetworkScan")
4607 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4608 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004609 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004610 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004611 if (e != null) {
4612 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4613 throw e;
4614 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004615 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004616 return TelephonyScanManager.INVALID_SCAN_ID;
4617 }
4618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 }
Hall Liu912dfd32019-04-25 14:02:26 -07004620 int callingUid = Binder.getCallingUid();
4621 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 return mNetworkScanRequestTracker.startNetworkScan(
4625 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004626 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
yinxu504e1392017-04-12 16:03:22 -07004630 }
4631
Hall Liub2ac8ef2019-02-28 15:56:23 -08004632 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004633 NetworkScanRequest request, int subId) {
4634 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4635 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4636 boolean hasNetworkScanPermission =
4637 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4638 == PERMISSION_GRANTED;
4639
4640 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4641 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4642 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004643 }
4644
4645 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4646 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004647 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4648 return new SecurityException("Specific channels must not be"
4649 + " scanned without location access.");
4650 }
4651 }
4652 }
4653
Hall Liub2ac8ef2019-02-28 15:56:23 -08004654 return null;
4655 }
4656
yinxu504e1392017-04-12 16:03:22 -07004657 /**
4658 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004659 *
4660 * @param subId id of the subscription
4661 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004662 */
4663 @Override
4664 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4666 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667
Hall Liu912dfd32019-04-25 14:02:26 -07004668 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004669 final long identity = Binder.clearCallingIdentity();
4670 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004671 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004672 } finally {
4673 Binder.restoreCallingIdentity(identity);
4674 }
yinxu504e1392017-04-12 16:03:22 -07004675 }
4676
4677 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004678 * Get the calculated preferred network type.
4679 * Used for debugging incorrect network type.
4680 *
4681 * @return the preferred network type, defined in RILConstants.java.
4682 */
4683 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004684 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004685 final Phone defaultPhone = getDefaultPhone();
4686 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4687 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004688 return RILConstants.PREFERRED_NETWORK_MODE;
4689 }
4690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004694 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
Junda Liu84d15a22014-07-02 11:21:04 -07004698 }
4699
4700 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004701 * Get the preferred network type.
4702 * Used for device configuration by some CDMA operators.
4703 *
4704 * @return the preferred network type, defined in RILConstants.java.
4705 */
4706 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004707 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004708 TelephonyPermissions
4709 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4710 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711
4712 final long identity = Binder.clearCallingIdentity();
4713 try {
4714 if (DBG) log("getPreferredNetworkType");
4715 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4716 int networkType = (result != null ? result[0] : -1);
4717 if (DBG) log("getPreferredNetworkType: " + networkType);
4718 return networkType;
4719 } finally {
4720 Binder.restoreCallingIdentity(identity);
4721 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004722 }
4723
4724 /**
4725 * Set the preferred network type.
4726 * Used for device configuration by some CDMA operators.
4727 *
4728 * @param networkType the preferred network type, defined in RILConstants.java.
4729 * @return true on success; false on any failure.
4730 */
4731 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004732 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4734 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735
4736 final long identity = Binder.clearCallingIdentity();
4737 try {
4738 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4739 Boolean success = (Boolean) sendRequest(
4740 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4741 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4742 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004743 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4745 }
4746 return success;
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004749 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004750 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004751
4752 /**
Miaoa84611c2019-03-15 09:21:10 +08004753 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004754 *
Miaoa84611c2019-03-15 09:21:10 +08004755 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004756 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004757 * @hide
4758 */
4759 @Override
Miaoa84611c2019-03-15 09:21:10 +08004760 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004763 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 try {
Miaoa84611c2019-03-15 09:21:10 +08004765 if (phone != null) {
4766 return phone.hasMatchedTetherApnSetting();
4767 } else {
4768 return false;
4769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004772 }
Junda Liu475951f2014-11-07 16:45:03 -08004773 }
4774
4775 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004776 * Set mobile data enabled
4777 * Used by the user through settings etc to turn on/off mobile data
4778 *
4779 * @param enable {@code true} turn turn data on, else {@code false}
4780 */
4781 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004782 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4784 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785
4786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 int phoneId = mSubscriptionController.getPhoneId(subId);
4789 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4790 Phone phone = PhoneFactory.getPhone(phoneId);
4791 if (phone != null) {
4792 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004793 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004795 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 }
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004799 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004800 }
4801
4802 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004803 * Get the user enabled state of Mobile Data.
4804 *
4805 * TODO: remove and use isUserDataEnabled.
4806 * This can't be removed now because some vendor codes
4807 * calls through ITelephony directly while they should
4808 * use TelephonyManager.
4809 *
4810 * @return true on enabled
4811 */
4812 @Override
4813 public boolean getDataEnabled(int subId) {
4814 return isUserDataEnabled(subId);
4815 }
4816
4817 /**
4818 * Get whether mobile data is enabled per user setting.
4819 *
4820 * There are other factors deciding whether mobile data is actually enabled, but they are
4821 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004822 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004823 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004824 *
4825 * @return {@code true} if data is enabled else {@code false}
4826 */
4827 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004828 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004829 try {
4830 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4831 null);
4832 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4834 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836
4837 final long identity = Binder.clearCallingIdentity();
4838 try {
4839 int phoneId = mSubscriptionController.getPhoneId(subId);
4840 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4841 Phone phone = PhoneFactory.getPhone(phoneId);
4842 if (phone != null) {
4843 boolean retVal = phone.isUserDataEnabled();
4844 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4845 return retVal;
4846 } else {
4847 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4848 return false;
4849 }
4850 } finally {
4851 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004852 }
4853 }
4854
4855 /**
4856 * Get whether mobile data is enabled.
4857 *
4858 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4859 * whether mobile data is actually enabled.
4860 *
4861 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4862 *
4863 * @return {@code true} if data is enabled else {@code false}
4864 */
4865 @Override
4866 public boolean isDataEnabled(int subId) {
4867 try {
4868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4869 null);
4870 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4872 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874
4875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 int phoneId = mSubscriptionController.getPhoneId(subId);
4878 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4879 Phone phone = PhoneFactory.getPhone(phoneId);
4880 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004881 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4883 return retVal;
4884 } else {
4885 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4886 return false;
4887 }
4888 } finally {
4889 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004890 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004891 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004892
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004893 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
4894 Phone phone) {
4895 //load access rules from carrier configs, and check those as well: b/139133814
4896 SubscriptionController subController = SubscriptionController.getInstance();
4897 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4898 || subController == null) return privilegeFromSim;
4899
4900 int uid = Binder.getCallingUid();
4901 PackageManager pkgMgr = phone.getContext().getPackageManager();
4902 String[] packages = pkgMgr.getPackagesForUid(uid);
4903
4904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4907 SubscriptionManager subManager = (SubscriptionManager)
4908 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4909 for (String pkg : packages) {
4910 if (subManager.canManageSubscription(subInfo, pkg)) {
4911 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4912 }
4913 }
4914 return privilegeFromSim;
4915 } finally {
4916 Binder.restoreCallingIdentity(identity);
4917 }
4918 }
4919
4920 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
4921 String pkgName) {
4922 //load access rules from carrier configs, and check those as well: b/139133814
4923 SubscriptionController subController = SubscriptionController.getInstance();
4924 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4925 || subController == null) return privilegeFromSim;
4926
4927 final long identity = Binder.clearCallingIdentity();
4928 try {
4929 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4930 SubscriptionManager subManager = (SubscriptionManager)
4931 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4932 return subManager.canManageSubscription(subInfo, pkgName)
4933 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
4934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
4937 }
4938
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004939 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004940 public int getCarrierPrivilegeStatus(int subId) {
4941 final Phone phone = getPhone(subId);
4942 if (phone == null) {
4943 loge("getCarrierPrivilegeStatus: Invalid subId");
4944 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4945 }
4946 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004947 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004948 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004949 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4950 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004951
4952 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4953 card.getCarrierPrivilegeStatusForCurrentTransaction(
4954 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004955 }
Junda Liu29340342014-07-10 15:23:27 -07004956
4957 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004958 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4959 final Phone phone = getPhone(subId);
4960 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004961 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004962 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4963 }
4964 UiccProfile profile =
4965 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4966 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004967 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004968 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4969 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004970 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4971 profile.getCarrierPrivilegeStatusForUid(
4972 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 }
4974
4975 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004976 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4977 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004978 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004979 }
4980
4981 int phoneId = SubscriptionManager.getPhoneId(subId);
4982 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004983 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004984 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004985 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4986 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004987 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4988 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4989 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004990 }
4991
4992 @Override
4993 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004994 if (TextUtils.isEmpty(pkgName))
4995 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004996 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4997 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4998 UiccCard card = UiccController.getInstance().getUiccCard(i);
4999 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005000 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005001 continue;
5002 }
5003
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005004 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5005 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5006 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005007 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5008 break;
5009 }
5010 }
5011
5012 return result;
Junda Liu29340342014-07-10 15:23:27 -07005013 }
Derek Tan89e89d42014-07-08 17:00:10 -07005014
5015 @Override
Junda Liue64de782015-04-16 17:19:16 -07005016 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5017 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5018 loge("phoneId " + phoneId + " is not valid.");
5019 return null;
5020 }
5021 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005022 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005023 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005024 return null ;
5025 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005026 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005027 }
5028
Amith Yamasani6e118872016-02-19 12:53:51 -08005029 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005030 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005031 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005032 List<String> privilegedPackages = new ArrayList<>();
5033 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005034 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5035 // has UICC in that slot.
5036 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005037 if (card.hasCarrierPrivilegeRules()) {
5038 if (packages == null) {
5039 // Only check packages in user 0 for now
5040 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005041 PackageManager.MATCH_DISABLED_COMPONENTS
5042 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005043 | PackageManager.GET_SIGNING_CERTIFICATES,
5044 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005045 }
5046 for (int p = packages.size() - 1; p >= 0; p--) {
5047 PackageInfo pkgInfo = packages.get(p);
5048 if (pkgInfo != null && pkgInfo.packageName != null
5049 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005050 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005051 privilegedPackages.add(pkgInfo.packageName);
5052 }
5053 }
5054 }
5055 }
5056 return privilegedPackages;
5057 }
5058
chen xuf7e9fe82019-05-09 19:31:02 -07005059 @Override
5060 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5061 List<String> privilegedPackages = new ArrayList<>();
5062 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5063 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5064 }
5065 return privilegedPackages;
5066 }
5067
Wink Savilleb564aae2014-10-23 10:18:09 -07005068 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005069 final Phone phone = getPhone(subId);
5070 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005071 if (card == null) {
5072 loge("getIccId: No UICC");
5073 return null;
5074 }
5075 String iccId = card.getIccId();
5076 if (TextUtils.isEmpty(iccId)) {
5077 loge("getIccId: ICC ID is null or empty.");
5078 return null;
5079 }
5080 return iccId;
5081 }
5082
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005083 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005084 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5085 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005086 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5087 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 final String iccId = getIccId(subId);
5092 final Phone phone = getPhone(subId);
5093 if (phone == null) {
5094 return false;
5095 }
5096 final String subscriberId = phone.getSubscriberId();
5097
5098 if (DBG_MERGE) {
5099 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5100 + subscriberId + " to " + number);
5101 }
5102
5103 if (TextUtils.isEmpty(iccId)) {
5104 return false;
5105 }
5106
5107 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5108
5109 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5110 if (alphaTag == null) {
5111 editor.remove(alphaTagPrefKey);
5112 } else {
5113 editor.putString(alphaTagPrefKey, alphaTag);
5114 }
5115
5116 // Record both the line number and IMSI for this ICCID, since we need to
5117 // track all merged IMSIs based on line number
5118 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5119 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5120 if (number == null) {
5121 editor.remove(numberPrefKey);
5122 editor.remove(subscriberPrefKey);
5123 } else {
5124 editor.putString(numberPrefKey, number);
5125 editor.putString(subscriberPrefKey, subscriberId);
5126 }
5127
5128 editor.commit();
5129 return true;
5130 } finally {
5131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005132 }
Derek Tan7226c842014-07-02 17:42:23 -07005133 }
5134
5135 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005136 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005137 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005139 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005140 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005141 return null;
5142 }
Derek Tan97ebb422014-09-05 16:55:38 -07005143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 final long identity = Binder.clearCallingIdentity();
5145 try {
5146 String iccId = getIccId(subId);
5147 if (iccId != null) {
5148 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5149 if (DBG_MERGE) {
5150 log("getLine1NumberForDisplay returning "
5151 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5152 }
5153 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5156 return null;
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005159 }
Derek Tan7226c842014-07-02 17:42:23 -07005160 }
5161
5162 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005163 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005165 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005166 return null;
5167 }
Derek Tan97ebb422014-09-05 16:55:38 -07005168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 String iccId = getIccId(subId);
5172 if (iccId != null) {
5173 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5174 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5175 }
5176 return null;
5177 } finally {
5178 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005179 }
Derek Tan7226c842014-07-02 17:42:23 -07005180 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005181
5182 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005183 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005184 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5185 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005187 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5188 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005189 return null;
5190 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005191
Jordan Liub49b04b2019-05-06 14:45:15 -07005192 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5193 // the process, where TelephonyManager was instantiated.
5194 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005195 final long identity = Binder.clearCallingIdentity();
5196 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005197 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 final TelephonyManager tele = TelephonyManager.from(context);
5199 final SubscriptionManager sub = SubscriptionManager.from(context);
5200
5201 // Figure out what subscribers are currently active
5202 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203
Jordan Liub49b04b2019-05-06 14:45:15 -07005204 // Only consider subs which match the current subId
5205 // This logic can be simplified. See b/131189269 for progress.
5206 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005207 activeSubscriberIds.add(tele.getSubscriberId(subId));
5208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209
5210 // First pass, find a number override for an active subscriber
5211 String mergeNumber = null;
5212 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5213 for (String key : prefs.keySet()) {
5214 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5215 final String subscriberId = (String) prefs.get(key);
5216 if (activeSubscriberIds.contains(subscriberId)) {
5217 final String iccId = key.substring(
5218 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5219 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5220 mergeNumber = (String) prefs.get(numberKey);
5221 if (DBG_MERGE) {
5222 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5223 + " for active subscriber " + subscriberId);
5224 }
5225 if (!TextUtils.isEmpty(mergeNumber)) {
5226 break;
5227 }
5228 }
5229 }
5230 }
5231
5232 // Shortcut when no active merged subscribers
5233 if (TextUtils.isEmpty(mergeNumber)) {
5234 return null;
5235 }
5236
5237 // Second pass, find all subscribers under that line override
5238 final ArraySet<String> result = new ArraySet<>();
5239 for (String key : prefs.keySet()) {
5240 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5241 final String number = (String) prefs.get(key);
5242 if (mergeNumber.equals(number)) {
5243 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5244 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5245 final String subscriberId = (String) prefs.get(subscriberKey);
5246 if (!TextUtils.isEmpty(subscriberId)) {
5247 result.add(subscriberId);
5248 }
5249 }
5250 }
5251 }
5252
5253 final String[] resultArray = result.toArray(new String[result.size()]);
5254 Arrays.sort(resultArray);
5255 if (DBG_MERGE) {
5256 Slog.d(LOG_TAG,
5257 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5258 }
5259 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005262 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005263 }
5264
5265 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005266 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5267 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5268
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 final TelephonyManager telephonyManager = mApp.getSystemService(
5272 TelephonyManager.class);
5273 String subscriberId = telephonyManager.getSubscriberId(subId);
5274 if (subscriberId == null) {
5275 if (DBG) {
5276 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5277 + subId);
5278 }
5279 return null;
5280 }
5281
5282 final SubscriptionInfo info = SubscriptionController.getInstance()
5283 .getSubscriptionInfo(subId);
5284 final ParcelUuid groupUuid = info.getGroupUuid();
5285 // If it doesn't belong to any group, return just subscriberId of itself.
5286 if (groupUuid == null) {
5287 return new String[]{subscriberId};
5288 }
5289
5290 // Get all subscriberIds from the group.
5291 final List<String> mergedSubscriberIds = new ArrayList<>();
5292 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5293 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5294 for (SubscriptionInfo subInfo : groupInfos) {
5295 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5296 if (subscriberId != null) {
5297 mergedSubscriberIds.add(subscriberId);
5298 }
5299 }
5300
5301 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304
5305 }
5306 }
5307
5308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005309 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5311 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312
5313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 final Phone phone = getPhone(subId);
5316 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005320 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005321
5322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005323 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005324 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5325 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005326 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327
5328 final long identity = Binder.clearCallingIdentity();
5329 try {
5330 final Phone phone = getPhone(subId);
5331 if (phone == null) {
5332 return false;
5333 }
5334 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5335 cdmaNonRoamingList);
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005338 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005339 }
5340
5341 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005342 @Deprecated
5343 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5344 enforceModifyPermission();
5345
5346 int returnValue = 0;
5347 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005348 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005349 if(result.exception == null) {
5350 if (result.result != null) {
5351 byte[] responseData = (byte[])(result.result);
5352 if(responseData.length > oemResp.length) {
5353 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5354 responseData.length + "bytes. Buffer Size is " +
5355 oemResp.length + "bytes.");
5356 }
5357 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5358 returnValue = responseData.length;
5359 }
5360 } else {
5361 CommandException ex = (CommandException) result.exception;
5362 returnValue = ex.getCommandError().ordinal();
5363 if(returnValue > 0) returnValue *= -1;
5364 }
5365 } catch (RuntimeException e) {
5366 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5367 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5368 if(returnValue > 0) returnValue *= -1;
5369 }
5370
5371 return returnValue;
5372 }
5373
5374 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005375 public void setRadioCapability(RadioAccessFamily[] rafs) {
5376 try {
5377 ProxyController.getInstance().setRadioCapability(rafs);
5378 } catch (RuntimeException e) {
5379 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5380 }
5381 }
5382
5383 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005384 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005385 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005386 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005387 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005388 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
chen xub97461a2018-10-26 14:17:57 -07005392 TelephonyPermissions
5393 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5394 mApp, phone.getSubId(), "getRadioAccessFamily");
5395 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
chen xub97461a2018-10-26 14:17:57 -07005399 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005400 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005401
5402 @Override
5403 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005404 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005405 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406
5407 final long identity = Binder.clearCallingIdentity();
5408 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005409 ImsManager.getInstance(defaultPhone.getContext(),
5410 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005414 }
5415
5416 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005417 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005418 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005420 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005421 return false;
5422 }
Svet Ganovb320e182015-04-16 12:30:10 -07005423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 // Check the user preference and the system-level IMS setting. Even if the user has
5427 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5428 // In the long run, we may instead need to check if there exists a connection service
5429 // which can support video calling.
5430 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005431 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 return imsManager.isVtEnabledByPlatform()
5433 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5434 && imsManager.isVtEnabledByUser();
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
5437 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005438 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005439
Andrew Leea1239f22015-03-02 17:44:07 -08005440 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5443 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5444 return false;
5445 }
5446
5447 final long identity = Binder.clearCallingIdentity();
5448 try {
5449 CarrierConfigManager configManager =
5450 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005451 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
5455 }
Andrew Leea1239f22015-03-02 17:44:07 -08005456 }
5457
5458 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 public boolean isWorldPhone(int subId, String callingPackage) {
5460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5461 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5462 return false;
5463 }
5464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 CarrierConfigManager configManager =
5468 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005469 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
Andrew Leea1239f22015-03-02 17:44:07 -08005474 }
5475
Andrew Lee9431b832015-03-09 18:46:45 -07005476 @Override
5477 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005478 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005479 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005480 }
5481
5482 @Override
5483 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 final long identity = Binder.clearCallingIdentity();
5485 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005486 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
Andrew Lee9431b832015-03-09 18:46:45 -07005490 }
5491
Hall Liuf6668912018-10-31 17:05:23 -07005492 /**
5493 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5494 * support for the feature and device firmware support.
5495 *
5496 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5497 */
5498 @Override
5499 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005501 final Phone phone = getPhone(subscriptionId);
5502 if (phone == null) {
5503 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5504 return false;
5505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005507 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5509 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005510 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 return isCarrierSupported && isDeviceSupported;
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
Hall Liu98187582018-01-22 19:15:32 -08005515 }
5516
Hall Liuf6668912018-10-31 17:05:23 -07005517 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005518 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5519 * RTT setting, will return true if the device and carrier both support RTT.
5520 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005521 */
5522 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005525 boolean isRttSupported = isRttSupported(subscriptionId);
5526 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005527 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005528 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5529 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5530 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005534 }
5535
Sanket Padawe7310cc72015-01-14 09:53:20 -08005536 /**
5537 * Returns the unique device ID of phone, for example, the IMEI for
5538 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5539 *
5540 * <p>Requires Permission:
5541 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5542 */
5543 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005544 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005545 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005546 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005547 return null;
5548 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005549 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005550 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5551 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005552 return null;
5553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554
5555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 return phone.getDeviceId();
5558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005561 }
5562
Ping Sunc67b7c22016-03-02 19:16:45 +08005563 /**
5564 * {@hide}
5565 * Returns the IMS Registration Status on a particular subid
5566 *
5567 * @param subId
5568 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005569 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005570 Phone phone = getPhone(subId);
5571 if (phone != null) {
5572 return phone.isImsRegistered();
5573 } else {
5574 return false;
5575 }
5576 }
5577
Santos Cordon7a1885b2015-02-03 11:15:19 -08005578 @Override
5579 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005586 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005587
Tyler Gunnf70ed162019-04-03 15:28:53 -07005588 @Override
5589 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5590 final long identity = Binder.clearCallingIdentity();
5591 try {
5592 Phone phone = getPhone(subscriptionId);
5593 if (phone == null) {
5594 return null;
5595 }
5596 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
5600 }
5601
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005602 /**
5603 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005604 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005605 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 Phone phone = getPhone(subId);
5609 if (phone != null) {
5610 return phone.isWifiCallingEnabled();
5611 } else {
5612 return false;
5613 }
5614 } finally {
5615 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005616 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005617 }
5618
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005619 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005620 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005621 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005622 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 final long identity = Binder.clearCallingIdentity();
5624 try {
5625 Phone phone = getPhone(subId);
5626 if (phone != null) {
5627 return phone.isVideoEnabled();
5628 } else {
5629 return false;
5630 }
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005633 }
5634 }
5635
5636 /**
5637 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5638 * defined in {@link ImsRegistrationImplBase}.
5639 */
5640 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 Phone phone = getPhone(subId);
5644 if (phone != null) {
5645 return phone.getImsRegistrationTech();
5646 } else {
5647 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5648 }
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005651 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005652 }
5653
Stuart Scott8eef64f2015-04-08 15:13:54 -07005654 @Override
5655 public void factoryReset(int subId) {
5656 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005657 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5658 return;
5659 }
5660
Svet Ganovcc087f82015-05-12 20:35:54 -07005661 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005662
Svet Ganovcc087f82015-05-12 20:35:54 -07005663 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005664 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5665 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005666 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005667 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005668 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005669 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5670 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005671 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005672 // There has been issues when Sms raw table somehow stores orphan
5673 // fragments. They lead to garbled message when new fragments come
5674 // in and combined with those stale ones. In case this happens again,
5675 // user can reset all network settings which will clean up this table.
5676 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005677 } finally {
5678 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005679 }
5680 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005681
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005682 private void cleanUpSmsRawTable(Context context) {
5683 ContentResolver resolver = context.getContentResolver();
5684 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5685 resolver.delete(uri, null, null);
5686 }
5687
Narayan Kamath1c496c22015-04-16 14:40:19 +01005688 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005689 public String getSimLocaleForSubscriber(int subId) {
5690 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5691 final Phone phone = getPhone(subId);
5692 if (phone == null) {
5693 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005694 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 final long identity = Binder.clearCallingIdentity();
5697 try {
chen xu5d3637b2019-01-21 23:31:38 -08005698 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5699 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005700 if (info == null) {
5701 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5702 return null;
5703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 // Try and fetch the locale from the carrier properties or from the SIM language
5705 // preferences (EF-PL and EF-LI)...
5706 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005708 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5709 if (localeFromDefaultSim != null) {
5710 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5711 if (DBG) log("Using locale from subId: " + subId + " locale: "
5712 + localeFromDefaultSim);
5713 return localeFromDefaultSim.toLanguageTag();
5714 } else {
5715 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 }
5717 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 // The SIM language preferences only store a language (e.g. fr = French), not an
5720 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5721 // the SIM and carrier preferences does not include a country we add the country
5722 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005723 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005725 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 return mccLocale.toLanguageTag();
5727 }
5728
5729 if (DBG) log("No locale found - returning null");
5730 return null;
5731 } finally {
5732 Binder.restoreCallingIdentity(identity);
5733 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005734 }
5735
5736 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005738 }
5739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 /**
5741 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5742 */
5743 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005744 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005745 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005746
Chenjie Yu1ba97252018-01-11 18:16:20 -08005747 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005748 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005749
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005750 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005751 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5752 * representing the state of the modem.
5753 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005754 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5755 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005756 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005757 */
5758 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005759 public void requestModemActivityInfo(ResultReceiver result) {
5760 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762
5763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 ModemActivityInfo ret = null;
5766 synchronized (mLastModemActivityInfo) {
5767 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5768 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005769 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005770 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005772 int[] txTimeMs = info.getTransmitTimeMillis();
5773 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005775 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 }
5777 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005778 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5779 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 mLastModemActivityInfo.setIdleTimeMillis(
5781 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005782 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5783 mLastModemActivityInfo.setReceiveTimeMillis(
5784 info.getReceiveTimeMillis() + mLastModemActivityInfo
5785 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005786 }
Chen Xud78231e2019-09-10 18:49:52 -07005787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5789 mLastModemActivityInfo.getSleepTimeMillis(),
5790 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005791 mLastModemActivityInfo.getTransmitTimeMillis(),
5792 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 Bundle bundle = new Bundle();
5795 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5796 result.send(0, bundle);
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005799 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005800 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005801
Siddharth Rayb8114062018-06-17 15:02:38 -07005802 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5803 // less than total activity duration.
5804 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5805 if (info == null) {
5806 return false;
5807 }
5808 int activityDurationMs =
5809 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5810 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005811 int[] txTimeMs = info.getTransmitTimeMillis();
5812 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5813 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005814 }
5815 return (info.isValid()
5816 && (info.getSleepTimeMillis() <= activityDurationMs)
5817 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005818 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005819 && (totalTxTimeMs <= activityDurationMs));
5820 }
5821
Jack Yu85bd38a2015-11-09 11:34:32 -08005822 /**
5823 * {@hide}
5824 * Returns the service state information on specified subscription.
5825 */
5826 @Override
5827 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005829 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005830 return null;
5831 }
5832
Hall Liuf19c44f2018-11-27 14:38:17 -08005833 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5834 LocationAccessPolicy.checkLocationPermission(mApp,
5835 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5836 .setCallingPackage(callingPackage)
5837 .setCallingPid(Binder.getCallingPid())
5838 .setCallingUid(Binder.getCallingUid())
5839 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005840 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005841 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5842 .build());
5843
5844 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5845 LocationAccessPolicy.checkLocationPermission(mApp,
5846 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5847 .setCallingPackage(callingPackage)
5848 .setCallingPid(Binder.getCallingPid())
5849 .setCallingUid(Binder.getCallingUid())
5850 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005851 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005852 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5853 .build());
5854 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5855 boolean hasFinePermission =
5856 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5857 boolean hasCoarsePermission =
5858 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 final Phone phone = getPhone(subId);
5863 if (phone == null) {
5864 return null;
5865 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005866
Hall Liuf19c44f2018-11-27 14:38:17 -08005867 ServiceState ss = phone.getServiceState();
5868
5869 // Scrub out the location info in ServiceState depending on what level of access
5870 // the caller has.
5871 if (hasFinePermission) return ss;
5872 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5873 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005877 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005878
5879 /**
5880 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5881 *
5882 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5883 * voicemail ringtone.
5884 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5885 * PhoneAccount.
5886 */
5887 @Override
5888 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889 final long identity = Binder.clearCallingIdentity();
5890 try {
5891 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5892 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005893 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005900 }
5901
5902 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005903 * Sets the per-account voicemail ringtone.
5904 *
5905 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5906 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5907 *
5908 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5909 * voicemail ringtone.
5910 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5911 * PhoneAccount.
5912 */
5913 @Override
5914 public void setVoicemailRingtoneUri(String callingPackage,
5915 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005916 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005917 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5918 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005919 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5921 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5922 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
5927 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5928 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005929 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 }
5931 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005934 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005935 }
5936
5937 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005938 * Returns whether vibration is set for voicemail notification in Phone settings.
5939 *
5940 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5941 * voicemail vibration setting.
5942 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5943 */
5944 @Override
5945 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 final long identity = Binder.clearCallingIdentity();
5947 try {
5948 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5949 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005950 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5954 } finally {
5955 Binder.restoreCallingIdentity(identity);
5956 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005957 }
5958
Youhan Wange64578a2016-05-02 15:32:42 -07005959 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005960 * Sets the per-account voicemail vibration.
5961 *
5962 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5963 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5964 *
5965 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5966 * voicemail vibration setting.
5967 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5968 * specific PhoneAccount.
5969 */
5970 @Override
5971 public void setVoicemailVibrationEnabled(String callingPackage,
5972 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005973 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5975 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005976 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5978 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5979 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005980 }
5981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 final long identity = Binder.clearCallingIdentity();
5983 try {
5984 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5985 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005986 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 }
5988 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5989 } finally {
5990 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005991 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005992 }
5993
5994 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005995 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5996 *
5997 * @throws SecurityException if the caller does not have the required permission
5998 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005999 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006000 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006001 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006002 }
6003
6004 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006005 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6006 * permission.
6007 *
6008 * @throws SecurityException if the caller does not have the required permission
6009 */
6010 private void enforceSendSmsPermission() {
6011 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6012 }
6013
6014 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006015 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006016 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006017 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006018 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006019 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 final long identity = Binder.clearCallingIdentity();
6021 try {
6022 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006023 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024 if (componentName == null) {
6025 throw new SecurityException(
6026 "Caller not current active visual voicemail package[null]");
6027 }
6028 String vvmPackage = componentName.getPackageName();
6029 if (!callingPackage.equals(vvmPackage)) {
6030 throw new SecurityException("Caller not current active visual voicemail package["
6031 + vvmPackage + "]");
6032 }
6033 } finally {
6034 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006035 }
6036 }
6037
6038 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006039 * Return the application ID for the app type.
6040 *
6041 * @param subId the subscription ID that this request applies to.
6042 * @param appType the uicc app type.
6043 * @return Application ID for specificied app type, or null if no uicc.
6044 */
6045 @Override
6046 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006047 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006048 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049
6050 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006051 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 if (phone == null) {
6053 return null;
6054 }
6055 String aid = null;
6056 try {
6057 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6058 .getApplicationByType(appType).getAid();
6059 } catch (Exception e) {
6060 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6061 }
6062 return aid;
6063 } finally {
6064 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006065 }
Youhan Wange64578a2016-05-02 15:32:42 -07006066 }
6067
Youhan Wang4001d252016-05-11 10:29:41 -07006068 /**
6069 * Return the Electronic Serial Number.
6070 *
6071 * @param subId the subscription ID that this request applies to.
6072 * @return ESN or null if error.
6073 */
6074 @Override
6075 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006076 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006077 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078
6079 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006080 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 if (phone == null) {
6082 return null;
6083 }
6084 String esn = null;
6085 try {
6086 esn = phone.getEsn();
6087 } catch (Exception e) {
6088 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6089 }
6090 return esn;
6091 } finally {
6092 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006093 }
Youhan Wang4001d252016-05-11 10:29:41 -07006094 }
6095
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006096 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006097 * Return the Preferred Roaming List Version.
6098 *
6099 * @param subId the subscription ID that this request applies to.
6100 * @return PRLVersion or null if error.
6101 */
6102 @Override
6103 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006104 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006105 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106
6107 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006108 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 if (phone == null) {
6110 return null;
6111 }
6112 String cdmaPrlVersion = null;
6113 try {
6114 cdmaPrlVersion = phone.getCdmaPrlVersion();
6115 } catch (Exception e) {
6116 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6117 }
6118 return cdmaPrlVersion;
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006121 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006122 }
6123
6124 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006125 * Get snapshot of Telephony histograms
6126 * @return List of Telephony histograms
6127 * @hide
6128 */
6129 @Override
6130 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6132 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133
6134 final long identity = Binder.clearCallingIdentity();
6135 try {
6136 return RIL.getTelephonyRILTimingHistograms();
6137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006140 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006141
6142 /**
6143 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006144 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6145 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006146 * Require system privileges. In the future we may add this to carrier APIs.
6147 *
Michele Berionne482f8202018-11-27 18:57:59 -08006148 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006149 */
6150 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006151 @TelephonyManager.SetCarrierRestrictionResult
6152 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006153 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006154 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006155
Michele Berionne482f8202018-11-27 18:57:59 -08006156 if (carrierRestrictionRules == null) {
6157 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006158 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 final long identity = Binder.clearCallingIdentity();
6161 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006162 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006163 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 } finally {
6165 Binder.restoreCallingIdentity(identity);
6166 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006167 }
6168
6169 /**
6170 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006171 * Get the allowed carrier list and the excluded carrier list, including the priority between
6172 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006173 * Require system privileges. In the future we may add this to carrier APIs.
6174 *
Michele Berionne482f8202018-11-27 18:57:59 -08006175 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006176 */
6177 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006178 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006179 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006180 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181
6182 final long identity = Binder.clearCallingIdentity();
6183 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006184 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6185 if (response instanceof CarrierRestrictionRules) {
6186 return (CarrierRestrictionRules) response;
6187 }
6188 // Response is an Exception of some kind,
6189 // which is signalled to the user as a NULL retval
6190 return null;
6191 } catch (Exception e) {
6192 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6193 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006197 }
6198
fionaxu59545b42016-05-25 15:53:37 -07006199 /**
6200 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6201 * @param subId the subscription ID that this action applies to.
6202 * @param enabled control enable or disable metered apns.
6203 * {@hide}
6204 */
6205 @Override
6206 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6207 enforceModifyPermission();
6208 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209
6210 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006211 if (phone == null) {
6212 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6213 return;
6214 }
6215 try {
6216 phone.carrierActionSetMeteredApnsEnabled(enabled);
6217 } catch (Exception e) {
6218 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 } finally {
6220 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006221 }
6222 }
6223
6224 /**
6225 * Action set from carrier signalling broadcast receivers to enable/disable radio
6226 * @param subId the subscription ID that this action applies to.
6227 * @param enabled control enable or disable radio.
6228 * {@hide}
6229 */
6230 @Override
6231 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6232 enforceModifyPermission();
6233 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234
6235 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006236 if (phone == null) {
6237 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6238 return;
6239 }
6240 try {
6241 phone.carrierActionSetRadioEnabled(enabled);
6242 } catch (Exception e) {
6243 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 } finally {
6245 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006246 }
6247 }
6248
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006249 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006250 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6251 * network status based on which carrier apps could apply actions accordingly,
6252 * enable/disable default url handler for example.
6253 *
6254 * @param subId the subscription ID that this action applies to.
6255 * @param report control start/stop reporting the default network status.
6256 * {@hide}
6257 */
6258 @Override
6259 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6260 enforceModifyPermission();
6261 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262
6263 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006264 if (phone == null) {
6265 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6266 return;
6267 }
6268 try {
6269 phone.carrierActionReportDefaultNetworkStatus(report);
6270 } catch (Exception e) {
6271 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 } finally {
6273 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006274 }
6275 }
6276
6277 /**
fionaxud9622282017-07-17 17:51:30 -07006278 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6279 * @param subId the subscription ID that this action applies to.
6280 * {@hide}
6281 */
6282 @Override
6283 public void carrierActionResetAll(int subId) {
6284 enforceModifyPermission();
6285 final Phone phone = getPhone(subId);
6286 if (phone == null) {
6287 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6288 return;
6289 }
6290 try {
6291 phone.carrierActionResetAll();
6292 } catch (Exception e) {
6293 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6294 }
6295 }
6296
6297 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006298 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6299 * bug report is being generated.
6300 */
6301 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006302 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006303 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6304 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006305 writer.println("Permission Denial: can't dump Phone from pid="
6306 + Binder.getCallingPid()
6307 + ", uid=" + Binder.getCallingUid()
6308 + "without permission "
6309 + android.Manifest.permission.DUMP);
6310 return;
6311 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006312 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006313 }
Jack Yueb89b242016-06-22 13:27:47 -07006314
Brad Ebingerdac2f002018-04-03 15:17:52 -07006315 @Override
6316 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6317 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6318 throws RemoteException {
6319 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6320 }
6321
Jack Yueb89b242016-06-22 13:27:47 -07006322 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006323 * Get aggregated video call data usage since boot.
6324 *
6325 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6326 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006327 * {@hide}
6328 */
6329 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006330 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006331 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6332 null);
6333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 // NetworkStatsService keeps tracking the active network interface and identity. It
6337 // records the delta with the corresponding network identity.
6338 // We just return the total video call data usage snapshot since boot.
6339 Phone phone = getPhone(subId);
6340 if (phone != null) {
6341 return phone.getVtDataUsage(perUidStats);
6342 }
6343 return null;
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006346 }
Jack Yueb89b242016-06-22 13:27:47 -07006347 }
Jack Yu75ab2952016-07-08 14:29:33 -07006348
6349 /**
6350 * Policy control of data connection. Usually used when data limit is passed.
6351 * @param enabled True if enabling the data, otherwise disabling.
6352 * @param subId Subscription index
6353 * {@hide}
6354 */
6355 @Override
6356 public void setPolicyDataEnabled(boolean enabled, int subId) {
6357 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358
6359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 Phone phone = getPhone(subId);
6362 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006363 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 }
6365 } finally {
6366 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006367 }
6368 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006369
6370 /**
6371 * Get Client request stats
6372 * @return List of Client Request Stats
6373 * @hide
6374 */
6375 @Override
6376 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006378 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006379 return null;
6380 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006381 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 final long identity = Binder.clearCallingIdentity();
6384 try {
6385 if (phone != null) {
6386 return phone.getClientRequestStats();
6387 }
6388
6389 return null;
6390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006393 }
6394
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006395 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006396 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006397 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006398 }
Jack Yueb4124c2017-02-16 15:32:43 -08006399
6400 /**
Grace Chen70990072017-03-24 17:21:30 -07006401 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006402 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006403 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006404 * @param state State of SIM (power down, power up, pass through)
6405 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6406 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6407 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006408 *
6409 **/
6410 @Override
Grace Chen70990072017-03-24 17:21:30 -07006411 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006412 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006413 Phone phone = PhoneFactory.getPhone(slotIndex);
6414
vagdeviaf9a5b92018-08-15 16:01:53 -07006415 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 final long identity = Binder.clearCallingIdentity();
6418 try {
6419 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006420 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 }
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006424 }
6425 }
Shuo Qiandd210312017-04-12 22:11:33 +00006426
Tyler Gunn65d45c22017-06-05 11:22:26 -07006427 private boolean isUssdApiAllowed(int subId) {
6428 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006429 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006430 if (configManager == null) {
6431 return false;
6432 }
6433 PersistableBundle pb = configManager.getConfigForSubId(subId);
6434 if (pb == null) {
6435 return false;
6436 }
6437 return pb.getBoolean(
6438 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6439 }
6440
Shuo Qiandd210312017-04-12 22:11:33 +00006441 /**
6442 * Check if phone is in emergency callback mode
6443 * @return true if phone is in emergency callback mode
6444 * @param subId sub id
6445 */
goneil9c5f4872017-12-05 14:07:56 -08006446 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006447 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006448 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006449 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450
6451 final long identity = Binder.clearCallingIdentity();
6452 try {
6453 if (phone != null) {
6454 return phone.isInEcm();
6455 } else {
6456 return false;
6457 }
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006460 }
6461 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006462
6463 /**
6464 * Get the current signal strength information for the given subscription.
6465 * Because this information is not updated when the device is in a low power state
6466 * it should not be relied-upon to be current.
6467 * @param subId Subscription index
6468 * @return the most recent cached signal strength info from the modem
6469 */
6470 @Override
6471 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 Phone p = getPhone(subId);
6475 if (p == null) {
6476 return null;
6477 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479 return p.getSignalStrength();
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006483 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006484
Pengquan Meng77b7f132018-08-22 14:49:57 -07006485 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006486 * Get the current modem radio state for the given slot.
6487 * @param slotIndex slot index.
6488 * @param callingPackage the name of the package making the call.
6489 * @return the current radio power state from the modem
6490 */
6491 @Override
6492 public int getRadioPowerState(int slotIndex, String callingPackage) {
6493 Phone phone = PhoneFactory.getPhone(slotIndex);
6494 if (phone != null) {
6495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6496 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6497 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6498 }
6499
6500 final long identity = Binder.clearCallingIdentity();
6501 try {
6502 return phone.getRadioPowerState();
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6508 }
6509
6510 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006511 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6512 *
6513 * <p>Requires one of the following permissions:
6514 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6515 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6516 * privileges.
6517 *
6518 * @param subId subscription id
6519 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6520 * {@code false}.
6521 */
6522 @Override
6523 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006524 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6525 null /* message */);
6526
Pengquan Menga1bb6272018-09-06 09:59:22 -07006527 boolean isEnabled = false;
6528 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006529 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006530 Phone phone = getPhone(subId);
6531 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006532 } catch (Exception e) {
6533 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6534 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006535 } finally {
6536 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006537 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006538 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006539 }
6540
6541
6542 /**
6543 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6544 *
6545 * <p> Requires permission:
6546 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6547 * privileges.
6548 *
6549 * @param subId subscription id
6550 * @param isEnabled {@code true} means enable, {@code false} means disable.
6551 */
6552 @Override
6553 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6555 mApp, subId, "setDataRoamingEnabled");
6556
Pengquan Menga1bb6272018-09-06 09:59:22 -07006557 final long identity = Binder.clearCallingIdentity();
6558 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006559 Phone phone = getPhone(subId);
6560 if (phone != null) {
6561 phone.setDataRoamingEnabled(isEnabled);
6562 }
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006565 }
6566 }
6567
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006568 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006569 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006570 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6571 mApp, subId, "isManualNetworkSelectionAllowed");
6572
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006573 boolean isAllowed = true;
6574 final long identity = Binder.clearCallingIdentity();
6575 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006576 Phone phone = getPhone(subId);
6577 if (phone != null) {
6578 isAllowed = phone.isCspPlmnEnabled();
6579 }
6580 } finally {
6581 Binder.restoreCallingIdentity(identity);
6582 }
6583 return isAllowed;
6584 }
6585
6586 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006587 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006588 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006589 try {
6590 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006591 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006592 } catch (SecurityException e) {
6593 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6594 // has carrier privileges on an active UICC
6595 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6596 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006597 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006598 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006599 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006603 UiccController uiccController = UiccController.getInstance();
6604 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006605 if (hasReadPermission) {
6606 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006607 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006608
6609 // Remove private info if the caller doesn't have access
6610 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6611 for (UiccCardInfo cardInfo : cardInfos) {
6612 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6613 // is available
6614 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6615 if (card == null || card.getUiccProfile() == null) {
6616 // assume no access if the card or profile is unavailable
6617 filteredInfos.add(cardInfo.getUnprivileged());
6618 continue;
6619 }
6620 UiccProfile profile = card.getUiccProfile();
6621 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6622 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6623 filteredInfos.add(cardInfo);
6624 } else {
6625 filteredInfos.add(cardInfo.getUnprivileged());
6626 }
6627 }
6628 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006629 } finally {
6630 Binder.restoreCallingIdentity(identity);
6631 }
6632 }
6633
6634 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006635 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006636 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 final long identity = Binder.clearCallingIdentity();
6639 try {
6640 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6641 if (slots == null) {
6642 Rlog.i(LOG_TAG, "slots is null.");
6643 return null;
6644 }
6645
6646 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6647 for (int i = 0; i < slots.length; i++) {
6648 UiccSlot slot = slots[i];
6649 if (slot == null) {
6650 continue;
6651 }
6652
Jordan Liu7be7e652019-05-06 18:55:02 +00006653 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 UiccCard card = slot.getUiccCard();
6655 if (card != null) {
6656 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006657 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006658 cardId = slot.getEid();
6659 if (TextUtils.isEmpty(cardId)) {
6660 cardId = slot.getIccId();
6661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 }
6663
Jordan Liu857451f2019-05-09 16:35:35 -07006664 if (cardId != null) {
6665 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6666 // if cardId is an EID, it's all digits so this is fine
6667 cardId = IccUtils.stripTrailingFs(cardId);
6668 }
6669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 int cardState = 0;
6671 switch (slot.getCardState()) {
6672 case CARDSTATE_ABSENT:
6673 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6674 break;
6675 case CARDSTATE_PRESENT:
6676 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6677 break;
6678 case CARDSTATE_ERROR:
6679 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6680 break;
6681 case CARDSTATE_RESTRICTED:
6682 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6683 break;
6684 default:
6685 break;
6686
6687 }
6688
6689 infos[i] = new UiccSlotInfo(
6690 slot.isActive(),
6691 slot.isEuicc(),
6692 cardId,
6693 cardState,
6694 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006695 slot.isExtendedApduSupported(),
6696 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 }
6698 return infos;
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006701 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006702 }
6703
6704 @Override
6705 public boolean switchSlots(int[] physicalSlots) {
6706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707
6708 final long identity = Binder.clearCallingIdentity();
6709 try {
6710 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006714 }
Jack Yu4c988042018-02-27 15:30:01 -08006715
6716 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006717 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 return UiccController.getInstance().getCardIdForDefaultEuicc();
6721 } finally {
6722 Binder.restoreCallingIdentity(identity);
6723 }
6724 }
6725
6726 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006727 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6728 enforceModifyPermission();
6729 final Phone phone = getPhone(subId);
6730 if (phone == null) {
6731 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6732 return;
6733 }
6734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 final long identity = Binder.clearCallingIdentity();
6736 try {
6737 phone.setRadioIndicationUpdateMode(filters, mode);
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
6740 }
Jack Yu4c988042018-02-27 15:30:01 -08006741 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006742
6743 /**
goneil47ffb6e2018-04-06 15:40:58 -07006744 * A test API to reload the UICC profile.
6745 *
6746 * <p>Requires that the calling app has permission
6747 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6748 * @hide
6749 */
6750 @Override
6751 public void refreshUiccProfile(int subId) {
6752 enforceModifyPermission();
6753
6754 final long identity = Binder.clearCallingIdentity();
6755 try {
6756 Phone phone = getPhone(subId);
6757 if (phone == null) {
6758 return;
6759 }
6760 UiccCard uiccCard = phone.getUiccCard();
6761 if (uiccCard == null) {
6762 return;
6763 }
6764 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6765 if (uiccProfile == null) {
6766 return;
6767 }
6768 uiccProfile.refresh();
6769 } finally {
6770 Binder.restoreCallingIdentity(identity);
6771 }
6772 }
6773
6774 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006775 * Returns false if the mobile data is disabled by default, otherwise return true.
6776 */
6777 private boolean getDefaultDataEnabled() {
6778 return "true".equalsIgnoreCase(
6779 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6780 }
6781
6782 /**
6783 * Returns true if the data roaming is enabled by default, i.e the system property
6784 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6785 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6786 */
6787 private boolean getDefaultDataRoamingEnabled(int subId) {
6788 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006789 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006790 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6791 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6792 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6793 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6794 return isDataRoamingEnabled;
6795 }
6796
6797 /**
6798 * Returns the default network type for the given {@code subId}, if the default network type is
6799 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6800 */
6801 private int getDefaultNetworkType(int subId) {
6802 return Integer.parseInt(
6803 TelephonyManager.getTelephonyProperty(
6804 mSubscriptionController.getPhoneId(subId),
6805 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6806 String.valueOf(Phone.PREFERRED_NT_MODE)));
6807 }
fionaxua13278b2018-03-21 00:08:13 -07006808
6809 @Override
6810 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006811 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006812 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813
6814 final long identity = Binder.clearCallingIdentity();
6815 try {
6816 final Phone phone = getPhone(subId);
6817 if (phone == null) {
6818 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6819 return;
6820 }
chen xueaba88a2019-03-15 13:15:10 -07006821 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6822 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823 } finally {
6824 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006825 }
fionaxua13278b2018-03-21 00:08:13 -07006826 }
6827
6828 @Override
6829 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006830 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831
6832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 final Phone phone = getPhone(subId);
6835 if (phone == null) {
6836 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6837 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6838 }
6839 return phone.getCarrierIdListVersion();
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006842 }
fionaxua13278b2018-03-21 00:08:13 -07006843 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006844
6845 @Override
6846 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6847 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6848 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6849 return -1;
6850 }
6851
6852 final long identity = Binder.clearCallingIdentity();
6853 try {
6854 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
6858 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006859
6860 @Override
6861 public int getCdmaRoamingMode(int subId) {
6862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6863 mApp, subId, "getCdmaRoamingMode");
6864
6865 final long identity = Binder.clearCallingIdentity();
6866 try {
6867 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
6870 }
6871 }
6872
6873 @Override
6874 public boolean setCdmaRoamingMode(int subId, int mode) {
6875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6876 mApp, subId, "setCdmaRoamingMode");
6877
6878 final long identity = Binder.clearCallingIdentity();
6879 try {
6880 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6881 } finally {
6882 Binder.restoreCallingIdentity(identity);
6883 }
6884 }
6885
6886 @Override
6887 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6889 mApp, subId, "setCdmaSubscriptionMode");
6890
6891 final long identity = Binder.clearCallingIdentity();
6892 try {
6893 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6894 } finally {
6895 Binder.restoreCallingIdentity(identity);
6896 }
6897 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006898
sqianc5eccab2018-10-19 18:46:41 -07006899 @Override
sqian8c685422019-02-22 15:55:18 -08006900 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006901 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006903 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006904 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6905 }
6906 final long identity = Binder.clearCallingIdentity();
6907 try {
sqian854d44b2018-12-12 16:48:18 -08006908 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6909 for (Phone phone: PhoneFactory.getPhones()) {
6910 if (phone.getEmergencyNumberTracker() != null
6911 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6912 emergencyNumberListInternal.put(
6913 phone.getSubId(),
6914 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6915 }
sqian11b7a0e2018-12-05 18:48:28 -08006916 }
sqian854d44b2018-12-12 16:48:18 -08006917 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006918 } finally {
6919 Binder.restoreCallingIdentity(identity);
6920 }
sqianc5eccab2018-10-19 18:46:41 -07006921 }
6922
6923 @Override
sqian8c685422019-02-22 15:55:18 -08006924 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006925 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006926 if (!exactMatch) {
6927 TelephonyPermissions
6928 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006929 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006930 }
6931 final long identity = Binder.clearCallingIdentity();
6932 try {
sqian854d44b2018-12-12 16:48:18 -08006933 for (Phone phone: PhoneFactory.getPhones()) {
6934 if (phone.getEmergencyNumberTracker() != null
6935 && phone.getEmergencyNumberTracker() != null) {
6936 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6937 number, exactMatch)) {
6938 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006939 }
6940 }
sqian11b7a0e2018-12-05 18:48:28 -08006941 }
6942 return false;
6943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
6946 }
6947
sqianf4ca7ed2019-01-15 18:32:07 -08006948 /**
6949 * Update emergency number list for test mode.
6950 */
6951 @Override
6952 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6954 "updateEmergencyNumberListTestMode");
6955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 for (Phone phone: PhoneFactory.getPhones()) {
6959 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6960 if (tracker != null) {
6961 tracker.executeEmergencyNumberTestModeCommand(action, num);
6962 }
6963 }
6964 } finally {
6965 Binder.restoreCallingIdentity(identity);
6966 }
6967 }
6968
6969 /**
6970 * Get the full emergency number list for test mode.
6971 */
6972 @Override
6973 public List<String> getEmergencyNumberListTestMode() {
6974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6975 "getEmergencyNumberListTestMode");
6976
6977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 Set<String> emergencyNumbers = new HashSet<>();
6980 for (Phone phone: PhoneFactory.getPhones()) {
6981 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6982 if (tracker != null) {
6983 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6984 emergencyNumbers.add(num.getNumber());
6985 }
6986 }
6987 }
6988 return new ArrayList<>(emergencyNumbers);
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
6991 }
6992 }
6993
chen xud6b45bd2018-10-30 22:27:10 -07006994 @Override
6995 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6996 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6997 Phone phone = getPhone(subId);
6998 if (phone == null) {
6999 return null;
7000 }
7001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 UiccProfile profile = UiccController.getInstance()
7004 .getUiccProfileForPhone(phone.getPhoneId());
7005 if (profile != null) {
7006 return profile.getCertsFromCarrierPrivilegeAccessRules();
7007 }
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
7011 return null;
7012 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007013
7014 /**
7015 * Enable or disable a modem stack.
7016 */
7017 @Override
7018 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7019 enforceModifyPermission();
7020
7021 final long identity = Binder.clearCallingIdentity();
7022 try {
7023 Phone phone = PhoneFactory.getPhone(slotIndex);
7024 if (phone == null) {
7025 return false;
7026 } else {
7027 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7028 }
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
7032 }
Michelecea4cf22018-12-21 15:00:11 -08007033
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007034 /**
7035 * Whether a modem stack is enabled or not.
7036 */
7037 @Override
7038 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7039 Phone phone = PhoneFactory.getPhone(slotIndex);
7040 if (phone == null) return false;
7041
7042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7043 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7044 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7045 }
7046
7047 final long identity = Binder.clearCallingIdentity();
7048 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007049 try {
7050 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7051 } catch (NoSuchElementException ex) {
7052 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7053 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007054 } finally {
7055 Binder.restoreCallingIdentity(identity);
7056 }
7057 }
7058
Michelecea4cf22018-12-21 15:00:11 -08007059 @Override
Michele0ea7d782019-03-19 14:58:42 -07007060 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007061 enforceModifyPermission();
7062
7063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007066 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007067 .commit();
7068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
7071 }
7072
7073 @Override
Michele0ea7d782019-03-19 14:58:42 -07007074 @TelephonyManager.IsMultiSimSupportedResult
7075 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007077 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7078 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007079 }
Michelecea4cf22018-12-21 15:00:11 -08007080
7081 final long identity = Binder.clearCallingIdentity();
7082 try {
Michele0ea7d782019-03-19 14:58:42 -07007083 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007084 } finally {
7085 Binder.restoreCallingIdentity(identity);
7086 }
7087 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007088
Michele0ea7d782019-03-19 14:58:42 -07007089 @TelephonyManager.IsMultiSimSupportedResult
7090 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007091 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7092 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7093 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007094 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7095 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007096 }
7097 // Check if the hardware supports multisim functionality. If usage of multisim is not
7098 // supported by the modem, indicate that it is restricted.
7099 PhoneCapability staticCapability =
7100 mPhoneConfigurationManager.getStaticPhoneCapability();
7101 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007102 loge("isMultiSimSupportedInternal: no static configuration available");
7103 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007104 }
7105 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007106 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7107 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007108 }
7109 // Check if support of multiple SIMs is restricted by carrier
7110 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007111 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007112 }
7113
Michele0ea7d782019-03-19 14:58:42 -07007114 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007115 }
7116
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007117 /**
7118 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007119 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7120 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7121 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007122 * @param numOfSims number of active sims we want to switch to
7123 */
7124 @Override
7125 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007126 if (numOfSims == 1) {
7127 enforceModifyPermission();
7128 } else {
7129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7130 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7131 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007132 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007133
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007134 try {
Michele30b57b22019-03-01 12:01:14 -08007135 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007136 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007137 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7138 return;
7139 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007140 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
7144 }
7145
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007146 @Override
7147 public boolean isApplicationOnUicc(int subId, int appType) {
7148 enforceReadPrivilegedPermission("isApplicationOnUicc");
7149 Phone phone = getPhone(subId);
7150 if (phone == null) {
7151 return false;
7152 }
7153 final long identity = Binder.clearCallingIdentity();
7154 try {
7155 UiccCard uiccCard = phone.getUiccCard();
7156 if (uiccCard == null) {
7157 return false;
7158 }
7159 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7160 if (uiccProfile == null) {
7161 return false;
7162 }
7163 if (TelephonyManager.APPTYPE_SIM <= appType
7164 && appType <= TelephonyManager.APPTYPE_ISIM) {
7165 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7166 }
7167 return false;
7168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
7171 }
7172
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007173 /**
chen xub4baa772019-04-03 10:23:41 -07007174 * Get whether making changes to modem configurations will trigger reboot.
7175 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007176 */
7177 @Override
chen xub4baa772019-04-03 10:23:41 -07007178 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7180 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7181 return false;
7182 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007183 final long identity = Binder.clearCallingIdentity();
7184 try {
7185 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
7189 }
7190
Nathan Harold29f5f052019-02-15 13:41:57 -08007191 private void updateModemStateMetrics() {
7192 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7193 // TODO: check the state for each modem if the api is ready.
7194 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7195 }
7196
Pengquan Meng3889a572019-01-23 11:16:29 -08007197 @Override
7198 public int[] getSlotsMapping() {
7199 enforceReadPrivilegedPermission("getSlotsMapping");
7200
7201 final long identity = Binder.clearCallingIdentity();
7202 try {
7203 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7204 // All logical slots should have a mapping to a physical slot.
7205 int[] logicalSlotsMapping = new int[phoneCount];
7206 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7207 for (int i = 0; i < slotInfos.length; i++) {
7208 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7209 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7210 }
7211 }
7212 return logicalSlotsMapping;
7213 } finally {
7214 Binder.restoreCallingIdentity(identity);
7215 }
7216 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007217
7218 /**
7219 * Get the IRadio HAL Version
7220 */
7221 @Override
7222 public int getRadioHalVersion() {
7223 Phone phone = getDefaultPhone();
7224 if (phone == null) return -1;
7225 HalVersion hv = phone.getHalVersion();
7226 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7227 return hv.major * 100 + hv.minor;
7228 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007229
7230 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007231 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7232 * corresponding network requests on a subId.
7233 *
7234 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007235 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007236 * 2) APN is un-metered for this subscription, or
7237 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7238 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7239 *
7240 * @return whether data is allowed for a apn type.
7241 *
7242 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007243 */
7244 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007245 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007246 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7247 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007248
7249 // Now that all security checks passes, perform the operation as ourselves.
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 Phone phone = getPhone(subId);
7253 if (phone == null) return false;
7254
Jack Yu41407ee2019-05-13 16:54:09 -07007255 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007256 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
7260 }
7261
7262 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007263 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007264 enforceReadPrivilegedPermission("isApnMetered");
7265
7266 // Now that all security checks passes, perform the operation as ourselves.
7267 final long identity = Binder.clearCallingIdentity();
7268 try {
7269 Phone phone = getPhone(subId);
7270 if (phone == null) return true; // By default return true.
7271
Jack Yu41407ee2019-05-13 16:54:09 -07007272 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007273 } finally {
7274 Binder.restoreCallingIdentity(identity);
7275 }
7276 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007277
7278 @Override
7279 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7280 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7281 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7282 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7283 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7284 }
7285 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7286 Intent intent = new Intent();
7287 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7288 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7289 // Bring up choose default SMS subscription dialog right now
7290 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7291 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7292 mApp.startActivity(intent);
7293 }
chen xud5ca2d52019-05-28 15:20:57 -07007294
7295 @Override
7296 public String getMmsUAProfUrl(int subId) {
7297 //TODO investigate if this API should require proper permission check in R b/133791609
7298 final long identity = Binder.clearCallingIdentity();
7299 try {
7300 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7301 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7302 } finally {
7303 Binder.restoreCallingIdentity(identity);
7304 }
7305 }
7306
7307 @Override
7308 public String getMmsUserAgent(int subId) {
7309 //TODO investigate if this API should require proper permission check in R b/133791609
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
7312 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7313 .getString(com.android.internal.R.string.config_mms_user_agent);
7314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
7317 }
Jack Yub07d4972019-05-28 16:12:25 -07007318
7319 @Override
7320 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7321 enforceModifyPermission();
7322
7323 // Now that all security checks passes, perform the operation as ourselves.
7324 final long identity = Binder.clearCallingIdentity();
7325 try {
7326 Phone phone = getPhone(subId);
7327 if (phone == null) return false;
7328
7329 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
7333 }
7334
7335 @Override
7336 public boolean isDataAllowedInVoiceCall(int subId) {
7337 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7338
7339 // Now that all security checks passes, perform the operation as ourselves.
7340 final long identity = Binder.clearCallingIdentity();
7341 try {
7342 Phone phone = getPhone(subId);
7343 if (phone == null) return false;
7344
7345 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
7348 }
7349 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007350
7351 /**
7352 * Updates whether conference event pacakge handling is enabled.
7353 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7354 * otherwise.
7355 */
7356 @Override
7357 public void setCepEnabled(boolean isCepEnabled) {
7358 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7359
7360 final long identity = Binder.clearCallingIdentity();
7361 try {
7362 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7363 for (Phone phone : PhoneFactory.getPhones()) {
7364 Phone defaultPhone = phone.getImsPhone();
7365 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7366 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7367 ImsPhoneCallTracker imsPhoneCallTracker =
7368 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7369 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7370 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7371 + imsPhone.getMsisdn());
7372 }
7373 }
7374 } finally {
7375 Binder.restoreCallingIdentity(identity);
7376 }
7377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007378}