blob: 12a725ceb3c95dfeaef0188d6ca6a88b63136e56 [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;
changbetty7157e9e2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
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;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070072import android.telephony.CellInfoGsm;
73import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070074import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070086import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070098import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700101import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsMmTelFeature;
109import android.telephony.ims.aidl.IImsRcsFeature;
110import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700112import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.feature.MmTelFeature;
114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700132import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800133import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800135import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700136import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100137import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700170import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800171import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700172import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800174import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700176import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700178import java.io.FileDescriptor;
179import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800182import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800184import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100185import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700187import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190/**
191 * Implementation of the ITelephony interface.
192 */
Santos Cordon117fee72014-05-16 17:56:12 -0700193public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private static final String LOG_TAG = "PhoneInterfaceManager";
195 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
196 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199 // Message codes used with mMainThreadHandler
200 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700201 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
202 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 private static final int CMD_OPEN_CHANNEL = 9;
204 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
205 private static final int CMD_CLOSE_CHANNEL = 11;
206 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800207 private static final int CMD_NV_READ_ITEM = 13;
208 private static final int EVENT_NV_READ_ITEM_DONE = 14;
209 private static final int CMD_NV_WRITE_ITEM = 15;
210 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
211 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
212 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700213 private static final int CMD_RESET_MODEM_CONFIG = 19;
214 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800215 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
216 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
217 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
218 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800219 private static final int CMD_SEND_ENVELOPE = 25;
220 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000221 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
222 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700223 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
224 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
225 private static final int CMD_EXCHANGE_SIM_IO = 31;
226 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800227 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
228 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700229 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700231 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
232 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700233 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
234 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
235 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700237 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
238 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
239 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
240 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700241 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
243 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244 private static final int CMD_SWITCH_SLOTS = 50;
245 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700246 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
247 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
248 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
249 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
250 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
251 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
252 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
253 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700254 private static final int CMD_GET_ALL_CELL_INFO = 60;
255 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
256 private static final int CMD_GET_CELL_LOCATION = 62;
257 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700258 private static final int CMD_MODEM_REBOOT = 64;
259 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700260 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
261 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800262 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
263 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264 private static final int CMD_GET_MODEM_STATUS = 70;
265 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700266 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
267 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700268 private static final int CMD_ERASE_MODEM_CONFIG = 74;
269 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800271 // Parameters of select command.
272 private static final int SELECT_COMMAND = 0xA4;
273 private static final int SELECT_P1 = 0x04;
274 private static final int SELECT_P2 = 0;
275 private static final int SELECT_P3 = 0x10;
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 /** The singleton instance. */
278 private static PhoneInterfaceManager sInstance;
279
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700282 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private AppOpsManager mAppOps;
284 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800285 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800286 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700287 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288
Derek Tan97ebb422014-09-05 16:55:38 -0700289 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
290 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800291 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800292 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700293
Michelecea4cf22018-12-21 15:00:11 -0800294 // String to store multi SIM allowed
295 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
296
Derek Tan740e1672017-06-27 14:56:27 -0700297 // The AID of ISD-R.
298 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
299
yinxub1bed742017-04-17 11:45:04 -0700300 private NetworkScanRequestTracker mNetworkScanRequestTracker;
301
David Kelly5e06a7f2018-03-12 14:10:59 +0000302 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
303 private static final int MANUFACTURER_CODE_LENGTH = 8;
304
Derek Tan89e89d42014-07-08 17:00:10 -0700305 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 * Experiment flag to enable erase modem config on reset network, default value is false
307 */
308 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
309 "reset_network_erase_modem_config_enabled";
310
311 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700312 * A request object to use for transmitting data to an ICC.
313 */
314 private static final class IccAPDUArgument {
315 public int channel, cla, command, p1, p2, p3;
316 public String data;
317
318 public IccAPDUArgument(int channel, int cla, int command,
319 int p1, int p2, int p3, String data) {
320 this.channel = channel;
321 this.cla = cla;
322 this.command = command;
323 this.p1 = p1;
324 this.p2 = p2;
325 this.p3 = p3;
326 this.data = data;
327 }
328 }
329
330 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700331 * A request object to use for transmitting data to an ICC.
332 */
333 private static final class ManualNetworkSelectionArgument {
334 public OperatorInfo operatorInfo;
335 public boolean persistSelection;
336
337 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
338 this.operatorInfo = operatorInfo;
339 this.persistSelection = persistSelection;
340 }
341 }
342
343 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
345 * request after sending. The main thread will notify the request when it is complete.
346 */
347 private static final class MainThreadRequest {
348 /** The argument to use for the request */
349 public Object argument;
350 /** The result of the request that is run on the main thread */
351 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800352 // The subscriber id that this request applies to. Defaults to
353 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
354 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
Nathan Harold92bed182018-10-12 18:16:49 -0700356 // In cases where subId is unavailable, the caller needs to specify the phone.
357 public Phone phone;
358
vagdeviaf9a5b92018-08-15 16:01:53 -0700359 public WorkSource workSource;
360
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 public MainThreadRequest(Object argument) {
362 this.argument = argument;
363 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800364
Nathan Harold92bed182018-10-12 18:16:49 -0700365 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
366 this.argument = argument;
367 if (phone != null) {
368 this.phone = phone;
369 }
370 this.workSource = workSource;
371 }
372
vagdeviaf9a5b92018-08-15 16:01:53 -0700373 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800374 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800375 if (subId != null) {
376 this.subId = subId;
377 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700378 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 }
381
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800382 private static final class IncomingThirdPartyCallArgs {
383 public final ComponentName component;
384 public final String callId;
385 public final String callerDisplayName;
386
387 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
388 String callerDisplayName) {
389 this.component = component;
390 this.callId = callId;
391 this.callerDisplayName = callerDisplayName;
392 }
393 }
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 /**
396 * A handler that processes messages on the main thread in the phone process. Since many
397 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
398 * inbound binder threads to the main thread in the phone process. The Binder thread
399 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
400 * on, which will be notified when the operation completes and will contain the result of the
401 * request.
402 *
403 * <p>If a MainThreadRequest object is provided in the msg.obj field,
404 * note that request.result must be set to something non-null for the calling thread to
405 * unblock.
406 */
407 private final class MainThreadHandler extends Handler {
408 @Override
409 public void handleMessage(Message msg) {
410 MainThreadRequest request;
411 Message onCompleted;
412 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800413 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800415 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
417 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 case CMD_HANDLE_USSD_REQUEST: {
419 request = (MainThreadRequest) msg.obj;
420 final Phone phone = getPhoneFromRequest(request);
421 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
422 String ussdRequest = ussdObject.first;
423 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700424
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 if (!isUssdApiAllowed(request.subId)) {
426 // Carrier does not support use of this API, return failure.
427 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
428 UssdResponse response = new UssdResponse(ussdRequest, null);
429 Bundle returnData = new Bundle();
430 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
431 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700432
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 request.result = true;
434 notifyRequester(request);
435 return;
436 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700437
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 try {
439 request.result = phone != null
440 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
441 } catch (CallStateException cse) {
442 request.result = false;
443 }
444 // Wake up the requesting thread
445 notifyRequester(request);
446 break;
pkanwar32d516d2016-10-14 19:37:38 -0700447 }
448
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 final Phone phone = getPhoneFromRequest(request);
452 request.result = phone != null ?
453 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
454 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800463 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 if (uiccCard == null) {
465 loge("iccTransmitApduLogicalChannel: No UICC");
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
470 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700471 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 iccArgument.channel, iccArgument.cla, iccArgument.command,
473 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700475 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 break;
477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 ar = (AsyncResult) msg.obj;
480 request = (MainThreadRequest) ar.userObj;
481 if (ar.exception == null && ar.result != null) {
482 request.result = ar.result;
483 } else {
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
485 if (ar.result == null) {
486 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800487 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800489 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 } else {
491 loge("iccTransmitApduLogicalChannel: Unknown exception");
492 }
493 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 break;
496
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
498 request = (MainThreadRequest) msg.obj;
499 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800500 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 if (uiccCard == null) {
502 loge("iccTransmitApduBasicChannel: No UICC");
503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 } else {
506 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
507 request);
508 uiccCard.iccTransmitApduBasicChannel(
509 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
510 iccArgument.p3, iccArgument.data, onCompleted);
511 }
512 break;
513
514 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
519 } else {
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
521 if (ar.result == null) {
522 loge("iccTransmitApduBasicChannel: Empty response");
523 } else if (ar.exception instanceof CommandException) {
524 loge("iccTransmitApduBasicChannel: CommandException: " +
525 ar.exception);
526 } else {
527 loge("iccTransmitApduBasicChannel: Unknown exception");
528 }
529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 break;
532
533 case CMD_EXCHANGE_SIM_IO:
534 request = (MainThreadRequest) msg.obj;
535 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 if (uiccCard == null) {
538 loge("iccExchangeSimIO: No UICC");
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 } else {
542 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
543 request);
544 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
545 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
546 iccArgument.data, onCompleted);
547 }
548 break;
549
550 case EVENT_EXCHANGE_SIM_IO_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
555 } else {
556 request.result = new IccIoResult(0x6f, 0, (byte[])null);
557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 break;
560
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 case CMD_SEND_ENVELOPE:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 if (uiccCard == null) {
565 loge("sendEnvelopeWithStatus: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
570 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
571 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 break;
573
574 case EVENT_SEND_ENVELOPE_DONE:
575 ar = (AsyncResult) msg.obj;
576 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700577 if (ar.exception == null && ar.result != null) {
578 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
581 if (ar.result == null) {
582 loge("sendEnvelopeWithStatus: Empty response");
583 } else if (ar.exception instanceof CommandException) {
584 loge("sendEnvelopeWithStatus: CommandException: " +
585 ar.exception);
586 } else {
587 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
588 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 break;
592
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 case CMD_OPEN_CHANNEL:
594 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800595 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800596 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 if (uiccCard == null) {
598 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800599 request.result = new IccOpenLogicalChannelResponse(-1,
600 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 } else {
603 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800604 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
605 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
609 case EVENT_OPEN_CHANNEL_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 int[] result = (int[]) ar.result;
615 int channelId = result[0];
616 byte[] selectResponse = null;
617 if (result.length > 1) {
618 selectResponse = new byte[result.length - 1];
619 for (int i = 1; i < result.length; ++i) {
620 selectResponse[i - 1] = (byte) result[i];
621 }
622 }
623 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 if (ar.result == null) {
627 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 if (ar.exception != null) {
630 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
631 }
632
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700634 if (ar.exception instanceof CommandException) {
635 CommandException.Error error =
636 ((CommandException) (ar.exception)).getCommandError();
637 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700639 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 }
642 }
643 openChannelResp = new IccOpenLogicalChannelResponse(
644 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700646 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
650 case CMD_CLOSE_CHANNEL:
651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800652 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900655 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
659 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
660 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
663 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800664 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
665 break;
666
667 case CMD_NV_READ_ITEM:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800670 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
671 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800672 break;
673
674 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800680 request.result = "";
681 if (ar.result == null) {
682 loge("nvReadItem: Empty response");
683 } else if (ar.exception instanceof CommandException) {
684 loge("nvReadItem: CommandException: " +
685 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800687 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
Jake Hambye994d462014-02-03 13:10:13 -0800693 case CMD_NV_WRITE_ITEM:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
696 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_WRITE_ITEM_DONE:
702 handleNullReturnEvent(msg, "nvWriteItem");
703 break;
704
705 case CMD_NV_WRITE_CDMA_PRL:
706 request = (MainThreadRequest) msg.obj;
707 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800708 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
711 case EVENT_NV_WRITE_CDMA_PRL_DONE:
712 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
713 break;
714
chen xu6dac5ab2018-10-26 17:39:23 -0700715 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800716 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700717 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800718 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800719 break;
720
chen xu6dac5ab2018-10-26 17:39:23 -0700721 case EVENT_RESET_MODEM_CONFIG_DONE:
722 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800723 break;
724
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 case CMD_GET_PREFERRED_NETWORK_TYPE:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700728 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 break;
730
731 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
732 ar = (AsyncResult) msg.obj;
733 request = (MainThreadRequest) ar.userObj;
734 if (ar.exception == null && ar.result != null) {
735 request.result = ar.result; // Integer
736 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800737 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800738 if (ar.result == null) {
739 loge("getPreferredNetworkType: Empty response");
740 } else if (ar.exception instanceof CommandException) {
741 loge("getPreferredNetworkType: CommandException: " +
742 ar.exception);
743 } else {
744 loge("getPreferredNetworkType: Unknown exception");
745 }
746 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case CMD_SET_PREFERRED_NETWORK_TYPE:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
753 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700754 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 break;
756
757 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
758 handleNullReturnEvent(msg, "setPreferredNetworkType");
759 break;
760
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000761 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
762 request = (MainThreadRequest)msg.obj;
763 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 break;
766
767 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
768 ar = (AsyncResult)msg.obj;
769 request = (MainThreadRequest)ar.userObj;
770 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000772 break;
773
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800774 case CMD_SET_VOICEMAIL_NUMBER:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
777 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800778 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
779 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800780 break;
781
782 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
783 handleNullReturnEvent(msg, "setVoicemailNumber");
784 break;
785
Stuart Scott54788802015-03-30 13:18:01 -0700786 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
789 request);
790 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
794 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
795 break;
796
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 case CMD_PERFORM_NETWORK_SCAN:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
800 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
801 break;
802
803 case EVENT_PERFORM_NETWORK_SCAN_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 CellNetworkScanResult cellScanResult;
807 if (ar.exception == null && ar.result != null) {
808 cellScanResult = new CellNetworkScanResult(
809 CellNetworkScanResult.STATUS_SUCCESS,
810 (List<OperatorInfo>) ar.result);
811 } else {
812 if (ar.result == null) {
813 loge("getCellNetworkScanResults: Empty response");
814 }
815 if (ar.exception != null) {
816 loge("getCellNetworkScanResults: Exception: " + ar.exception);
817 }
818 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
819 if (ar.exception instanceof CommandException) {
820 CommandException.Error error =
821 ((CommandException) (ar.exception)).getCommandError();
822 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
824 } else if (error == CommandException.Error.GENERIC_FAILURE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
826 }
827 }
828 cellScanResult = new CellNetworkScanResult(errorCode, null);
829 }
830 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700831 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 break;
833
834 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
835 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700836 ManualNetworkSelectionArgument selArg =
837 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700838 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
839 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700840 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
841 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700842 break;
843
844 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null) {
848 request.result = true;
849 } else {
850 request.result = false;
851 loge("setNetworkSelectionModeManual " + ar.exception);
852 }
853 notifyRequester(request);
854 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700855 break;
856
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700857 case CMD_GET_MODEM_ACTIVITY_INFO:
858 request = (MainThreadRequest) msg.obj;
859 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700860 if (defaultPhone != null) {
861 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
862 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700863 break;
864
865 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
871 if (ar.result == null) {
872 loge("queryModemActivityInfo: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("queryModemActivityInfo: CommandException: " +
875 ar.exception);
876 } else {
877 loge("queryModemActivityInfo: Unknown exception");
878 }
879 }
Amit Mahajand4766222016-01-28 15:28:28 -0800880 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
881 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800882 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800883 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700884 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700885 break;
886
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 case CMD_SET_ALLOWED_CARRIERS:
888 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800889 CarrierRestrictionRules argument =
890 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800892 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 break;
894
895 case EVENT_SET_ALLOWED_CARRIERS_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result;
900 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800901 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
902 if (ar.exception instanceof CommandException) {
903 loge("setAllowedCarriers: CommandException: " + ar.exception);
904 CommandException.Error error =
905 ((CommandException) (ar.exception)).getCommandError();
906 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
907 request.result =
908 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
909 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 } else {
911 loge("setAllowedCarriers: Unknown exception");
912 }
913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700915 break;
916
917 case CMD_GET_ALLOWED_CARRIERS:
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800920 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700921 break;
922
923 case EVENT_GET_ALLOWED_CARRIERS_DONE:
924 ar = (AsyncResult) msg.obj;
925 request = (MainThreadRequest) ar.userObj;
926 if (ar.exception == null && ar.result != null) {
927 request.result = ar.result;
928 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800929 request.result = new IllegalStateException(
930 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700931 if (ar.result == null) {
932 loge("getAllowedCarriers: Empty response");
933 } else if (ar.exception instanceof CommandException) {
934 loge("getAllowedCarriers: CommandException: " +
935 ar.exception);
936 } else {
937 loge("getAllowedCarriers: Unknown exception");
938 }
939 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700941 break;
942
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 if (ar.exception == null && ar.result != null) {
947 request.result = ar.result;
948 } else {
949 request.result = new IllegalArgumentException(
950 "Failed to retrieve Forbidden Plmns");
951 if (ar.result == null) {
952 loge("getForbiddenPlmns: Empty response");
953 } else {
954 loge("getForbiddenPlmns: Unknown exception");
955 }
956 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800958 break;
959
960 case CMD_GET_FORBIDDEN_PLMNS:
961 request = (MainThreadRequest) msg.obj;
962 uiccCard = getUiccCardFromRequest(request);
963 if (uiccCard == null) {
964 loge("getForbiddenPlmns() UiccCard is null");
965 request.result = new IllegalArgumentException(
966 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700967 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800968 break;
969 }
970 Integer appType = (Integer) request.argument;
971 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
972 if (uiccApp == null) {
973 loge("getForbiddenPlmns() no app with specified type -- "
974 + appType);
975 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700976 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800977 break;
978 } else {
979 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
980 + " specified type -- " + appType);
981 }
982 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
983 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
984 onCompleted);
985 break;
986
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000987 case CMD_SWITCH_SLOTS:
988 request = (MainThreadRequest) msg.obj;
989 int[] physicalSlots = (int[]) request.argument;
990 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
991 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
992 break;
993
994 case EVENT_SWITCH_SLOTS_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700998 notifyRequester(request);
999 break;
1000 case CMD_GET_NETWORK_SELECTION_MODE:
1001 request = (MainThreadRequest) msg.obj;
1002 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1003 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1004 break;
1005
1006 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception != null) {
1010 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1011 } else {
1012 int mode = ((int[]) ar.result)[0];
1013 if (mode == 0) {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1015 } else {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1017 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001018 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001019 notifyRequester(request);
1020 break;
1021 case CMD_GET_CDMA_ROAMING_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1024 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1025 break;
1026 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception != null) {
1030 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1031 } else {
1032 request.result = ((int[]) ar.result)[0];
1033 }
1034 notifyRequester(request);
1035 break;
1036 case CMD_SET_CDMA_ROAMING_MODE:
1037 request = (MainThreadRequest) msg.obj;
1038 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1039 int mode = (int) request.argument;
1040 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1041 break;
1042 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
1045 request.result = ar.exception == null;
1046 notifyRequester(request);
1047 break;
1048 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1051 int subscriptionMode = (int) request.argument;
1052 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1053 break;
1054 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 request.result = ar.exception == null;
1058 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001059 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 case CMD_GET_ALL_CELL_INFO:
1061 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001063 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 case EVENT_GET_ALL_CELL_INFO_DONE:
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001068 // If a timeout occurs, the response will be null
1069 request.result = (ar.exception == null && ar.result != null)
1070 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001071 synchronized (request) {
1072 request.notifyAll();
1073 }
1074 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 case CMD_REQUEST_CELL_INFO_UPDATE:
1076 request = (MainThreadRequest) msg.obj;
1077 request.phone.requestCellInfoUpdate(request.workSource,
1078 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1079 break;
1080 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1081 ar = (AsyncResult) msg.obj;
1082 request = (MainThreadRequest) ar.userObj;
1083 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1084 try {
1085 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001086 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001087 cb.onError(
1088 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1089 ar.exception.getClass().getName(),
1090 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001093 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 } else {
1095 // use the result as returned
1096 cb.onCellInfo((List<CellInfo>) ar.result);
1097 }
1098 } catch (RemoteException re) {
1099 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1100 }
1101 break;
1102 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001103 request = (MainThreadRequest) msg.obj;
1104 WorkSource ws = (WorkSource) request.argument;
1105 Phone phone = getPhoneFromRequest(request);
1106 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1107 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001108 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 if (ar.exception == null) {
1112 request.result = ar.result;
1113 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001114 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001115 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1116 ? new CdmaCellLocation() : new GsmCellLocation();
1117 }
1118
1119 synchronized (request) {
1120 request.notifyAll();
1121 }
1122 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001123 case CMD_MODEM_REBOOT:
1124 request = (MainThreadRequest) msg.obj;
1125 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001126 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001127 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001128 case EVENT_CMD_MODEM_REBOOT_DONE:
1129 handleNullReturnEvent(msg, "rebootModem");
1130 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001131 case CMD_REQUEST_ENABLE_MODEM:
1132 request = (MainThreadRequest) msg.obj;
1133 boolean enable = (boolean) request.argument;
1134 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001135 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001136 PhoneConfigurationManager.getInstance()
1137 .enablePhone(request.phone, enable, onCompleted);
1138 break;
1139 case EVENT_ENABLE_MODEM_DONE:
1140 ar = (AsyncResult) msg.obj;
1141 request = (MainThreadRequest) ar.userObj;
1142 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001144 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 if ((boolean) request.result) {
1146 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1147 updateModemStateMetrics();
1148 } else {
1149 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1150 + ar.exception);
1151 }
1152 notifyRequester(request);
1153 break;
1154 case CMD_GET_MODEM_STATUS:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1157 PhoneConfigurationManager.getInstance()
1158 .getPhoneStatusFromModem(request.phone, onCompleted);
1159 break;
1160 case EVENT_GET_MODEM_STATUS_DONE:
1161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 int id = request.phone.getPhoneId();
1164 if (ar.exception == null && ar.result != null) {
1165 request.result = ar.result;
1166 //update the cache as modem status has changed
1167 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1168 (boolean) request.result);
1169 } else {
1170 // Return true if modem status cannot be retrieved. For most cases,
1171 // modem status is on. And for older version modems, GET_MODEM_STATUS
1172 // and disable modem are not supported. Modem is always on.
1173 // TODO: this should be fixed in R to support a third
1174 // status UNKNOWN b/131631629
1175 request.result = true;
1176 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1177 + ar.exception);
1178 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001179 notifyRequester(request);
1180 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001181 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
1184 if (ar.exception == null && ar.result != null) {
1185 request.result = ar.result;
1186 } else {
1187 request.result = -1;
1188 loge("Failed to set Forbidden Plmns");
1189 if (ar.result == null) {
1190 loge("setForbidenPlmns: Empty response");
1191 } else if (ar.exception != null) {
1192 loge("setForbiddenPlmns: Exception: " + ar.exception);
1193 request.result = -1;
1194 } else {
1195 loge("setForbiddenPlmns: Unknown exception");
1196 }
1197 }
1198 notifyRequester(request);
1199 break;
1200 case CMD_SET_FORBIDDEN_PLMNS:
1201 request = (MainThreadRequest) msg.obj;
1202 uiccCard = getUiccCardFromRequest(request);
1203 if (uiccCard == null) {
1204 loge("setForbiddenPlmns: UiccCard is null");
1205 request.result = -1;
1206 notifyRequester(request);
1207 break;
1208 }
1209 Pair<Integer, List<String>> setFplmnsArgs =
1210 (Pair<Integer, List<String>>) request.argument;
1211 appType = setFplmnsArgs.first;
1212 List<String> fplmns = setFplmnsArgs.second;
1213 uiccApp = uiccCard.getApplicationByType(appType);
1214 if (uiccApp == null) {
1215 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1216 request.result = -1;
1217 loge("Failed to get UICC App");
1218 notifyRequester(request);
1219 } else {
1220 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1221 ((SIMRecords) uiccApp.getIccRecords())
1222 .setForbiddenPlmns(onCompleted, fplmns);
1223 }
Naina Nallurid63128d2019-09-17 14:10:30 -07001224 case CMD_ERASE_MODEM_CONFIG:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1227 defaultPhone.eraseModemConfig(onCompleted);
1228 break;
1229 case EVENT_ERASE_MODEM_CONFIG_DONE:
1230 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001231 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 default:
1233 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1234 break;
1235 }
1236 }
Jake Hambye994d462014-02-03 13:10:13 -08001237
Pengquan Menga1bb6272018-09-06 09:59:22 -07001238 private void notifyRequester(MainThreadRequest request) {
1239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 }
1243
Jake Hambye994d462014-02-03 13:10:13 -08001244 private void handleNullReturnEvent(Message msg, String command) {
1245 AsyncResult ar = (AsyncResult) msg.obj;
1246 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1247 if (ar.exception == null) {
1248 request.result = true;
1249 } else {
1250 request.result = false;
1251 if (ar.exception instanceof CommandException) {
1252 loge(command + ": CommandException: " + ar.exception);
1253 } else {
1254 loge(command + ": Unknown exception");
1255 }
1256 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001257 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
1261 /**
1262 * Posts the specified command to be executed on the main thread,
1263 * waits for the request to complete, and returns the result.
1264 * @see #sendRequestAsync
1265 */
1266 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001267 return sendRequest(
1268 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001269 }
1270
1271 /**
1272 * Posts the specified command to be executed on the main thread,
1273 * waits for the request to complete, and returns the result.
1274 * @see #sendRequestAsync
1275 */
1276 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1277 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001278 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001286 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001287 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001288 }
1289
1290 /**
1291 * Posts the specified command to be executed on the main thread,
1292 * waits for the request to complete, and returns the result.
1293 * @see #sendRequestAsync
1294 */
Nathan Harold92bed182018-10-12 18:16:49 -07001295 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1296 return sendRequest(command, argument, subId, null, workSource);
1297 }
1298
1299 /**
1300 * Posts the specified command to be executed on the main thread,
1301 * waits for the request to complete, and returns the result.
1302 * @see #sendRequestAsync
1303 */
1304 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1305 return sendRequest(
1306 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1307 }
1308
1309 /**
1310 * Posts the specified command to be executed on the main thread,
1311 * waits for the request to complete, and returns the result.
1312 * @see #sendRequestAsync
1313 */
1314 private Object sendRequest(
1315 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1317 throw new RuntimeException("This method will deadlock if called from the main thread.");
1318 }
1319
Nathan Harold92bed182018-10-12 18:16:49 -07001320 MainThreadRequest request = null;
1321 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1322 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1323 } else if (phone != null) {
1324 request = new MainThreadRequest(argument, phone, workSource);
1325 } else {
1326 request = new MainThreadRequest(argument, subId, workSource);
1327 }
1328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 Message msg = mMainThreadHandler.obtainMessage(command, request);
1330 msg.sendToTarget();
1331
1332 // Wait for the request to complete
1333 synchronized (request) {
1334 while (request.result == null) {
1335 try {
1336 request.wait();
1337 } catch (InterruptedException e) {
1338 // Do nothing, go back and wait until the request is complete
1339 }
1340 }
1341 }
1342 return request.result;
1343 }
1344
1345 /**
1346 * Asynchronous ("fire and forget") version of sendRequest():
1347 * Posts the specified command to be executed on the main thread, and
1348 * returns immediately.
1349 * @see #sendRequest
1350 */
1351 private void sendRequestAsync(int command) {
1352 mMainThreadHandler.sendEmptyMessage(command);
1353 }
1354
1355 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 */
1359 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 sendRequestAsync(command, argument, null, null);
1361 }
1362
1363 /**
1364 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1365 * @see {@link #sendRequest(int,Object)}
1366 */
1367 private void sendRequestAsync(
1368 int command, Object argument, Phone phone, WorkSource workSource) {
1369 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001370 Message msg = mMainThreadHandler.obtainMessage(command, request);
1371 msg.sendToTarget();
1372 }
1373
1374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 * Initialize the singleton PhoneInterfaceManager instance.
1376 * This is only done once, at startup, from PhoneApp.onCreate().
1377 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001378 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 synchronized (PhoneInterfaceManager.class) {
1380 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 } else {
1383 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1384 }
1385 return sInstance;
1386 }
1387 }
1388
1389 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001390 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001393 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1395 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001396 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001397 mTelephonySharedPreferences =
1398 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001399 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001400 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 publish();
1403 }
1404
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001405 private Phone getDefaultPhone() {
1406 Phone thePhone = getPhone(getDefaultSubscription());
1407 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1408 }
1409
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 private void publish() {
1411 if (DBG) log("publish: " + this);
1412
1413 ServiceManager.addService("phone", this);
1414 }
1415
Stuart Scott584921c2015-01-15 17:10:34 -08001416 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001417 if (request.phone != null) {
1418 return request.phone;
1419 } else {
1420 return getPhoneFromSubId(request.subId);
1421 }
1422 }
1423
1424 private Phone getPhoneFromSubId(int subId) {
1425 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1426 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001427 }
1428
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001429 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1430 Phone phone = getPhoneFromRequest(request);
1431 return phone == null ? null :
1432 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1433 }
1434
Wink Saville36469e72014-06-11 15:17:00 -07001435 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001436 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001437 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439
Naina Nallurid63128d2019-09-17 14:10:30 -07001440 private void sendEraseModemConfig(Phone phone) {
1441 if (phone != null) {
1442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1443 mApp, phone.getSubId(), "eraseModemConfig");
1444 final long identity = Binder.clearCallingIdentity();
1445 try {
1446 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1447 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
1450 }
1451 }
1452 }
1453
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 if (DBG) log("dial: " + number);
1460 // No permission check needed here: This is just a wrapper around the
1461 // ACTION_DIAL intent, which is available to any app since it puts up
1462 // the UI before it does anything.
1463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001464 final long identity = Binder.clearCallingIdentity();
1465 try {
1466 String url = createTelUrl(number);
1467 if (url == null) {
1468 return;
1469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001471 // PENDING: should we just silently fail if phone is offhook or ringing?
1472 PhoneConstants.State state = mCM.getState(subId);
1473 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1474 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1475 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1476 mApp.startActivity(intent);
1477 }
1478 } finally {
1479 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481 }
1482
1483 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001485 }
1486
Wink Savilleb564aae2014-10-23 10:18:09 -07001487 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 if (DBG) log("call: " + number);
1489
1490 // This is just a wrapper around the ACTION_CALL intent, but we still
1491 // need to do a permission check since we're calling startActivity()
1492 // from the context of the phone app.
1493 enforceCallPermission();
1494
Jordan Liu1617b712019-07-10 15:06:26 -07001495 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 != AppOpsManager.MODE_ALLOWED) {
1497 return;
1498 }
1499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001500 final long identity = Binder.clearCallingIdentity();
1501 try {
1502 String url = createTelUrl(number);
1503 if (url == null) {
1504 return;
1505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001507 boolean isValid = false;
1508 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1509 if (slist != null) {
1510 for (SubscriptionInfo subInfoRecord : slist) {
1511 if (subInfoRecord.getSubscriptionId() == subId) {
1512 isValid = true;
1513 break;
1514 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001515 }
Wink Saville08874612014-08-31 19:19:58 -07001516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001517 if (!isValid) {
1518 return;
1519 }
Wink Saville08874612014-08-31 19:19:58 -07001520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001521 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1522 intent.putExtra(SUBSCRIPTION_KEY, subId);
1523 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1524 mApp.startActivity(intent);
1525 } finally {
1526 Binder.restoreCallingIdentity(identity);
1527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 }
1529
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001531 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001532 }
1533
Wink Savilleb564aae2014-10-23 10:18:09 -07001534 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001535 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001536 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1537 }
1538
1539 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001544 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001545 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1546 }
1547
1548 /** {@hide} */
1549 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001550 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001555
1556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1559 checkSimPin.start();
1560 return checkSimPin.unlockSim(null, pin);
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Saville9de0f752013-10-22 19:04:03 -07001566 /** {@hide} */
1567 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001568 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001569 }
1570
Wink Savilleb564aae2014-10-23 10:18:09 -07001571 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001573
1574 final long identity = Binder.clearCallingIdentity();
1575 try {
1576 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1577 checkSimPuk.start();
1578 return checkSimPuk.unlockSim(puk, pin);
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
1581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 }
1583
1584 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001585 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 * a synchronous one.
1587 */
1588 private static class UnlockSim extends Thread {
1589
1590 private final IccCard mSimCard;
1591
1592 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001593 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1594 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595
1596 // For replies from SimCard interface
1597 private Handler mHandler;
1598
1599 // For async handler to identify request type
1600 private static final int SUPPLY_PIN_COMPLETE = 100;
1601
1602 public UnlockSim(IccCard simCard) {
1603 mSimCard = simCard;
1604 }
1605
1606 @Override
1607 public void run() {
1608 Looper.prepare();
1609 synchronized (UnlockSim.this) {
1610 mHandler = new Handler() {
1611 @Override
1612 public void handleMessage(Message msg) {
1613 AsyncResult ar = (AsyncResult) msg.obj;
1614 switch (msg.what) {
1615 case SUPPLY_PIN_COMPLETE:
1616 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1617 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001618 mRetryCount = msg.arg1;
1619 if (ar.exception != null) {
1620 if (ar.exception instanceof CommandException &&
1621 ((CommandException)(ar.exception)).getCommandError()
1622 == CommandException.Error.PASSWORD_INCORRECT) {
1623 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1624 } else {
1625 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1626 }
1627 } else {
1628 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 mDone = true;
1631 UnlockSim.this.notifyAll();
1632 }
1633 break;
1634 }
1635 }
1636 };
1637 UnlockSim.this.notifyAll();
1638 }
1639 Looper.loop();
1640 }
1641
1642 /*
1643 * Use PIN or PUK to unlock SIM card
1644 *
1645 * If PUK is null, unlock SIM card with PIN
1646 *
1647 * If PUK is not null, unlock SIM card with PUK and set PIN code
1648 */
Wink Saville9de0f752013-10-22 19:04:03 -07001649 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650
1651 while (mHandler == null) {
1652 try {
1653 wait();
1654 } catch (InterruptedException e) {
1655 Thread.currentThread().interrupt();
1656 }
1657 }
1658 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1659
1660 if (puk == null) {
1661 mSimCard.supplyPin(pin, callback);
1662 } else {
1663 mSimCard.supplyPuk(puk, pin, callback);
1664 }
1665
1666 while (!mDone) {
1667 try {
1668 Log.d(LOG_TAG, "wait for done");
1669 wait();
1670 } catch (InterruptedException e) {
1671 // Restore the interrupted status
1672 Thread.currentThread().interrupt();
1673 }
1674 }
1675 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001676 int[] resultArray = new int[2];
1677 resultArray[0] = mResult;
1678 resultArray[1] = mRetryCount;
1679 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681 }
1682
1683 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001684 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001685
1686 }
1687
Wink Savilleb564aae2014-10-23 10:18:09 -07001688 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 // No permission check needed here: this call is harmless, and it's
1690 // needed for the ServiceState.requestStateUpdate() call (which is
1691 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 phone.updateServiceLocation();
1697 }
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 }
1702
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001703 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001704 @Override
1705 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001706 return isRadioOnWithFeature(callingPackage, null);
1707 }
1708
1709
1710 @Override
1711 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1712 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1713 callingFeatureId);
1714 }
1715
1716 @Deprecated
1717 @Override
1718 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1719 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001720 }
1721
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001722 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001723 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1724 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001726 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001727 return false;
1728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729
1730 final long identity = Binder.clearCallingIdentity();
1731 try {
1732 return isRadioOnForSubscriber(subId);
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
1735 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001736 }
1737
1738 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 final Phone phone = getPhone(subId);
1742 if (phone != null) {
1743 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1744 } else {
1745 return false;
1746 }
1747 } finally {
1748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
1752 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001753 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755
Wink Savilleb564aae2014-10-23 10:18:09 -07001756 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001758
1759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 final Phone phone = getPhone(subId);
1762 if (phone != null) {
1763 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1764 }
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Wink Saville36469e72014-06-11 15:17:00 -07001768 }
1769
1770 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001771 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001772 }
1773
Wink Savilleb564aae2014-10-23 10:18:09 -07001774 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 final Phone phone = getPhone(subId);
1780 if (phone == null) {
1781 return false;
1782 }
1783 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1784 toggleRadioOnOffForSubscriber(subId);
1785 }
1786 return true;
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
Wink Saville36469e72014-06-11 15:17:00 -07001791
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 public boolean needMobileRadioShutdown() {
1793 /*
1794 * If any of the Radios are available, it will need to be
1795 * shutdown. So return true if any Radio is available.
1796 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1800 Phone phone = PhoneFactory.getPhone(i);
1801 if (phone != null && phone.isRadioAvailable()) return true;
1802 }
1803 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1804 return false;
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001808 }
1809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001810 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 enforceModifyPermission();
1813
1814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1817 logv("Shutting down Phone " + i);
1818 shutdownRadioUsingPhoneId(i);
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001822 }
1823 }
1824
1825 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001826 Phone phone = PhoneFactory.getPhone(phoneId);
1827 if (phone != null && phone.isRadioAvailable()) {
1828 phone.shutdownRadio();
1829 }
1830 }
1831
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1838 if (defaultPhone != null) {
1839 defaultPhone.setRadioPower(turnOn);
1840 return true;
1841 } else {
1842 loge("There's no default phone.");
1843 return false;
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001847 }
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone != null) {
1857 phone.setRadioPower(turnOn);
1858 return true;
1859 } else {
1860 return false;
1861 }
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 }
1866
Wink Saville36469e72014-06-11 15:17:00 -07001867 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 public boolean enableDataConnectivity() {
1870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 int subId = mSubscriptionController.getDefaultDataSubId();
1875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001877 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878 return true;
1879 } else {
1880 return false;
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
Wink Saville36469e72014-06-11 15:17:00 -07001887 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 public boolean disableDataConnectivity() {
1890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 int subId = mSubscriptionController.getDefaultDataSubId();
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001897 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 return true;
1899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001908 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 final long identity = Binder.clearCallingIdentity();
1910 try {
1911 final Phone phone = getPhone(subId);
1912 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001913 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 } else {
1915 return false;
1916 }
1917 } finally {
1918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
1922 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001923 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001924 }
1925
pkanwarae03a6b2016-11-06 20:37:09 -08001926 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 enforceCallPermission();
1928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return;
1933 }
1934 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1935 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
1938 }
pkanwar32d516d2016-10-14 19:37:38 -07001939 };
1940
Wink Savilleb564aae2014-10-23 10:18:09 -07001941 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001943
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
1946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1947 return false;
1948 }
1949 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001956 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001959 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960 final long identity = Binder.clearCallingIdentity();
1961 try {
1962 Phone phone = PhoneFactory.getPhone(slotIndex);
1963 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1964 PhoneConstantConversions.convertCallState(phone.getState());
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001971 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001972 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1973 }
1974
1975 @Override
1976 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001977 final long identity = Binder.clearCallingIdentity();
1978 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001979 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 if (phone != null) {
1981 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1982 } else {
1983 return PhoneConstantConversions.convertDataState(
1984 PhoneConstants.DataState.DISCONNECTED);
1985 }
1986 } finally {
1987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001992 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001993 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1994 }
1995
1996 @Override
1997 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 final long identity = Binder.clearCallingIdentity();
1999 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002000 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001 if (phone != null) {
2002 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2003 } else {
2004 return TelephonyManager.DATA_ACTIVITY_NONE;
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002012 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002013 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002014 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002015
2016 LocationAccessPolicy.LocationPermissionResult locationResult =
2017 LocationAccessPolicy.checkLocationPermission(mApp,
2018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2019 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002020 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002021 .setCallingPid(Binder.getCallingPid())
2022 .setCallingUid(Binder.getCallingUid())
2023 .setMethod("getCellLocation")
2024 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2025 .build());
2026 switch (locationResult) {
2027 case DENIED_HARD:
2028 throw new SecurityException("Not allowed to access cell location");
2029 case DENIED_SOFT:
2030 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034 final long identity = Binder.clearCallingIdentity();
2035 try {
2036 if (DBG_LOC) log("getCellLocation: is active user");
2037 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002038 int subId = mSubscriptionController.getDefaultDataSubId();
2039 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2040 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 return data;
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Svetoslav64fad262015-04-14 14:35:21 -07002045 }
2046
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002048 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2049 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002050 if (!TextUtils.isEmpty(callingPackage)) {
2051 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2053 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002054 return "";
2055 }
2056 }
2057
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002058 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2059 // registered cell info, so return a NULL country instead.
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002062 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2063 // Get default phone in this case.
2064 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2065 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002067 // Todo: fix this when we can get the actual cellular network info when the device
2068 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002069 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002070 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2071 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002072 return "";
2073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 Phone phone = PhoneFactory.getPhone(phoneId);
2075 if (phone != null) {
2076 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002077 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 if (sst != null) {
2079 LocaleTracker lt = sst.getLocaleTracker();
2080 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002081 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2082 return lt.getCurrentCountry();
2083 } else if (emergencyNumberTracker != null) {
2084 return emergencyNumberTracker.getEmergencyCountryIso();
2085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 }
2087 }
2088 }
2089 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002090 } finally {
2091 Binder.restoreCallingIdentity(identity);
2092 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002093 }
2094
2095 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002097 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002098 }
2099
Sanket Padawe356d7632015-06-22 14:03:32 -07002100 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002101 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 mApp.enforceCallingOrSelfPermission(
2103 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104
2105 final long identity = Binder.clearCallingIdentity();
2106 try {
2107 final Phone phone = getPhone(subId);
2108 if (phone != null) {
2109 phone.enableLocationUpdates();
2110 }
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
2116 @Override
2117 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002118 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002119 }
2120
Sanket Padawe356d7632015-06-22 14:03:32 -07002121 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002122 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 mApp.enforceCallingOrSelfPermission(
2124 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125
2126 final long identity = Binder.clearCallingIdentity();
2127 try {
2128 final Phone phone = getPhone(subId);
2129 if (phone != null) {
2130 phone.disableLocationUpdates();
2131 }
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
2136
Nathan Harold31d7ff32018-10-15 20:20:30 -07002137 /**
2138 * Returns the target SDK version number for a given package name.
2139 *
Nathan Haroldec184742019-07-10 17:04:16 -07002140 * This call MUST be invoked before clearing the calling UID.
2141 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002142 * @return target SDK if the package is found or INT_MAX.
2143 */
2144 private int getTargetSdk(String packageName) {
2145 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002146 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002147 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002148 if (ai != null) return ai.targetSdkVersion;
2149 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002150 loge("Failed to get package info for pkg="
2151 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002152 }
2153 return Integer.MAX_VALUE;
2154 }
2155
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 @Override
2157 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002158 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2159 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002160 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002161 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2162 throw new SecurityException(
2163 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2164 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002165
Jordan Liu1617b712019-07-10 15:06:26 -07002166 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2168 return null;
2169 }
Svetoslav64fad262015-04-14 14:35:21 -07002170
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002171 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002173 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002174 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175
Nathan Haroldf180aac2018-06-01 18:43:55 -07002176 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2177 for (CellInfo ci : info) {
2178 if (ci instanceof CellInfoGsm) {
2179 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2180 } else if (ci instanceof CellInfoWcdma) {
2181 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002184 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002187 private List<CellInfo> getCachedCellInfo() {
2188 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2189 for (Phone phone : PhoneFactory.getPhones()) {
2190 List<CellInfo> info = phone.getAllCellInfo();
2191 if (info != null) cellInfos.addAll(info);
2192 }
2193 return cellInfos;
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195
2196 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002197 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002198 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002199 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002200
2201 LocationAccessPolicy.LocationPermissionResult locationResult =
2202 LocationAccessPolicy.checkLocationPermission(mApp,
2203 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2204 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002205 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002206 .setCallingPid(Binder.getCallingPid())
2207 .setCallingUid(Binder.getCallingUid())
2208 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002209 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002210 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2211 .build());
2212 switch (locationResult) {
2213 case DENIED_HARD:
2214 throw new SecurityException("Not allowed to access cell info");
2215 case DENIED_SOFT:
2216 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002219 final int targetSdk = getTargetSdk(callingPackage);
2220 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2221 return getCachedCellInfo();
2222 }
2223
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002224 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 final long identity = Binder.clearCallingIdentity();
2227 try {
2228 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2229 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002230 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002231 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 if (info != null) cellInfos.addAll(info);
2233 }
2234 return cellInfos;
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238 }
2239
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002240 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002241 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2242 String callingFeatureId) {
2243 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2244 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 }
2246
2247 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2249 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002251 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002252 }
2253
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002254 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2255 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002256 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002257 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002258
2259 LocationAccessPolicy.LocationPermissionResult locationResult =
2260 LocationAccessPolicy.checkLocationPermission(mApp,
2261 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2262 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002263 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002264 .setCallingPid(Binder.getCallingPid())
2265 .setCallingUid(Binder.getCallingUid())
2266 .setMethod("requestCellInfoUpdate")
2267 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2268 .build());
2269 switch (locationResult) {
2270 case DENIED_HARD:
2271 throw new SecurityException("Not allowed to access cell info");
2272 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002273 try {
2274 cb.onCellInfo(new ArrayList<CellInfo>());
2275 } catch (RemoteException re) {
2276 // Drop without consequences
2277 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002278 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002279 }
2280
Nathan Harolda939a962019-05-09 10:13:47 -07002281
2282 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002283 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2284
2285 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2286 }
2287
2288 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002290 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002291 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002295 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
Shishir Agrawala9f32182016-04-12 12:00:16 -07002301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002302 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 Phone phone = PhoneFactory.getPhone(slotIndex);
2304 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 return null;
2306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002308 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002309 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 return null;
2311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 return phone.getImei();
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
2318 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002319 }
2320
2321 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002322 public String getTypeAllocationCodeForSlot(int slotIndex) {
2323 Phone phone = PhoneFactory.getPhone(slotIndex);
2324 String tac = null;
2325 if (phone != null) {
2326 String imei = phone.getImei();
2327 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2328 }
2329 return tac;
2330 }
2331
2332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002333 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002334 Phone phone = PhoneFactory.getPhone(slotIndex);
2335 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002336 return null;
2337 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002338
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002340 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002341 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002342 return null;
2343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 return phone.getMeid();
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
2350 }
Jack Yu2af8d712017-03-15 17:14:14 -07002351 }
2352
2353 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002354 public String getManufacturerCodeForSlot(int slotIndex) {
2355 Phone phone = PhoneFactory.getPhone(slotIndex);
2356 String manufacturerCode = null;
2357 if (phone != null) {
2358 String meid = phone.getMeid();
2359 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2360 }
2361 return manufacturerCode;
2362 }
2363
2364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002365 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2366 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002367 Phone phone = PhoneFactory.getPhone(slotIndex);
2368 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002369 return null;
2370 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002371 int subId = phone.getSubId();
2372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002373 mApp, subId, callingPackage, callingFeatureId,
2374 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002375 return null;
2376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 return phone.getDeviceSvn();
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002384 }
2385
fionaxu43304da2017-11-27 22:51:16 -08002386 @Override
2387 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
fionaxu43304da2017-11-27 22:51:16 -08002395 }
2396
2397 @Override
2398 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 final Phone phone = getPhone(subId);
2402 return phone == null ? null : phone.getCarrierName();
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
fionaxu43304da2017-11-27 22:51:16 -08002406 }
2407
calvinpanffe225e2018-11-01 19:43:06 +08002408 @Override
chen xu0026ca62019-03-06 15:28:50 -08002409 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 final Phone phone = getPhone(subId);
2413 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002414 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002415 } finally {
2416 Binder.restoreCallingIdentity(identity);
2417 }
2418 }
2419
2420 @Override
chen xu0026ca62019-03-06 15:28:50 -08002421 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002425 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
chen xu651eec72018-11-11 19:03:44 -08002431 @Override
chen xu864e11c2018-12-06 22:10:03 -08002432 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2433 if (!isSubscriptionMccMnc) {
2434 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2435 }
chen xu651eec72018-11-11 19:03:44 -08002436 final Phone phone = PhoneFactory.getPhone(slotIndex);
2437 if (phone == null) {
2438 return TelephonyManager.UNKNOWN_CARRIER_ID;
2439 }
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
2445 }
2446 }
2447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 //
2449 // Internal helper methods.
2450 //
2451
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002452 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2454 *
2455 * @throws SecurityException if the caller does not have the required permission
2456 */
2457 private void enforceModifyPermission() {
2458 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2459 }
2460
Shuo Qian3b6ee772019-11-13 17:43:31 -08002461 private void enforceActiveEmergencySessionPermission() {
2462 mApp.enforceCallingOrSelfPermission(
2463 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 /**
2467 * Make sure the caller has the CALL_PHONE permission.
2468 *
2469 * @throws SecurityException if the caller does not have the required permission
2470 */
2471 private void enforceCallPermission() {
2472 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2473 }
2474
paulhu5a773602019-08-23 19:17:33 +08002475 private void enforceSettingsPermission() {
2476 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002477 }
2478
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 private String createTelUrl(String number) {
2480 if (TextUtils.isEmpty(number)) {
2481 return null;
2482 }
2483
Jake Hambye994d462014-02-03 13:10:13 -08002484 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Ihab Awadf9e92732013-12-05 18:02:52 -08002487 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2489 }
2490
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002491 private static void logv(String msg) {
2492 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2493 }
2494
Ihab Awadf9e92732013-12-05 18:02:52 -08002495 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2497 }
2498
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002499 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002501 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002502 }
2503
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002505 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = PhoneFactory.getPhone(slotIndex);
2509 if (phone == null) {
2510 return PhoneConstants.PHONE_TYPE_NONE;
2511 } else {
2512 return phone.getPhoneType();
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 icon index to display
2521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002523 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2524 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2525 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002526 }
2527
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2530 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002532 mApp, subId, callingPackage, callingFeatureId,
2533 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 return -1;
2535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 final Phone phone = getPhone(subId);
2540 if (phone != null) {
2541 return phone.getCdmaEriIconIndex();
2542 } else {
2543 return -1;
2544 }
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
2550 /**
2551 * Returns the CDMA ERI icon mode,
2552 * 0 - ON
2553 * 1 - FLASHING
2554 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002556 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2557 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2558 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002559 }
2560
Sanket Padawe356d7632015-06-22 14:03:32 -07002561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002562 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2563 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002565 mApp, subId, callingPackage, callingFeatureId,
2566 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002567 return -1;
2568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 return phone.getCdmaEriIconMode();
2575 } else {
2576 return -1;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
2583 /**
2584 * Returns the CDMA ERI text,
2585 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002587 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2588 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2589 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002590 }
2591
Sanket Padawe356d7632015-06-22 14:03:32 -07002592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2594 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002596 mApp, subId, callingPackage, callingFeatureId,
2597 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002598 return null;
2599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600
2601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 final Phone phone = getPhone(subId);
2604 if (phone != null) {
2605 return phone.getCdmaEriText();
2606 } else {
2607 return null;
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613
2614 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002615 * Returns the CDMA MDN.
2616 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002618 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2620 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621
2622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 return phone.getLine1Number();
2627 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002628 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 return null;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002633 }
2634 }
2635
2636 /**
2637 * Returns the CDMA MIN.
2638 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002639 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002640 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2642 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2648 return phone.getCdmaMin();
2649 } else {
2650 return null;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002654 }
2655 }
2656
Hall Liud892bec2018-11-30 14:51:45 -08002657 @Override
2658 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2659 INumberVerificationCallback callback, String callingPackage) {
2660 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2661 != PERMISSION_GRANTED) {
2662 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2663 }
2664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2665
2666 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2667 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2668 throw new SecurityException("Calling package must be configured in the device config");
2669 }
2670
2671 if (range == null) {
2672 throw new NullPointerException("Range must be non-null");
2673 }
2674
2675 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002676 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002677
2678 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2679 }
2680
Junda Liuca05d5d2014-08-14 22:36:34 -07002681 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 * Returns true if CDMA provisioning needs to run.
2683 */
2684 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 final long identity = Binder.clearCallingIdentity();
2686 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002687 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
2693 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002694 * Sets the voice mail number of a given subId.
2695 */
2696 @Override
2697 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002698 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2703 new Pair<String, String>(alphaTag, number), new Integer(subId));
2704 return success;
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002708 }
2709
Ta-wei Yen87c49842016-05-13 21:19:52 -07002710 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002711 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002713 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2714 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002715 if (!TextUtils.equals(callingPackage, systemDialer)) {
2716 throw new SecurityException("caller must be system dialer");
2717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2722 if (phoneAccountHandle == null) {
2723 return null;
2724 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002728 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002729 }
2730
2731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002732 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2733 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002736 mApp, subId, callingPackage, callingFeatureId,
2737 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002738 return null;
2739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002741 final long identity = Binder.clearCallingIdentity();
2742 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002743 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002744 } finally {
2745 Binder.restoreCallingIdentity(identity);
2746 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002747 }
2748
2749 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002750 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2751 VisualVoicemailSmsFilterSettings settings) {
2752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002757 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002761 }
2762
2763 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002764 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2765 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002770 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 } finally {
2772 Binder.restoreCallingIdentity(identity);
2773 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002774 }
2775
2776 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002777 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2778 String callingPackage, int subId) {
2779 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002784 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002788 }
2789
2790 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002791 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002792 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002797 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002801 }
2802
2803 @Override
2804 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2805 String number, int port, String text, PendingIntent sentIntent) {
2806 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002807 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002808 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002809 SmsController smsController = PhoneFactory.getSmsController();
2810 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2811 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002812 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002813
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002814 /**
fionaxu0152e512016-11-14 13:36:14 -08002815 * Sets the voice activation state of a given subId.
2816 */
2817 @Override
2818 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2820 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 final Phone phone = getPhone(subId);
2825 if (phone != null) {
2826 phone.setVoiceActivationState(activationState);
2827 } else {
2828 loge("setVoiceActivationState fails with invalid subId: " + subId);
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002832 }
2833 }
2834
2835 /**
2836 * Sets the data activation state of a given subId.
2837 */
2838 @Override
2839 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2841 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 final Phone phone = getPhone(subId);
2846 if (phone != null) {
2847 phone.setDataActivationState(activationState);
2848 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002849 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002853 }
2854 }
2855
2856 /**
2857 * Returns the voice activation state of a given subId.
2858 */
2859 @Override
2860 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
fionaxu0152e512016-11-14 13:36:14 -08002863 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 if (phone != null) {
2867 return phone.getVoiceActivationState();
2868 } else {
2869 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002873 }
2874 }
2875
2876 /**
2877 * Returns the data activation state of a given subId.
2878 */
2879 @Override
2880 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002881 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
fionaxu0152e512016-11-14 13:36:14 -08002883 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 if (phone != null) {
2887 return phone.getDataActivationState();
2888 } else {
2889 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2890 }
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002893 }
2894 }
2895
2896 /**
Wink Saville36469e72014-06-11 15:17:00 -07002897 * Returns the unread count of voicemails for a subId
2898 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002900 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2901 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 mApp, subId, callingPackage, callingFeatureId,
2904 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002905 return 0;
2906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 final Phone phone = getPhone(subId);
2910 if (phone != null) {
2911 return phone.getVoiceMessageCount();
2912 } else {
2913 return 0;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 }
2919
2920 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002921 * returns true, if the device is in a state where both voice and data
2922 * are supported simultaneously. This can change based on location or network condition.
2923 */
2924 @Override
2925 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 final Phone phone = getPhone(subId);
2929 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002933 }
2934
2935 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002936 * Send the dialer code if called from the current default dialer or the caller has
2937 * carrier privilege.
2938 * @param inputCode The dialer code to send
2939 */
2940 @Override
2941 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002942 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002943 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002944 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2945 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002946 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002947 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2948 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
fionaxu235cc5e2017-03-06 22:25:57 -08002957 }
2958
Pengquan Menga1bb6272018-09-06 09:59:22 -07002959 @Override
2960 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002961 if (!isActiveSubscription(subId)) {
2962 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2963 }
2964
Pengquan Menga1bb6272018-09-06 09:59:22 -07002965 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2966 }
2967
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002969 public boolean isInEmergencySmsMode() {
2970 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 for (Phone phone : PhoneFactory.getPhones()) {
2974 if (phone.isInEmergencySmsMode()) {
2975 return true;
2976 }
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 return false;
2982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2986 throws RemoteException {
2987 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002988 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2989 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2990 "IMS not available on device.");
2991 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 final long token = Binder.clearCallingIdentity();
2993 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002997 } catch (ImsException e) {
2998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 } finally {
3000 Binder.restoreCallingIdentity(token);
3001 }
3002 }
3003
3004 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003005 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3006 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3008 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3009 }
Meng Wangafbc5852019-09-19 17:37:13 -07003010 final long token = Binder.clearCallingIdentity();
3011 try {
3012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3013 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3014 .removeRegistrationCallbackForSubscription(c, subId);
3015 } catch (ImsException e) {
3016 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3017 + "is inactive, ignoring unregister.");
3018 // If the subscription is no longer active, just return, since the callback
3019 // will already have been removed internally.
3020 } finally {
3021 Binder.restoreCallingIdentity(token);
3022 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003023 }
3024
Brad Ebingera34a6c22019-10-22 17:36:18 -07003025 /**
3026 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3027 */
3028 @Override
3029 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3030 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3031 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3033 "IMS not available on device.");
3034 }
3035 final long token = Binder.clearCallingIdentity();
3036 try {
3037 Phone phone = getPhone(subId);
3038 if (phone == null) {
3039 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3040 + subId + "'");
3041 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3042 }
3043 phone.getImsRegistrationState(regState -> {
3044 try {
3045 consumer.accept((regState == null)
3046 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3047 } catch (RemoteException e) {
3048 // Ignore if the remote process is no longer available to call back.
3049 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3050 }
3051 });
3052 } finally {
3053 Binder.restoreCallingIdentity(token);
3054 }
3055 }
3056
3057 /**
3058 * Get the transport type for the IMS service registration state.
3059 */
3060 @Override
3061 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3062 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3063 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3064 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3065 "IMS not available on device.");
3066 }
3067 final long token = Binder.clearCallingIdentity();
3068 try {
3069 Phone phone = getPhone(subId);
3070 if (phone == null) {
3071 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3072 + subId + "'");
3073 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3074 }
3075 phone.getImsRegistrationTech(regTech -> {
3076 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3077 int regTechConverted = (regTech == null)
3078 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3079 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3080 regTechConverted);
3081 try {
3082 consumer.accept(regTechConverted);
3083 } catch (RemoteException e) {
3084 // Ignore if the remote process is no longer available to call back.
3085 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3086 }
3087 });
3088 } finally {
3089 Binder.restoreCallingIdentity(token);
3090 }
3091 }
3092
Brad Ebinger35c841c2018-10-01 10:40:55 -07003093 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003094 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3095 throws RemoteException {
3096 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003097 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3098 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3099 "IMS not available on device.");
3100 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3102 final long token = Binder.clearCallingIdentity();
3103 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003105 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003106 } catch (ImsException e) {
3107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 } finally {
3109 Binder.restoreCallingIdentity(token);
3110 }
3111 }
3112
3113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003114 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3115 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003116 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3117 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3118 }
Meng Wangafbc5852019-09-19 17:37:13 -07003119
3120 final long token = Binder.clearCallingIdentity();
3121 try {
3122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3123 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003124 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003125 } catch (ImsException e) {
3126 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3127 + "is inactive, ignoring unregister.");
3128 // If the subscription is no longer active, just return, since the callback
3129 // will already have been removed internally.
3130 } finally {
3131 Binder.restoreCallingIdentity(token);
3132 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 }
3134
3135 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003136 public boolean isCapable(int subId, int capability, int regTech) {
3137 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3139 final long token = Binder.clearCallingIdentity();
3140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003143 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3145 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003146 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003147 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3148 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 } finally {
3150 Binder.restoreCallingIdentity(token);
3151 }
3152 }
3153
3154 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003155 public boolean isAvailable(int subId, int capability, int regTech) {
3156 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003157 final long token = Binder.clearCallingIdentity();
3158 try {
3159 Phone phone = getPhone(subId);
3160 if (phone == null) return false;
3161 return phone.isImsCapabilityAvailable(capability, regTech);
3162 } finally {
3163 Binder.restoreCallingIdentity(token);
3164 }
3165 }
3166
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003167 /**
3168 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3169 * subscription.
3170 * @param subId The subscription to use to check the configuration.
3171 * @param callback The callback that will be used to send the result.
3172 * @param capability The MmTelFeature capability that will be used to send the result.
3173 * @param transportType The transport type of the MmTelFeature capability.
3174 */
3175 @Override
3176 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3177 int transportType) {
3178 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3179 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3180 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3181 "IMS not available on device.");
3182 }
3183 final long token = Binder.clearCallingIdentity();
3184 try {
3185 int slotId = getSlotIndex(subId);
3186 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3187 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3188 + subId + "'");
3189 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3190 }
3191 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3192 transportType, aBoolean -> {
3193 try {
3194 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3195 } catch (RemoteException e) {
3196 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3197 + "running. Ignore");
3198 }
3199 });
3200 } finally {
3201 Binder.restoreCallingIdentity(token);
3202 }
3203 }
3204
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 @Override
3206 public boolean isAdvancedCallingSettingEnabled(int subId) {
3207 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3209 final long token = Binder.clearCallingIdentity();
3210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003211 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003213 } catch (ImsException e) {
3214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 } finally {
3216 Binder.restoreCallingIdentity(token);
3217 }
3218 }
3219
3220 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003221 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003223 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003229 } catch (ImsException e) {
3230 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 } finally {
3232 Binder.restoreCallingIdentity(identity);
3233 }
3234 }
3235
3236 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003237 public boolean isVtSettingEnabled(int subId) {
3238 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3243 } catch (ImsException e) {
3244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
3248 }
3249
3250 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003251 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003253 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003257 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003258 } catch (ImsException e) {
3259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
3263 }
3264
3265 @Override
3266 public boolean isVoWiFiSettingEnabled(int subId) {
3267 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003273 } catch (ImsException e) {
3274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
3278 }
3279
3280 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003281 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003283 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003287 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003288 } catch (ImsException e) {
3289 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
3293 }
3294
3295 @Override
3296 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3297 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003301 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003303 } catch (ImsException e) {
3304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003311 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003313 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3329 "setVoWiFiNonPersistent");
3330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003334 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003335 } catch (ImsException e) {
3336 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
3340 }
3341
3342 @Override
3343 public int getVoWiFiModeSetting(int subId) {
3344 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003350 } catch (ImsException e) {
3351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
3357 @Override
3358 public void setVoWiFiModeSetting(int subId, int mode) {
3359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3360 "setVoWiFiModeSetting");
3361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003366 } catch (ImsException e) {
3367 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
3373 @Override
3374 public int getVoWiFiRoamingModeSetting(int subId) {
3375 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003381 } catch (ImsException e) {
3382 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
3389 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3391 "setVoWiFiRoamingModeSetting");
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003395 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003397 } catch (ImsException e) {
3398 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
3402 }
3403
3404 @Override
3405 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3407 "setRttCapabilityEnabled");
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3412 } catch (ImsException e) {
3413 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
3417 }
3418
3419 @Override
3420 public boolean isTtyOverVolteEnabled(int subId) {
3421 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003427 } catch (ImsException e) {
3428 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
3432 }
3433
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 @Override
3435 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3436 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003440 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003441 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003442 } catch (ImsException e) {
3443 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
3447 }
3448
3449 @Override
3450 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3451 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3452 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003453 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3454 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3455 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003456 try {
3457 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003458 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003459 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003460 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003461 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3462 + "is inactive, ignoring unregister.");
3463 // If the subscription is no longer active, just return, since the callback will already
3464 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
3468 }
3469
3470 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003471 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3472 boolean isProvisioned) {
3473 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3474 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3475 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3476 }
3477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3478 "setProvisioningStatusForCapability");
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3482 Phone phone = getPhone(subId);
3483 if (phone == null) {
3484 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3485 + subId);
3486 return;
3487 }
3488 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3489 return;
3490 }
3491
3492 // this capability requires provisioning, route to the correct API.
3493 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3494 switch (capability) {
3495 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3496 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3497 ims.setVolteProvisioned(isProvisioned);
3498 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3499 ims.setWfcProvisioned(isProvisioned);
3500 }
3501 break;
3502 }
3503 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3504 // There is currently no difference in VT provisioning type.
3505 ims.setVtProvisioned(isProvisioned);
3506 break;
3507 }
3508 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3509 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3510 // change the capability of the feature instead if needed.
3511 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3512 == isProvisioned) {
3513 // No change in provisioning.
3514 return;
3515 }
3516 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3517 try {
3518 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003519 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003520 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3521 + ", Exception" + e.getMessage());
3522 }
3523 break;
3524 }
3525 default: {
3526 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3527 + capability + "', which does not require provisioning.");
3528 }
3529 }
3530
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
3534 }
3535
3536 @Override
3537 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3538 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3539 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3540 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3541 }
3542 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3546 Phone phone = getPhone(subId);
3547 if (phone == null) {
3548 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3549 + subId);
3550 // We will fail with "true" as the provisioning status because this is the default
3551 // if we do not require provisioning.
3552 return true;
3553 }
3554
3555 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3556 return true;
3557 }
3558
3559 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3560 switch (capability) {
3561 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3562 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3563 return ims.isVolteProvisionedOnDevice();
3564 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3565 return ims.isWfcProvisionedOnDevice();
3566 }
3567 // This should never happen, since we are checking tech above to make sure it
3568 // is either LTE or IWLAN.
3569 throw new IllegalArgumentException("Invalid radio technology for voice "
3570 + "capability.");
3571 }
3572 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3573 // There is currently no difference in VT provisioning type.
3574 return ims.isVtProvisionedOnDevice();
3575 }
3576 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3577 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3578 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3579 }
3580 default: {
3581 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3582 + capability + "', which does not require provisioning.");
3583 }
3584 }
3585
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
3589 }
3590
3591 @Override
3592 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3593 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3594 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3595 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3596 }
3597 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3598 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3599 return (provisionedBits & capability) > 0;
3600 }
3601
3602 @Override
3603 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3604 boolean isProvisioned) {
3605 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3606 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3607 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3608 }
3609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3610 "setProvisioningStatusForCapability");
3611 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3612 // If the current provisioning status for capability already matches isProvisioned,
3613 // do nothing.
3614 if (((provisionedBits & capability) > 0) == isProvisioned) {
3615 return;
3616 }
3617 if (isProvisioned) {
3618 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3619 } else {
3620 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3621 }
3622 }
3623
3624 /**
3625 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3626 * technology. The bitfield should mirror the bitfield defined by
3627 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3628 */
3629 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3630 String key = getMmTelProvisioningKey(subId, tech);
3631 // Default is no capabilities are provisioned.
3632 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3633 }
3634
3635 /**
3636 * Sets the MmTel capability provisioning bitfield (defined by
3637 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3638 * technology specified.
3639 *
3640 * Note: This is a synchronous command and should not be called on UI thread.
3641 */
3642 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3643 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3644 String key = getMmTelProvisioningKey(subId, tech);
3645 editor.putInt(key, newField);
3646 editor.commit();
3647 }
3648
3649 private static String getMmTelProvisioningKey(int subId, int tech) {
3650 // resulting key is provision_ims_mmtel_{subId}_{tech}
3651 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3652 }
3653
3654 /**
3655 * Query CarrierConfig to see if the specified capability requires provisioning for the
3656 * carrier associated with the subscription id.
3657 */
3658 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3659 int capability) {
3660 CarrierConfigManager configManager = new CarrierConfigManager(context);
3661 PersistableBundle c = configManager.getConfigForSubId(subId);
3662 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003663 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003664 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3665 false);
3666 boolean requireVoiceVtProvisioning = c.getBoolean(
3667 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3668
3669 // First check to make sure that the capability requires provisioning.
3670 switch (capability) {
3671 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3672 // intentional fallthrough
3673 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3674 if (requireVoiceVtProvisioning) {
3675 // Voice and Video requires provisioning
3676 return true;
3677 }
3678 break;
3679 }
3680 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3681 if (requireUtProvisioning) {
3682 // UT requires provisioning
3683 return true;
3684 }
3685 break;
3686 }
3687 }
3688 return false;
3689 }
3690
3691 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003692 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003693 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3694 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3695 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003696 enforceReadPrivilegedPermission("getImsProvisioningInt");
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003700 int slotId = getSlotIndex(subId);
3701 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3702 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3703 + subId + "' for key:" + key);
3704 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3705 }
3706 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003707 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003708 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3709 + subId + "' for key:" + key);
3710 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
3716 @Override
3717 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003718 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3719 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3720 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003721 enforceReadPrivilegedPermission("getImsProvisioningString");
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003725 int slotId = getSlotIndex(subId);
3726 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3727 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3728 + subId + "' for key:" + key);
3729 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3730 }
3731 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003732 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003733 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3734 + subId + "' for key:" + key);
3735 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
3739 }
3740
3741 @Override
3742 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003743 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3744 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3745 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3747 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003751 int slotId = getSlotIndex(subId);
3752 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3753 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3754 + subId + "' for key:" + key);
3755 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3756 }
3757 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003759 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3760 + "' for key:" + key);
3761 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
3765 }
3766
3767 @Override
3768 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3770 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3771 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3773 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003777 int slotId = getSlotIndex(subId);
3778 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3779 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3780 + subId + "' for key:" + key);
3781 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3782 }
3783 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003784 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003785 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3786 + "' for key:" + key);
3787 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
3791 }
3792
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003793 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 int slotId = SubscriptionManager.getSlotIndex(subId);
3795 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003796 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3797 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 }
3799 return slotId;
3800 }
3801
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003802 private int getSlotIndex(int subId) {
3803 int slotId = SubscriptionManager.getSlotIndex(subId);
3804 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3805 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3806 }
3807 return slotId;
3808 }
3809
Wink Saville36469e72014-06-11 15:17:00 -07003810 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003811 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003812 */
3813 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003814 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3815 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003816 final int targetSdk = getTargetSdk(callingPackage);
3817 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003818 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003819 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003820 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003821 mApp, subId, callingPackage, callingFeatureId,
3822 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003823 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3824 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = getPhone(subId);
3829 if (phone != null) {
3830 return phone.getServiceState().getDataNetworkType();
3831 } else {
3832 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3833 }
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003837 }
3838
3839 /**
3840 * Returns the data network type
3841 */
3842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003843 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3844 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3845 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003846 }
3847
3848 /**
3849 * Returns the data network type for a subId
3850 */
3851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003852 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3853 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003855 mApp, subId, callingPackage, callingFeatureId,
3856 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003857 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3858 }
3859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 final Phone phone = getPhone(subId);
3863 if (phone != null) {
3864 return phone.getServiceState().getDataNetworkType();
3865 } else {
3866 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3867 }
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003871 }
3872
3873 /**
Wink Saville36469e72014-06-11 15:17:00 -07003874 * Returns the Voice network type for a subId
3875 */
3876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003877 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3878 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003880 mApp, subId, callingPackage, callingFeatureId,
3881 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003882 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3883 }
3884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 final Phone phone = getPhone(subId);
3888 if (phone != null) {
3889 return phone.getServiceState().getVoiceNetworkType();
3890 } else {
3891 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3892 }
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003896 }
3897
3898 /**
3899 * @return true if a ICC card is present
3900 */
3901 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003902 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003903 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3904 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003905 }
3906
3907 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003908 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003909 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003910 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003911 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 final Phone phone = PhoneFactory.getPhone(slotIndex);
3915 if (phone != null) {
3916 return phone.getIccCard().hasIccCard();
3917 } else {
3918 return false;
3919 }
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003923 }
3924
3925 /**
3926 * Return if the current radio is LTE on CDMA. This
3927 * is a tri-state return value as for a period of time
3928 * the mode may be unknown.
3929 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003930 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003931 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003932 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003933 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003935 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3936 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3937 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003938 }
3939
Sanket Padawe356d7632015-06-22 14:03:32 -07003940 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003941 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3942 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003944 mApp, subId, callingPackage, callingFeatureId,
3945 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003946 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3947 }
3948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
3952 if (phone == null) {
3953 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3954 } else {
3955 return phone.getLteOnCdmaMode();
3956 }
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003959 }
Wink Saville36469e72014-06-11 15:17:00 -07003960 }
3961
Wink Saville36469e72014-06-11 15:17:00 -07003962 /**
3963 * {@hide}
3964 * Returns Default subId, 0 in the case of single standby.
3965 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003966 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003967 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003968 }
3969
Shishir Agrawala9f32182016-04-12 12:00:16 -07003970 private int getSlotForDefaultSubscription() {
3971 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3972 }
3973
Wink Savilleb564aae2014-10-23 10:18:09 -07003974 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003975 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003976 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003977
Pengquan Menge92a50d2018-09-21 15:54:48 -07003978 private boolean isActiveSubscription(int subId) {
3979 return mSubscriptionController.isActiveSubId(subId);
3980 }
3981
Ihab Awadf2177b72013-11-25 13:33:23 -08003982 /**
3983 * @see android.telephony.TelephonyManager.WifiCallingChoices
3984 */
3985 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 final long identity = Binder.clearCallingIdentity();
3987 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003988 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3990 getWhenToMakeWifiCallsDefaultPreference());
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003994 }
3995
3996 /**
3997 * @see android.telephony.TelephonyManager.WifiCallingChoices
3998 */
3999 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004003 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004008 }
4009
Sailesh Nepald1e68152013-12-12 19:08:02 -08004010 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004011 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004012 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004013 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004014
Jordan Liu4c733742019-02-28 12:03:40 -08004015 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4016 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4017 if (phoneId == -1) {
4018 throw new IllegalArgumentException("Given slot index: " + slotIndex
4019 + " does not correspond to an active phone");
4020 }
4021 return PhoneFactory.getPhone(phoneId);
4022 }
4023
Shishir Agrawal566b7612013-10-28 14:41:00 -07004024 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004025 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4026 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4028 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004030 if (DBG) {
4031 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4032 }
4033 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4034 p2);
4035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004036
Jordan Liu4c733742019-02-28 12:03:40 -08004037
4038 @Override
4039 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4040 int slotIndex, String callingPackage, String aid, int p2) {
4041 enforceModifyPermission();
4042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4043 if (DBG) {
4044 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4045 }
4046 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4047 callingPackage, aid, p2);
4048 }
4049
4050 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4051 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 if (TextUtils.equals(ISDR_AID, aid)) {
4055 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004056 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4057 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 if (bestComponent == null
4059 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4060 loge("The calling package is not allowed to access ISD-R.");
4061 throw new SecurityException(
4062 "The calling package is not allowed to access ISD-R.");
4063 }
Derek Tan740e1672017-06-27 14:56:27 -07004064 }
Derek Tan740e1672017-06-27 14:56:27 -07004065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004066 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004067 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4068 null /* workSource */);
4069 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 return response;
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004074 }
4075
4076 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004077 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4079 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004080 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4081 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4082 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004083
Jordan Liu4c733742019-02-28 12:03:40 -08004084 @Override
4085 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4086 enforceModifyPermission();
4087 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4088 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4089 channel);
4090 }
4091
4092 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 if (channel < 0) {
4096 return false;
4097 }
Jordan Liu4c733742019-02-28 12:03:40 -08004098 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4099 null /* workSource */);
4100 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 return success;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004104 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004105 }
4106
4107 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004108 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004109 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4111 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004112 if (DBG) {
4113 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4114 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4115 + p3 + " data=" + data);
4116 }
4117 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4118 command, p1, p2, p3, data);
4119 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004120
Jordan Liu4c733742019-02-28 12:03:40 -08004121 @Override
4122 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4123 int command, int p1, int p2, int p3, String data) {
4124 enforceModifyPermission();
4125 if (DBG) {
4126 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4127 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4128 + p3 + " data=" + data);
4129 }
4130 return iccTransmitApduLogicalChannelWithPermission(
4131 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4132 data);
4133 }
4134
4135 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4136 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 final long identity = Binder.clearCallingIdentity();
4138 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004139 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 return "";
4141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004144 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4145 null /* workSource */);
4146 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 // Append the returned status code to the end of the response payload.
4149 String s = Integer.toHexString(
4150 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4151 if (response.payload != null) {
4152 s = IccUtils.bytesToHexString(response.payload) + s;
4153 }
4154 return s;
4155 } finally {
4156 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004157 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004158 }
Jake Hambye994d462014-02-03 13:10:13 -08004159
Evan Charltonc66da362014-05-16 14:06:40 -07004160 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004161 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4162 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4164 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004166 if (DBG) {
4167 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4168 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4169 }
4170 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4171 cla, command, p1, p2, p3, data);
4172 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004173
Jordan Liu4c733742019-02-28 12:03:40 -08004174 @Override
4175 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4176 int command, int p1, int p2, int p3, String data) {
4177 enforceModifyPermission();
4178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4179 if (DBG) {
4180 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4181 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4182 + " data=" + data);
4183 }
4184
4185 return iccTransmitApduBasicChannelWithPermission(
4186 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4187 p2, p3, data);
4188 }
4189
4190 // open APDU basic channel assuming the caller has sufficient permissions
4191 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4192 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4196 && TextUtils.equals(ISDR_AID, data)) {
4197 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004198 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4199 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 if (bestComponent == null
4201 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4202 loge("The calling package is not allowed to select ISD-R.");
4203 throw new SecurityException(
4204 "The calling package is not allowed to select ISD-R.");
4205 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004206 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004209 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4210 null /* workSource */);
4211 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 // Append the returned status code to the end of the response payload.
4214 String s = Integer.toHexString(
4215 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4216 if (response.payload != null) {
4217 s = IccUtils.bytesToHexString(response.payload) + s;
4218 }
4219 return s;
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004222 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004223 }
4224
4225 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004226 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004227 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4229 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 if (DBG) {
4234 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4235 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4236 }
4237
4238 IccIoResult response =
4239 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4240 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4241 subId);
4242
4243 if (DBG) {
4244 log("Exchange SIM_IO [R]" + response);
4245 }
4246
4247 byte[] result = null;
4248 int length = 2;
4249 if (response.payload != null) {
4250 length = 2 + response.payload.length;
4251 result = new byte[length];
4252 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4253 } else {
4254 result = new byte[length];
4255 }
4256
4257 result[length - 1] = (byte) response.sw2;
4258 result[length - 2] = (byte) response.sw1;
4259 return result;
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004262 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004263 }
4264
Nathan Haroldb3014052017-01-25 15:57:32 -08004265 /**
4266 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4267 * on a particular subscription
4268 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4270 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004273 return null;
4274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 if (appType != TelephonyManager.APPTYPE_USIM
4279 && appType != TelephonyManager.APPTYPE_SIM) {
4280 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4281 return null;
4282 }
4283 Object response = sendRequest(
4284 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4285 if (response instanceof String[]) {
4286 return (String[]) response;
4287 }
yincheng zhao2737e882019-09-06 17:06:54 -07004288 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004290 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004293 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004294 }
4295
yincheng zhao2737e882019-09-06 17:06:54 -07004296 /**
4297 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4298 * subscription.
4299 *
4300 * @param subId the id of the subscription.
4301 * @param appType the uicc app type, must be USIM or SIM.
4302 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4303 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004304 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004305 * @return number of fplmns that is successfully written to the SIM.
4306 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004307 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4308 String callingFeatureId) {
4309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4310 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004311 if (DBG) logv("no permissions for setForbiddenplmns");
4312 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4313 }
4314 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4315 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4316 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4317 }
4318 if (fplmns == null) {
4319 throw new IllegalArgumentException("Fplmn List provided is null");
4320 }
4321 for (String fplmn : fplmns) {
4322 if (!CellIdentity.isValidPlmn(fplmn)) {
4323 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4324 }
4325 }
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 Object response = sendRequest(
4329 CMD_SET_FORBIDDEN_PLMNS,
4330 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4331 subId);
4332 return (int) response;
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
4336 }
4337
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004339 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4341 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4346 if (response.payload == null) {
4347 return "";
4348 }
Evan Charltonc66da362014-05-16 14:06:40 -07004349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 // Append the returned status code to the end of the response payload.
4351 String s = Integer.toHexString(
4352 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4353 s = IccUtils.bytesToHexString(response.payload) + s;
4354 return s;
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Evan Charltonc66da362014-05-16 14:06:40 -07004358 }
4359
Jake Hambye994d462014-02-03 13:10:13 -08004360 /**
4361 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4362 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4363 *
4364 * @param itemID the ID of the item to read
4365 * @return the NV item as a String, or null on error.
4366 */
4367 @Override
4368 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004369 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4371 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004376 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4378 return value;
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Jake Hambye994d462014-02-03 13:10:13 -08004382 }
4383
4384 /**
4385 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4386 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4387 *
4388 * @param itemID the ID of the item to read
4389 * @param itemValue the value to write, as a String
4390 * @return true on success; false on any failure
4391 */
4392 @Override
4393 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004394 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4396 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397
4398 final long identity = Binder.clearCallingIdentity();
4399 try {
4400 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4401 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004402 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4404 return success;
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
4407 }
Jake Hambye994d462014-02-03 13:10:13 -08004408 }
4409
4410 /**
4411 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4412 * Used for device configuration by some CDMA operators.
4413 *
4414 * @param preferredRoamingList byte array containing the new PRL
4415 * @return true on success; false on any failure
4416 */
4417 @Override
4418 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4420 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4425 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4426 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4427 return success;
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
Jake Hambye994d462014-02-03 13:10:13 -08004431 }
4432
4433 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004434 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004435 * Used for device configuration by some CDMA operators.
4436 *
chen xu6dac5ab2018-10-26 17:39:23 -07004437 * @param slotIndex - device slot.
4438 *
Jake Hambye994d462014-02-03 13:10:13 -08004439 * @return true on success; false on any failure
4440 */
4441 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004442 public boolean resetModemConfig(int slotIndex) {
4443 Phone phone = PhoneFactory.getPhone(slotIndex);
4444 if (phone != null) {
4445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4446 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447
chen xu6dac5ab2018-10-26 17:39:23 -07004448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4451 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4452 return success;
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 }
chen xu6dac5ab2018-10-26 17:39:23 -07004457 return false;
4458 }
4459
4460 /**
4461 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4462 *
4463 * @param slotIndex - device slot.
4464 *
4465 * @return true on success; false on any failure
4466 */
4467 @Override
4468 public boolean rebootModem(int slotIndex) {
4469 Phone phone = PhoneFactory.getPhone(slotIndex);
4470 if (phone != null) {
4471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4472 mApp, phone.getSubId(), "rebootModem");
4473
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4477 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4478 return success;
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
4482 }
4483 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004484 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004485
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004486 public String[] getPcscfAddress(String apnType, String callingPackage,
4487 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004488 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4490 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004491 return new String[0];
4492 }
4493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004496 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
Wink Saville36469e72014-06-11 15:17:00 -07004500 }
4501
Brad Ebinger51f743a2017-01-23 13:50:20 -08004502 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004503 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4504 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004505 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004506 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508
4509 final long identity = Binder.clearCallingIdentity();
4510 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004511 ImsResolver resolver = PhoneFactory.getImsResolver();
4512 if (resolver == null) {
4513 // may happen if the device does not support IMS.
4514 return;
4515 }
4516 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004520 }
4521
4522 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004523 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4524 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004525 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004526 public void disableIms(int slotId) {
4527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528
4529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004531 ImsResolver resolver = PhoneFactory.getImsResolver();
4532 if (resolver == null) {
4533 // may happen if the device does not support IMS.
4534 return;
4535 }
4536 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004540 }
4541
4542 /**
4543 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4544 * feature or {@link null} if the service is not available. If the feature is available, the
4545 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4546 */
4547 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004548 IImsServiceFeatureCallback callback) {
4549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004553 ImsResolver resolver = PhoneFactory.getImsResolver();
4554 if (resolver == null) {
4555 // may happen if the device does not support IMS.
4556 return null;
4557 }
4558 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004562 }
4563
4564 /**
4565 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4566 * feature during emergency calling or {@link null} if the service is not available. If the
4567 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4568 * listener for feature updates.
4569 */
4570 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004575 ImsResolver resolver = PhoneFactory.getImsResolver();
4576 if (resolver == null) {
4577 // may happen if the device does not support IMS.
4578 return null;
4579 }
4580 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004584 }
4585
Brad Ebinger5f64b052017-12-14 14:26:15 -08004586 /**
4587 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004588 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004589 */
4590 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592
4593 final long identity = Binder.clearCallingIdentity();
4594 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004595 ImsResolver resolver = PhoneFactory.getImsResolver();
4596 if (resolver == null) {
4597 // may happen if the device does not support IMS.
4598 return null;
4599 }
4600 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004604 }
4605
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004606 /**
4607 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004608 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004609 */
4610 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004615 ImsResolver resolver = PhoneFactory.getImsResolver();
4616 if (resolver == null) {
4617 // may happen if the device does not support IMS.
4618 return null;
4619 }
4620 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004624 }
4625
Brad Ebinger884c07b2018-02-15 16:17:40 -08004626 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004627 * Sets the ImsService Package Name that Telephony will bind to.
4628 *
4629 * @param slotId the slot ID that the ImsService should bind for.
4630 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4631 * ImsService is the device default ImsService.
4632 * @param packageName The package name of the application that contains the ImsService to bind
4633 * to.
4634 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4635 * @hide
4636 */
4637 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004638 int[] subIds = SubscriptionManager.getSubId(slotId);
4639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4640 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4641 "setImsService");
4642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 final long identity = Binder.clearCallingIdentity();
4644 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004645 ImsResolver resolver = PhoneFactory.getImsResolver();
4646 if (resolver == null) {
4647 // may happen if the device does not support IMS.
4648 return false;
4649 }
4650 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4651 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004655 }
4656
4657 /**
4658 * Return the ImsService configuration.
4659 *
4660 * @param slotId The slot that the ImsService is associated with.
4661 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4662 * the device default.
4663 * @return the package name of the ImsService configuration.
4664 */
4665 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004666 int[] subIds = SubscriptionManager.getSubId(slotId);
4667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4668 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4669 "getImsService");
4670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671 final long identity = Binder.clearCallingIdentity();
4672 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004673 ImsResolver resolver = PhoneFactory.getImsResolver();
4674 if (resolver == null) {
4675 // may happen if the device does not support IMS.
4676 return "";
4677 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004678 // TODO: change API to query RCS separately.
4679 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4680 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004684 }
4685
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004686 /**
4687 * Get the MmTelFeature state associated with the requested subscription id.
4688 * @param subId The subscription that the MmTelFeature is associated with.
4689 * @param callback A callback with an integer containing the
4690 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4691 */
4692 @Override
4693 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4694 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4695 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4696 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4697 "IMS not available on device.");
4698 }
4699 final long token = Binder.clearCallingIdentity();
4700 try {
4701 int slotId = getSlotIndex(subId);
4702 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4703 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4704 + subId + "'");
4705 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4706 }
4707 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4708 try {
4709 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4710 } catch (RemoteException e) {
4711 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4712 + "Ignore");
4713 }
4714 });
4715 } finally {
4716 Binder.restoreCallingIdentity(token);
4717 }
4718 }
4719
Wink Saville36469e72014-06-11 15:17:00 -07004720 public void setImsRegistrationState(boolean registered) {
4721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722
4723 final long identity = Binder.clearCallingIdentity();
4724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004725 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 } finally {
4727 Binder.restoreCallingIdentity(identity);
4728 }
Wink Saville36469e72014-06-11 15:17:00 -07004729 }
4730
4731 /**
Stuart Scott54788802015-03-30 13:18:01 -07004732 * Set the network selection mode to automatic.
4733 *
4734 */
4735 @Override
4736 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739
Pengquan Menge92a50d2018-09-21 15:54:48 -07004740 if (!isActiveSubscription(subId)) {
4741 return;
4742 }
4743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4747 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
4750 }
Stuart Scott54788802015-03-30 13:18:01 -07004751 }
4752
Pengquan Mengea84e042018-09-20 14:57:26 -07004753 /**
4754 * Ask the radio to connect to the input network and change selection mode to manual.
4755 *
4756 * @param subId the id of the subscription.
4757 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4758 * the operator to attach to.
4759 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4760 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4761 * normal network selection next time.
4762 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004763 */
4764 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004765 public boolean setNetworkSelectionModeManual(
4766 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4768 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004769
4770 if (!isActiveSubscription(subId)) {
4771 return false;
4772 }
4773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 final long identity = Binder.clearCallingIdentity();
4775 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004776 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004778 if (DBG) {
4779 log("setNetworkSelectionModeManual: subId: " + subId
4780 + " operator: " + operatorInfo);
4781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4783 } finally {
4784 Binder.restoreCallingIdentity(identity);
4785 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004786 }
4787
4788 /**
4789 * Scans for available networks.
4790 */
4791 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004792 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4795 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004796 LocationAccessPolicy.LocationPermissionResult locationResult =
4797 LocationAccessPolicy.checkLocationPermission(mApp,
4798 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4799 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004800 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004801 .setCallingPid(Binder.getCallingPid())
4802 .setCallingUid(Binder.getCallingUid())
4803 .setMethod("getCellNetworkScanResults")
4804 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4805 .build());
4806 switch (locationResult) {
4807 case DENIED_HARD:
4808 throw new SecurityException("Not allowed to access scan results -- location");
4809 case DENIED_SOFT:
4810 return null;
4811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812
Pengquan Menga1bb6272018-09-06 09:59:22 -07004813 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 try {
4815 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004816 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 } finally {
4819 Binder.restoreCallingIdentity(identity);
4820 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004821 }
4822
4823 /**
yinxub1bed742017-04-17 11:45:04 -07004824 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004825 *
yinxub1bed742017-04-17 11:45:04 -07004826 * @param subId id of the subscription
4827 * @param request contains the radio access networks with bands/channels to scan
4828 * @param messenger callback messenger for scan results or errors
4829 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004830 * @return the id of the requested scan which can be used to stop the scan.
4831 */
4832 @Override
4833 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004834 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4836 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004837 LocationAccessPolicy.LocationPermissionResult locationResult =
4838 LocationAccessPolicy.checkLocationPermission(mApp,
4839 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4840 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004841 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004842 .setCallingPid(Binder.getCallingPid())
4843 .setCallingUid(Binder.getCallingUid())
4844 .setMethod("requestNetworkScan")
4845 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4846 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004847 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004848 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004849 if (e != null) {
4850 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4851 throw e;
4852 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004853 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004854 return TelephonyScanManager.INVALID_SCAN_ID;
4855 }
4856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 }
Hall Liu912dfd32019-04-25 14:02:26 -07004858 int callingUid = Binder.getCallingUid();
4859 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004860 final long identity = Binder.clearCallingIdentity();
4861 try {
4862 return mNetworkScanRequestTracker.startNetworkScan(
4863 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004864 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
yinxu504e1392017-04-12 16:03:22 -07004868 }
4869
Hall Liub2ac8ef2019-02-28 15:56:23 -08004870 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004871 NetworkScanRequest request, int subId) {
4872 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4873 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4874 boolean hasNetworkScanPermission =
4875 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4876 == PERMISSION_GRANTED;
4877
4878 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4879 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4880 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004881 }
4882
4883 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4884 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004885 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4886 return new SecurityException("Specific channels must not be"
4887 + " scanned without location access.");
4888 }
4889 }
4890 }
4891
Hall Liub2ac8ef2019-02-28 15:56:23 -08004892 return null;
4893 }
4894
yinxu504e1392017-04-12 16:03:22 -07004895 /**
4896 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004897 *
4898 * @param subId id of the subscription
4899 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004900 */
4901 @Override
4902 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4904 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905
Hall Liu912dfd32019-04-25 14:02:26 -07004906 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004909 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
yinxu504e1392017-04-12 16:03:22 -07004913 }
4914
4915 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004916 * Get the calculated preferred network type.
4917 * Used for debugging incorrect network type.
4918 *
4919 * @return the preferred network type, defined in RILConstants.java.
4920 */
4921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004922 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004923 final Phone defaultPhone = getDefaultPhone();
4924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004925 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004926 return RILConstants.PREFERRED_NETWORK_MODE;
4927 }
4928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 final long identity = Binder.clearCallingIdentity();
4930 try {
4931 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004932 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
Junda Liu84d15a22014-07-02 11:21:04 -07004936 }
4937
4938 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004939 * Get the preferred network type.
4940 * Used for device configuration by some CDMA operators.
4941 *
4942 * @return the preferred network type, defined in RILConstants.java.
4943 */
4944 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004945 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004946 TelephonyPermissions
4947 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4948 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949
4950 final long identity = Binder.clearCallingIdentity();
4951 try {
4952 if (DBG) log("getPreferredNetworkType");
4953 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4954 int networkType = (result != null ? result[0] : -1);
4955 if (DBG) log("getPreferredNetworkType: " + networkType);
4956 return networkType;
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004960 }
4961
4962 /**
4963 * Set the preferred network type.
4964 * Used for device configuration by some CDMA operators.
4965 *
4966 * @param networkType the preferred network type, defined in RILConstants.java.
4967 * @return true on success; false on any failure.
4968 */
4969 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004970 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4972 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973
4974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4977 Boolean success = (Boolean) sendRequest(
4978 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4979 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4980 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004981 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4983 }
4984 return success;
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004987 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004988 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004989
4990 /**
Miaoa84611c2019-03-15 09:21:10 +08004991 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004992 *
Miaoa84611c2019-03-15 09:21:10 +08004993 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004994 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004995 * @hide
4996 */
4997 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004998 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004999 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005001 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 try {
Miaoa84611c2019-03-15 09:21:10 +08005003 if (phone != null) {
5004 return phone.hasMatchedTetherApnSetting();
5005 } else {
5006 return false;
5007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 } finally {
5009 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005010 }
Junda Liu475951f2014-11-07 16:45:03 -08005011 }
5012
5013 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005014 * Set mobile data enabled
5015 * Used by the user through settings etc to turn on/off mobile data
5016 *
5017 * @param enable {@code true} turn turn data on, else {@code false}
5018 */
5019 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005020 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023
5024 final long identity = Binder.clearCallingIdentity();
5025 try {
5026 int phoneId = mSubscriptionController.getPhoneId(subId);
5027 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5028 Phone phone = PhoneFactory.getPhone(phoneId);
5029 if (phone != null) {
5030 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005031 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005033 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 }
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005037 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005038 }
5039
5040 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005041 * Get the user enabled state of Mobile Data.
5042 *
5043 * TODO: remove and use isUserDataEnabled.
5044 * This can't be removed now because some vendor codes
5045 * calls through ITelephony directly while they should
5046 * use TelephonyManager.
5047 *
5048 * @return true on enabled
5049 */
5050 @Override
5051 public boolean getDataEnabled(int subId) {
5052 return isUserDataEnabled(subId);
5053 }
5054
5055 /**
5056 * Get whether mobile data is enabled per user setting.
5057 *
5058 * There are other factors deciding whether mobile data is actually enabled, but they are
5059 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005060 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005061 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005062 *
5063 * @return {@code true} if data is enabled else {@code false}
5064 */
5065 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005066 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005067 try {
5068 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5069 null);
5070 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074
5075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 int phoneId = mSubscriptionController.getPhoneId(subId);
5078 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5079 Phone phone = PhoneFactory.getPhone(phoneId);
5080 if (phone != null) {
5081 boolean retVal = phone.isUserDataEnabled();
5082 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5083 return retVal;
5084 } else {
5085 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5086 return false;
5087 }
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005090 }
5091 }
5092
5093 /**
5094 * Get whether mobile data is enabled.
5095 *
5096 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5097 * whether mobile data is actually enabled.
5098 *
5099 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5100 *
5101 * @return {@code true} if data is enabled else {@code false}
5102 */
5103 @Override
5104 public boolean isDataEnabled(int subId) {
5105 try {
5106 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5107 null);
5108 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5110 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112
5113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 int phoneId = mSubscriptionController.getPhoneId(subId);
5116 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5117 Phone phone = PhoneFactory.getPhone(phoneId);
5118 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005119 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5121 return retVal;
5122 } else {
5123 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5124 return false;
5125 }
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005128 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005129 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005130
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005131 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5132 Phone phone) {
5133 //load access rules from carrier configs, and check those as well: b/139133814
5134 SubscriptionController subController = SubscriptionController.getInstance();
5135 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5136 || subController == null) return privilegeFromSim;
5137
5138 int uid = Binder.getCallingUid();
5139 PackageManager pkgMgr = phone.getContext().getPackageManager();
5140 String[] packages = pkgMgr.getPackagesForUid(uid);
5141
5142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5145 SubscriptionManager subManager = (SubscriptionManager)
5146 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5147 for (String pkg : packages) {
5148 if (subManager.canManageSubscription(subInfo, pkg)) {
5149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5150 }
5151 }
5152 return privilegeFromSim;
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
5156 }
5157
5158 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5159 String pkgName) {
5160 //load access rules from carrier configs, and check those as well: b/139133814
5161 SubscriptionController subController = SubscriptionController.getInstance();
5162 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5163 || subController == null) return privilegeFromSim;
5164
5165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5168 SubscriptionManager subManager = (SubscriptionManager)
5169 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5170 return subManager.canManageSubscription(subInfo, pkgName)
5171 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
5175 }
5176
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005177 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005178 public int getCarrierPrivilegeStatus(int subId) {
5179 final Phone phone = getPhone(subId);
5180 if (phone == null) {
5181 loge("getCarrierPrivilegeStatus: Invalid subId");
5182 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5183 }
5184 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005185 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005186 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005187 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5188 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005189
5190 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5191 card.getCarrierPrivilegeStatusForCurrentTransaction(
5192 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005193 }
Junda Liu29340342014-07-10 15:23:27 -07005194
5195 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005196 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5197 final Phone phone = getPhone(subId);
5198 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005199 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005200 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5201 }
5202 UiccProfile profile =
5203 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5204 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005205 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005206 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5207 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005208 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5209 profile.getCarrierPrivilegeStatusForUid(
5210 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005211 }
5212
5213 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005214 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5215 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005216 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005217 }
5218
5219 int phoneId = SubscriptionManager.getPhoneId(subId);
5220 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005221 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005222 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005223 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5224 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005225 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5226 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5227 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005228 }
5229
5230 @Override
5231 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005232 if (TextUtils.isEmpty(pkgName))
5233 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005234 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5235 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5236 UiccCard card = UiccController.getInstance().getUiccCard(i);
5237 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005238 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005239 continue;
5240 }
5241
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005242 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5243 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5244 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005245 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5246 break;
5247 }
5248 }
5249
5250 return result;
Junda Liu29340342014-07-10 15:23:27 -07005251 }
Derek Tan89e89d42014-07-08 17:00:10 -07005252
5253 @Override
Junda Liue64de782015-04-16 17:19:16 -07005254 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5255 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5256 loge("phoneId " + phoneId + " is not valid.");
5257 return null;
5258 }
5259 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005260 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005261 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005262 return null ;
5263 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005264 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005265 }
5266
Amith Yamasani6e118872016-02-19 12:53:51 -08005267 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005268 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005269 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005270 List<String> privilegedPackages = new ArrayList<>();
5271 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005272 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5273 // has UICC in that slot.
5274 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005275 if (card.hasCarrierPrivilegeRules()) {
5276 if (packages == null) {
5277 // Only check packages in user 0 for now
5278 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005279 PackageManager.MATCH_DISABLED_COMPONENTS
5280 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005281 | PackageManager.GET_SIGNING_CERTIFICATES,
5282 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005283 }
5284 for (int p = packages.size() - 1; p >= 0; p--) {
5285 PackageInfo pkgInfo = packages.get(p);
5286 if (pkgInfo != null && pkgInfo.packageName != null
5287 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005288 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005289 privilegedPackages.add(pkgInfo.packageName);
5290 }
5291 }
5292 }
5293 }
5294 return privilegedPackages;
5295 }
5296
chen xuf7e9fe82019-05-09 19:31:02 -07005297 @Override
5298 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005299 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5300
5301 final long identity = Binder.clearCallingIdentity();
5302
chen xuf7e9fe82019-05-09 19:31:02 -07005303 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005304 try {
5305 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5306 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5307 }
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005310 }
5311 return privilegedPackages;
5312 }
5313
Wink Savilleb564aae2014-10-23 10:18:09 -07005314 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005315 final Phone phone = getPhone(subId);
5316 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005317 if (card == null) {
5318 loge("getIccId: No UICC");
5319 return null;
5320 }
5321 String iccId = card.getIccId();
5322 if (TextUtils.isEmpty(iccId)) {
5323 loge("getIccId: ICC ID is null or empty.");
5324 return null;
5325 }
5326 return iccId;
5327 }
5328
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005329 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005330 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5331 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005332 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5333 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 final long identity = Binder.clearCallingIdentity();
5336 try {
5337 final String iccId = getIccId(subId);
5338 final Phone phone = getPhone(subId);
5339 if (phone == null) {
5340 return false;
5341 }
5342 final String subscriberId = phone.getSubscriberId();
5343
5344 if (DBG_MERGE) {
5345 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5346 + subscriberId + " to " + number);
5347 }
5348
5349 if (TextUtils.isEmpty(iccId)) {
5350 return false;
5351 }
5352
5353 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5354
5355 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5356 if (alphaTag == null) {
5357 editor.remove(alphaTagPrefKey);
5358 } else {
5359 editor.putString(alphaTagPrefKey, alphaTag);
5360 }
5361
5362 // Record both the line number and IMSI for this ICCID, since we need to
5363 // track all merged IMSIs based on line number
5364 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5365 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5366 if (number == null) {
5367 editor.remove(numberPrefKey);
5368 editor.remove(subscriberPrefKey);
5369 } else {
5370 editor.putString(numberPrefKey, number);
5371 editor.putString(subscriberPrefKey, subscriberId);
5372 }
5373
5374 editor.commit();
5375 return true;
5376 } finally {
5377 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005378 }
Derek Tan7226c842014-07-02 17:42:23 -07005379 }
5380
5381 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005382 public String getLine1NumberForDisplay(int subId, String callingPackage,
5383 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005384 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005385 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005386 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005387 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005388 return null;
5389 }
Derek Tan97ebb422014-09-05 16:55:38 -07005390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 String iccId = getIccId(subId);
5394 if (iccId != null) {
5395 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5396 if (DBG_MERGE) {
5397 log("getLine1NumberForDisplay returning "
5398 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5399 }
5400 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5403 return null;
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005406 }
Derek Tan7226c842014-07-02 17:42:23 -07005407 }
5408
5409 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005410 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5411 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005413 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005414 return null;
5415 }
Derek Tan97ebb422014-09-05 16:55:38 -07005416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 String iccId = getIccId(subId);
5420 if (iccId != null) {
5421 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5422 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5423 }
5424 return null;
5425 } finally {
5426 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005427 }
Derek Tan7226c842014-07-02 17:42:23 -07005428 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005429
5430 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005431 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5432 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005433 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5434 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005435 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005436 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005437 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005438 return null;
5439 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005440
Jordan Liub49b04b2019-05-06 14:45:15 -07005441 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5442 // the process, where TelephonyManager was instantiated.
5443 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005444 final long identity = Binder.clearCallingIdentity();
5445 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005446 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 final TelephonyManager tele = TelephonyManager.from(context);
5448 final SubscriptionManager sub = SubscriptionManager.from(context);
5449
5450 // Figure out what subscribers are currently active
5451 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452
Jordan Liub49b04b2019-05-06 14:45:15 -07005453 // Only consider subs which match the current subId
5454 // This logic can be simplified. See b/131189269 for progress.
5455 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005456 activeSubscriberIds.add(tele.getSubscriberId(subId));
5457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458
5459 // First pass, find a number override for an active subscriber
5460 String mergeNumber = null;
5461 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5462 for (String key : prefs.keySet()) {
5463 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5464 final String subscriberId = (String) prefs.get(key);
5465 if (activeSubscriberIds.contains(subscriberId)) {
5466 final String iccId = key.substring(
5467 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5468 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5469 mergeNumber = (String) prefs.get(numberKey);
5470 if (DBG_MERGE) {
5471 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5472 + " for active subscriber " + subscriberId);
5473 }
5474 if (!TextUtils.isEmpty(mergeNumber)) {
5475 break;
5476 }
5477 }
5478 }
5479 }
5480
5481 // Shortcut when no active merged subscribers
5482 if (TextUtils.isEmpty(mergeNumber)) {
5483 return null;
5484 }
5485
5486 // Second pass, find all subscribers under that line override
5487 final ArraySet<String> result = new ArraySet<>();
5488 for (String key : prefs.keySet()) {
5489 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5490 final String number = (String) prefs.get(key);
5491 if (mergeNumber.equals(number)) {
5492 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5493 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5494 final String subscriberId = (String) prefs.get(subscriberKey);
5495 if (!TextUtils.isEmpty(subscriberId)) {
5496 result.add(subscriberId);
5497 }
5498 }
5499 }
5500 }
5501
5502 final String[] resultArray = result.toArray(new String[result.size()]);
5503 Arrays.sort(resultArray);
5504 if (DBG_MERGE) {
5505 Slog.d(LOG_TAG,
5506 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5507 }
5508 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005509 } finally {
5510 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005511 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005512 }
5513
5514 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005515 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5516 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5517
5518 final long identity = Binder.clearCallingIdentity();
5519 try {
5520 final TelephonyManager telephonyManager = mApp.getSystemService(
5521 TelephonyManager.class);
5522 String subscriberId = telephonyManager.getSubscriberId(subId);
5523 if (subscriberId == null) {
5524 if (DBG) {
5525 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5526 + subId);
5527 }
5528 return null;
5529 }
5530
5531 final SubscriptionInfo info = SubscriptionController.getInstance()
5532 .getSubscriptionInfo(subId);
5533 final ParcelUuid groupUuid = info.getGroupUuid();
5534 // If it doesn't belong to any group, return just subscriberId of itself.
5535 if (groupUuid == null) {
5536 return new String[]{subscriberId};
5537 }
5538
5539 // Get all subscriberIds from the group.
5540 final List<String> mergedSubscriberIds = new ArrayList<>();
5541 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005542 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5543 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005544 for (SubscriptionInfo subInfo : groupInfos) {
5545 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5546 if (subscriberId != null) {
5547 mergedSubscriberIds.add(subscriberId);
5548 }
5549 }
5550
5551 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
5554
5555 }
5556 }
5557
5558 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005559 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005560 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5561 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562
5563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 final Phone phone = getPhone(subId);
5566 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005570 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005571
5572 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005573 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005574 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5575 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005576 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577
5578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 final Phone phone = getPhone(subId);
5581 if (phone == null) {
5582 return false;
5583 }
5584 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5585 cdmaNonRoamingList);
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005588 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005589 }
5590
5591 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005592 @Deprecated
5593 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5594 enforceModifyPermission();
5595
5596 int returnValue = 0;
5597 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005598 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005599 if(result.exception == null) {
5600 if (result.result != null) {
5601 byte[] responseData = (byte[])(result.result);
5602 if(responseData.length > oemResp.length) {
5603 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5604 responseData.length + "bytes. Buffer Size is " +
5605 oemResp.length + "bytes.");
5606 }
5607 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5608 returnValue = responseData.length;
5609 }
5610 } else {
5611 CommandException ex = (CommandException) result.exception;
5612 returnValue = ex.getCommandError().ordinal();
5613 if(returnValue > 0) returnValue *= -1;
5614 }
5615 } catch (RuntimeException e) {
5616 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5617 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5618 if(returnValue > 0) returnValue *= -1;
5619 }
5620
5621 return returnValue;
5622 }
5623
5624 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005625 public void setRadioCapability(RadioAccessFamily[] rafs) {
5626 try {
5627 ProxyController.getInstance().setRadioCapability(rafs);
5628 } catch (RuntimeException e) {
5629 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5630 }
5631 }
5632
5633 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005634 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005635 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005636 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005637 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005638 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 final long identity = Binder.clearCallingIdentity();
5641 try {
chen xub97461a2018-10-26 14:17:57 -07005642 TelephonyPermissions
5643 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5644 mApp, phone.getSubId(), "getRadioAccessFamily");
5645 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
chen xub97461a2018-10-26 14:17:57 -07005649 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005650 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005651
5652 @Override
5653 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005654 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005659 ImsManager.getInstance(defaultPhone.getContext(),
5660 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005664 }
5665
5666 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005667 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005668 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5670 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005671 return false;
5672 }
Svet Ganovb320e182015-04-16 12:30:10 -07005673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 // Check the user preference and the system-level IMS setting. Even if the user has
5677 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5678 // In the long run, we may instead need to check if there exists a connection service
5679 // which can support video calling.
5680 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005681 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 return imsManager.isVtEnabledByPlatform()
5683 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5684 && imsManager.isVtEnabledByUser();
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005688 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005689
Andrew Leea1239f22015-03-02 17:44:07 -08005690 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005691 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5692 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005694 mApp, subId, callingPackage, callingFeatureId,
5695 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 return false;
5697 }
5698
5699 final long identity = Binder.clearCallingIdentity();
5700 try {
5701 CarrierConfigManager configManager =
5702 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Andrew Leea1239f22015-03-02 17:44:07 -08005708 }
5709
5710 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005711 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005713 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 return false;
5715 }
5716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 CarrierConfigManager configManager =
5720 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005721 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Andrew Leea1239f22015-03-02 17:44:07 -08005726 }
5727
Andrew Lee9431b832015-03-09 18:46:45 -07005728 @Override
5729 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005730 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005731 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005732 }
5733
5734 @Override
5735 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 final long identity = Binder.clearCallingIdentity();
5737 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005738 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
Andrew Lee9431b832015-03-09 18:46:45 -07005742 }
5743
Hall Liuf6668912018-10-31 17:05:23 -07005744 /**
5745 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5746 * support for the feature and device firmware support.
5747 *
5748 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5749 */
5750 @Override
5751 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005753 final Phone phone = getPhone(subscriptionId);
5754 if (phone == null) {
5755 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5756 return false;
5757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005759 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5761 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005762 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 return isCarrierSupported && isDeviceSupported;
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
5766 }
Hall Liu98187582018-01-22 19:15:32 -08005767 }
5768
Hall Liuf6668912018-10-31 17:05:23 -07005769 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005770 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5771 * RTT setting, will return true if the device and carrier both support RTT.
5772 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005773 */
5774 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 final long identity = Binder.clearCallingIdentity();
5776 try {
Hall Liu30de3502019-10-29 16:50:20 -07005777 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005781 }
5782
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005783 @Deprecated
5784 @Override
5785 public String getDeviceId(String callingPackage) {
5786 return getDeviceIdWithFeature(callingPackage, null);
5787 }
5788
Sanket Padawe7310cc72015-01-14 09:53:20 -08005789 /**
5790 * Returns the unique device ID of phone, for example, the IMEI for
5791 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5792 *
5793 * <p>Requires Permission:
5794 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5795 */
5796 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005797 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005798 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005799 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005800 return null;
5801 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005802 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005803 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005804 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005805 return null;
5806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 return phone.getDeviceId();
5811 } finally {
5812 Binder.restoreCallingIdentity(identity);
5813 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005814 }
5815
Ping Sunc67b7c22016-03-02 19:16:45 +08005816 /**
5817 * {@hide}
5818 * Returns the IMS Registration Status on a particular subid
5819 *
5820 * @param subId
5821 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005822 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005823 Phone phone = getPhone(subId);
5824 if (phone != null) {
5825 return phone.isImsRegistered();
5826 } else {
5827 return false;
5828 }
5829 }
5830
Santos Cordon7a1885b2015-02-03 11:15:19 -08005831 @Override
5832 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005839 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005840
Tyler Gunnf70ed162019-04-03 15:28:53 -07005841 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005842 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005843 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005845 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005846 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5847 }
5848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
5854 }
5855
5856 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005857 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 Phone phone = getPhone(subscriptionId);
5861 if (phone == null) {
5862 return null;
5863 }
5864 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
5869
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005870 /**
5871 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005872 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005873 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
5876 Phone phone = getPhone(subId);
5877 if (phone != null) {
5878 return phone.isWifiCallingEnabled();
5879 } else {
5880 return false;
5881 }
5882 } finally {
5883 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005884 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005885 }
5886
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005887 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005888 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005889 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005890 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 final long identity = Binder.clearCallingIdentity();
5892 try {
5893 Phone phone = getPhone(subId);
5894 if (phone != null) {
5895 return phone.isVideoEnabled();
5896 } else {
5897 return false;
5898 }
5899 } finally {
5900 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005901 }
5902 }
5903
5904 /**
5905 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5906 * defined in {@link ImsRegistrationImplBase}.
5907 */
5908 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 final long identity = Binder.clearCallingIdentity();
5910 try {
5911 Phone phone = getPhone(subId);
5912 if (phone != null) {
5913 return phone.getImsRegistrationTech();
5914 } else {
5915 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5916 }
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005919 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005920 }
5921
Stuart Scott8eef64f2015-04-08 15:13:54 -07005922 @Override
5923 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005924 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005925 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5926 return;
5927 }
5928
Svet Ganovcc087f82015-05-12 20:35:54 -07005929 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005930
Svet Ganovcc087f82015-05-12 20:35:54 -07005931 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005932 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5933 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005934 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005935 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005936 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005937 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5938 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005939 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005940 // There has been issues when Sms raw table somehow stores orphan
5941 // fragments. They lead to garbled message when new fragments come
5942 // in and combined with those stale ones. In case this happens again,
5943 // user can reset all network settings which will clean up this table.
5944 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005945 // Clean up IMS settings as well here.
5946 int slotId = getSlotIndex(subId);
5947 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5948 ImsManager.getInstance(mApp, slotId).factoryReset();
5949 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005950
5951 // Erase modem config if erase modem on network setting is enabled.
5952 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5953 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5954 if (configValue != null && Boolean.parseBoolean(configValue)) {
5955 sendEraseModemConfig(getDefaultPhone());
5956 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005957 } finally {
5958 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005959 }
5960 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005961
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005962 private void cleanUpSmsRawTable(Context context) {
5963 ContentResolver resolver = context.getContentResolver();
5964 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5965 resolver.delete(uri, null, null);
5966 }
5967
Narayan Kamath1c496c22015-04-16 14:40:19 +01005968 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005969 public String getSimLocaleForSubscriber(int subId) {
5970 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5971 final Phone phone = getPhone(subId);
5972 if (phone == null) {
5973 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005974 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 final long identity = Binder.clearCallingIdentity();
5977 try {
chen xu5d3637b2019-01-21 23:31:38 -08005978 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005979 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005980 if (info == null) {
5981 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5982 return null;
5983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 // Try and fetch the locale from the carrier properties or from the SIM language
5985 // preferences (EF-PL and EF-LI)...
5986 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005988 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5989 if (localeFromDefaultSim != null) {
5990 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5991 if (DBG) log("Using locale from subId: " + subId + " locale: "
5992 + localeFromDefaultSim);
5993 return localeFromDefaultSim.toLanguageTag();
5994 } else {
5995 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 }
5997 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 // The SIM language preferences only store a language (e.g. fr = French), not an
6000 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6001 // the SIM and carrier preferences does not include a country we add the country
6002 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006003 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006005 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 return mccLocale.toLanguageTag();
6007 }
6008
6009 if (DBG) log("No locale found - returning null");
6010 return null;
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006014 }
6015
6016 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006017 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6018 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006019 }
6020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 /**
6022 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6023 */
6024 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006025 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6026 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006027 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006028
Chenjie Yu1ba97252018-01-11 18:16:20 -08006029 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006030 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006031
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006032 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006033 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6034 * representing the state of the modem.
6035 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006036 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6037 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006038 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006039 */
6040 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006041 public void requestModemActivityInfo(ResultReceiver result) {
6042 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006043 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
6047 ModemActivityInfo ret = null;
6048 synchronized (mLastModemActivityInfo) {
6049 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6050 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006051 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006052 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006054 int[] txTimeMs = info.getTransmitTimeMillis();
6055 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006057 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 }
6059 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006060 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6061 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 mLastModemActivityInfo.setIdleTimeMillis(
6063 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006064 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6065 mLastModemActivityInfo.setReceiveTimeMillis(
6066 info.getReceiveTimeMillis() + mLastModemActivityInfo
6067 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006068 }
Chen Xud78231e2019-09-10 18:49:52 -07006069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6071 mLastModemActivityInfo.getSleepTimeMillis(),
6072 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006073 mLastModemActivityInfo.getTransmitTimeMillis(),
6074 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 Bundle bundle = new Bundle();
6077 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6078 result.send(0, bundle);
6079 } finally {
6080 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006081 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006082 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006083
Siddharth Rayb8114062018-06-17 15:02:38 -07006084 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6085 // less than total activity duration.
6086 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6087 if (info == null) {
6088 return false;
6089 }
6090 int activityDurationMs =
6091 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6092 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006093 int[] txTimeMs = info.getTransmitTimeMillis();
6094 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6095 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006096 }
6097 return (info.isValid()
6098 && (info.getSleepTimeMillis() <= activityDurationMs)
6099 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006100 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006101 && (totalTxTimeMs <= activityDurationMs));
6102 }
6103
Jack Yu85bd38a2015-11-09 11:34:32 -08006104 /**
6105 * {@hide}
6106 * Returns the service state information on specified subscription.
6107 */
6108 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006109 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6110 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006112 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006113 return null;
6114 }
6115
Hall Liuf19c44f2018-11-27 14:38:17 -08006116 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6117 LocationAccessPolicy.checkLocationPermission(mApp,
6118 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6119 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006120 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006121 .setCallingPid(Binder.getCallingPid())
6122 .setCallingUid(Binder.getCallingUid())
6123 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006124 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006125 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6126 .build());
6127
6128 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6129 LocationAccessPolicy.checkLocationPermission(mApp,
6130 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6131 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006132 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006133 .setCallingPid(Binder.getCallingPid())
6134 .setCallingUid(Binder.getCallingUid())
6135 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006136 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006137 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6138 .build());
6139 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6140 boolean hasFinePermission =
6141 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6142 boolean hasCoarsePermission =
6143 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145 final long identity = Binder.clearCallingIdentity();
6146 try {
6147 final Phone phone = getPhone(subId);
6148 if (phone == null) {
6149 return null;
6150 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006151
Hall Liuf19c44f2018-11-27 14:38:17 -08006152 ServiceState ss = phone.getServiceState();
6153
6154 // Scrub out the location info in ServiceState depending on what level of access
6155 // the caller has.
6156 if (hasFinePermission) return ss;
6157 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6158 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006162 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006163
6164 /**
6165 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6166 *
6167 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6168 * voicemail ringtone.
6169 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6170 * PhoneAccount.
6171 */
6172 @Override
6173 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6177 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006178 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6182 } finally {
6183 Binder.restoreCallingIdentity(identity);
6184 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006185 }
6186
6187 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006188 * Sets the per-account voicemail ringtone.
6189 *
6190 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6191 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6192 *
6193 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6194 * voicemail ringtone.
6195 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6196 * PhoneAccount.
6197 */
6198 @Override
6199 public void setVoicemailRingtoneUri(String callingPackage,
6200 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006201 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006202 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006203 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6204 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6206 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6207 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209
6210 final long identity = Binder.clearCallingIdentity();
6211 try {
6212 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6213 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006214 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 }
6216 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006219 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006220 }
6221
6222 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006223 * Returns whether vibration is set for voicemail notification in Phone settings.
6224 *
6225 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6226 * voicemail vibration setting.
6227 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6228 */
6229 @Override
6230 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 final long identity = Binder.clearCallingIdentity();
6232 try {
6233 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6234 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006235 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006242 }
6243
Youhan Wange64578a2016-05-02 15:32:42 -07006244 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006245 * Sets the per-account voicemail vibration.
6246 *
6247 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6248 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6249 *
6250 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6251 * voicemail vibration setting.
6252 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6253 * specific PhoneAccount.
6254 */
6255 @Override
6256 public void setVoicemailVibrationEnabled(String callingPackage,
6257 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006258 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006260 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6261 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6263 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6264 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006265 }
6266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6270 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006271 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 }
6273 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6274 } finally {
6275 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006276 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006277 }
6278
6279 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006280 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6281 *
6282 * @throws SecurityException if the caller does not have the required permission
6283 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006284 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006285 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006286 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006287 }
6288
6289 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006290 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6291 * permission.
6292 *
6293 * @throws SecurityException if the caller does not have the required permission
6294 */
6295 private void enforceSendSmsPermission() {
6296 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6297 }
6298
6299 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006300 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006301 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006302 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006303 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006304 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 final long identity = Binder.clearCallingIdentity();
6306 try {
6307 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006308 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 if (componentName == null) {
6310 throw new SecurityException(
6311 "Caller not current active visual voicemail package[null]");
6312 }
6313 String vvmPackage = componentName.getPackageName();
6314 if (!callingPackage.equals(vvmPackage)) {
6315 throw new SecurityException("Caller not current active visual voicemail package["
6316 + vvmPackage + "]");
6317 }
6318 } finally {
6319 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006320 }
6321 }
6322
6323 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006324 * Return the application ID for the app type.
6325 *
6326 * @param subId the subscription ID that this request applies to.
6327 * @param appType the uicc app type.
6328 * @return Application ID for specificied app type, or null if no uicc.
6329 */
6330 @Override
6331 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006332 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006333 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334
6335 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006336 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 if (phone == null) {
6338 return null;
6339 }
6340 String aid = null;
6341 try {
6342 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6343 .getApplicationByType(appType).getAid();
6344 } catch (Exception e) {
6345 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6346 }
6347 return aid;
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006350 }
Youhan Wange64578a2016-05-02 15:32:42 -07006351 }
6352
Youhan Wang4001d252016-05-11 10:29:41 -07006353 /**
6354 * Return the Electronic Serial Number.
6355 *
6356 * @param subId the subscription ID that this request applies to.
6357 * @return ESN or null if error.
6358 */
6359 @Override
6360 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006361 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006362 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006365 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366 if (phone == null) {
6367 return null;
6368 }
6369 String esn = null;
6370 try {
6371 esn = phone.getEsn();
6372 } catch (Exception e) {
6373 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6374 }
6375 return esn;
6376 } finally {
6377 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006378 }
Youhan Wang4001d252016-05-11 10:29:41 -07006379 }
6380
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006381 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006382 * Return the Preferred Roaming List Version.
6383 *
6384 * @param subId the subscription ID that this request applies to.
6385 * @return PRLVersion or null if error.
6386 */
6387 @Override
6388 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006389 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006390 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391
6392 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006393 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 if (phone == null) {
6395 return null;
6396 }
6397 String cdmaPrlVersion = null;
6398 try {
6399 cdmaPrlVersion = phone.getCdmaPrlVersion();
6400 } catch (Exception e) {
6401 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6402 }
6403 return cdmaPrlVersion;
6404 } finally {
6405 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006406 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006407 }
6408
6409 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006410 * Get snapshot of Telephony histograms
6411 * @return List of Telephony histograms
6412 * @hide
6413 */
6414 @Override
6415 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6417 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418
6419 final long identity = Binder.clearCallingIdentity();
6420 try {
6421 return RIL.getTelephonyRILTimingHistograms();
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
6424 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006425 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006426
6427 /**
6428 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006429 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6430 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006431 * Require system privileges. In the future we may add this to carrier APIs.
6432 *
Michele Berionne482f8202018-11-27 18:57:59 -08006433 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006434 */
6435 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006436 @TelephonyManager.SetCarrierRestrictionResult
6437 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006438 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006439 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006440
Michele Berionne482f8202018-11-27 18:57:59 -08006441 if (carrierRestrictionRules == null) {
6442 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006443 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445 final long identity = Binder.clearCallingIdentity();
6446 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006447 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006448 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006452 }
6453
6454 /**
6455 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006456 * Get the allowed carrier list and the excluded carrier list, including the priority between
6457 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006458 * Require system privileges. In the future we may add this to carrier APIs.
6459 *
Michele Berionne482f8202018-11-27 18:57:59 -08006460 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006461 */
6462 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006463 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006464 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006466
6467 final long identity = Binder.clearCallingIdentity();
6468 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006469 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6470 if (response instanceof CarrierRestrictionRules) {
6471 return (CarrierRestrictionRules) response;
6472 }
6473 // Response is an Exception of some kind,
6474 // which is signalled to the user as a NULL retval
6475 return null;
6476 } catch (Exception e) {
6477 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6478 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479 } finally {
6480 Binder.restoreCallingIdentity(identity);
6481 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006482 }
6483
fionaxu59545b42016-05-25 15:53:37 -07006484 /**
6485 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6486 * @param subId the subscription ID that this action applies to.
6487 * @param enabled control enable or disable metered apns.
6488 * {@hide}
6489 */
6490 @Override
6491 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6492 enforceModifyPermission();
6493 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494
6495 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006496 if (phone == null) {
6497 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6498 return;
6499 }
6500 try {
6501 phone.carrierActionSetMeteredApnsEnabled(enabled);
6502 } catch (Exception e) {
6503 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006504 } finally {
6505 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006506 }
6507 }
6508
6509 /**
6510 * Action set from carrier signalling broadcast receivers to enable/disable radio
6511 * @param subId the subscription ID that this action applies to.
6512 * @param enabled control enable or disable radio.
6513 * {@hide}
6514 */
6515 @Override
6516 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6517 enforceModifyPermission();
6518 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519
6520 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006521 if (phone == null) {
6522 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6523 return;
6524 }
6525 try {
6526 phone.carrierActionSetRadioEnabled(enabled);
6527 } catch (Exception e) {
6528 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006531 }
6532 }
6533
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006534 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006535 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6536 * network status based on which carrier apps could apply actions accordingly,
6537 * enable/disable default url handler for example.
6538 *
6539 * @param subId the subscription ID that this action applies to.
6540 * @param report control start/stop reporting the default network status.
6541 * {@hide}
6542 */
6543 @Override
6544 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6545 enforceModifyPermission();
6546 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547
6548 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006549 if (phone == null) {
6550 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6551 return;
6552 }
6553 try {
6554 phone.carrierActionReportDefaultNetworkStatus(report);
6555 } catch (Exception e) {
6556 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006559 }
6560 }
6561
6562 /**
fionaxud9622282017-07-17 17:51:30 -07006563 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6564 * @param subId the subscription ID that this action applies to.
6565 * {@hide}
6566 */
6567 @Override
6568 public void carrierActionResetAll(int subId) {
6569 enforceModifyPermission();
6570 final Phone phone = getPhone(subId);
6571 if (phone == null) {
6572 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6573 return;
6574 }
6575 try {
6576 phone.carrierActionResetAll();
6577 } catch (Exception e) {
6578 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6579 }
6580 }
6581
6582 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006583 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6584 * bug report is being generated.
6585 */
6586 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006587 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006588 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6589 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006590 writer.println("Permission Denial: can't dump Phone from pid="
6591 + Binder.getCallingPid()
6592 + ", uid=" + Binder.getCallingUid()
6593 + "without permission "
6594 + android.Manifest.permission.DUMP);
6595 return;
6596 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006597 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006598 }
Jack Yueb89b242016-06-22 13:27:47 -07006599
Brad Ebingerdac2f002018-04-03 15:17:52 -07006600 @Override
6601 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6602 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6603 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006604 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6605 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006606 }
6607
Jack Yueb89b242016-06-22 13:27:47 -07006608 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006609 * Get aggregated video call data usage since boot.
6610 *
6611 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6612 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006613 * {@hide}
6614 */
6615 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006616 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006617 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6618 null);
6619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006620 final long identity = Binder.clearCallingIdentity();
6621 try {
6622 // NetworkStatsService keeps tracking the active network interface and identity. It
6623 // records the delta with the corresponding network identity.
6624 // We just return the total video call data usage snapshot since boot.
6625 Phone phone = getPhone(subId);
6626 if (phone != null) {
6627 return phone.getVtDataUsage(perUidStats);
6628 }
6629 return null;
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006632 }
Jack Yueb89b242016-06-22 13:27:47 -07006633 }
Jack Yu75ab2952016-07-08 14:29:33 -07006634
6635 /**
6636 * Policy control of data connection. Usually used when data limit is passed.
6637 * @param enabled True if enabling the data, otherwise disabling.
6638 * @param subId Subscription index
6639 * {@hide}
6640 */
6641 @Override
6642 public void setPolicyDataEnabled(boolean enabled, int subId) {
6643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644
6645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 Phone phone = getPhone(subId);
6648 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006649 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 }
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006653 }
6654 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006655
6656 /**
6657 * Get Client request stats
6658 * @return List of Client Request Stats
6659 * @hide
6660 */
6661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006662 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6663 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006665 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006666 return null;
6667 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006668 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 if (phone != null) {
6673 return phone.getClientRequestStats();
6674 }
6675
6676 return null;
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006680 }
6681
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006682 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006683 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006684 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006685 }
Jack Yueb4124c2017-02-16 15:32:43 -08006686
6687 /**
Grace Chen70990072017-03-24 17:21:30 -07006688 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006689 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006690 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006691 * @param state State of SIM (power down, power up, pass through)
6692 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6693 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6694 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006695 *
6696 **/
6697 @Override
Grace Chen70990072017-03-24 17:21:30 -07006698 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006699 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006700 Phone phone = PhoneFactory.getPhone(slotIndex);
6701
vagdeviaf9a5b92018-08-15 16:01:53 -07006702 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 final long identity = Binder.clearCallingIdentity();
6705 try {
6706 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006707 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 }
6709 } finally {
6710 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006711 }
6712 }
Shuo Qiandd210312017-04-12 22:11:33 +00006713
Tyler Gunn65d45c22017-06-05 11:22:26 -07006714 private boolean isUssdApiAllowed(int subId) {
6715 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006716 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006717 if (configManager == null) {
6718 return false;
6719 }
6720 PersistableBundle pb = configManager.getConfigForSubId(subId);
6721 if (pb == null) {
6722 return false;
6723 }
6724 return pb.getBoolean(
6725 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6726 }
6727
Shuo Qiandd210312017-04-12 22:11:33 +00006728 /**
6729 * Check if phone is in emergency callback mode
6730 * @return true if phone is in emergency callback mode
6731 * @param subId sub id
6732 */
goneil9c5f4872017-12-05 14:07:56 -08006733 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006734 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006735 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737
6738 final long identity = Binder.clearCallingIdentity();
6739 try {
6740 if (phone != null) {
6741 return phone.isInEcm();
6742 } else {
6743 return false;
6744 }
6745 } finally {
6746 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006747 }
6748 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006749
6750 /**
6751 * Get the current signal strength information for the given subscription.
6752 * Because this information is not updated when the device is in a low power state
6753 * it should not be relied-upon to be current.
6754 * @param subId Subscription index
6755 * @return the most recent cached signal strength info from the modem
6756 */
6757 @Override
6758 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 Phone p = getPhone(subId);
6762 if (p == null) {
6763 return null;
6764 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 return p.getSignalStrength();
6767 } finally {
6768 Binder.restoreCallingIdentity(identity);
6769 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006770 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006771
Pengquan Meng77b7f132018-08-22 14:49:57 -07006772 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006773 * Get the current modem radio state for the given slot.
6774 * @param slotIndex slot index.
6775 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006776 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006777 * @return the current radio power state from the modem
6778 */
6779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006780 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006781 Phone phone = PhoneFactory.getPhone(slotIndex);
6782 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6784 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006785 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6786 }
6787
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
6790 return phone.getRadioPowerState();
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
6794 }
6795 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6796 }
6797
6798 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006799 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6800 *
6801 * <p>Requires one of the following permissions:
6802 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6803 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6804 * privileges.
6805 *
6806 * @param subId subscription id
6807 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6808 * {@code false}.
6809 */
6810 @Override
6811 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006812 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6813 null /* message */);
6814
Pengquan Menga1bb6272018-09-06 09:59:22 -07006815 boolean isEnabled = false;
6816 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006817 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006818 Phone phone = getPhone(subId);
6819 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006820 } catch (Exception e) {
6821 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6822 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006823 } finally {
6824 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006825 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006826 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006827 }
6828
6829
6830 /**
6831 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6832 *
6833 * <p> Requires permission:
6834 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6835 * privileges.
6836 *
6837 * @param subId subscription id
6838 * @param isEnabled {@code true} means enable, {@code false} means disable.
6839 */
6840 @Override
6841 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6843 mApp, subId, "setDataRoamingEnabled");
6844
Pengquan Menga1bb6272018-09-06 09:59:22 -07006845 final long identity = Binder.clearCallingIdentity();
6846 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006847 Phone phone = getPhone(subId);
6848 if (phone != null) {
6849 phone.setDataRoamingEnabled(isEnabled);
6850 }
6851 } finally {
6852 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006853 }
6854 }
6855
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006856 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006857 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006858 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6859 mApp, subId, "isManualNetworkSelectionAllowed");
6860
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006861 boolean isAllowed = true;
6862 final long identity = Binder.clearCallingIdentity();
6863 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006864 Phone phone = getPhone(subId);
6865 if (phone != null) {
6866 isAllowed = phone.isCspPlmnEnabled();
6867 }
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
6870 }
6871 return isAllowed;
6872 }
6873
6874 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006875 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006876 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006877 try {
6878 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006879 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006880 } catch (SecurityException e) {
6881 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6882 // has carrier privileges on an active UICC
6883 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6884 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006885 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006886 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006887 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006888
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006891 UiccController uiccController = UiccController.getInstance();
6892 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006893 if (hasReadPermission) {
6894 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006895 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006896
6897 // Remove private info if the caller doesn't have access
6898 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6899 for (UiccCardInfo cardInfo : cardInfos) {
6900 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6901 // is available
6902 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6903 if (card == null || card.getUiccProfile() == null) {
6904 // assume no access if the card or profile is unavailable
6905 filteredInfos.add(cardInfo.getUnprivileged());
6906 continue;
6907 }
6908 UiccProfile profile = card.getUiccProfile();
6909 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6910 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6911 filteredInfos.add(cardInfo);
6912 } else {
6913 filteredInfos.add(cardInfo.getUnprivileged());
6914 }
6915 }
6916 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919 }
6920 }
6921
6922 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006923 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006924 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6929 if (slots == null) {
6930 Rlog.i(LOG_TAG, "slots is null.");
6931 return null;
6932 }
6933
6934 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6935 for (int i = 0; i < slots.length; i++) {
6936 UiccSlot slot = slots[i];
6937 if (slot == null) {
6938 continue;
6939 }
6940
Jordan Liu7be7e652019-05-06 18:55:02 +00006941 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 UiccCard card = slot.getUiccCard();
6943 if (card != null) {
6944 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006945 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006946 cardId = slot.getEid();
6947 if (TextUtils.isEmpty(cardId)) {
6948 cardId = slot.getIccId();
6949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 }
6951
Jordan Liu857451f2019-05-09 16:35:35 -07006952 if (cardId != null) {
6953 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6954 // if cardId is an EID, it's all digits so this is fine
6955 cardId = IccUtils.stripTrailingFs(cardId);
6956 }
6957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 int cardState = 0;
6959 switch (slot.getCardState()) {
6960 case CARDSTATE_ABSENT:
6961 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6962 break;
6963 case CARDSTATE_PRESENT:
6964 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6965 break;
6966 case CARDSTATE_ERROR:
6967 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6968 break;
6969 case CARDSTATE_RESTRICTED:
6970 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6971 break;
6972 default:
6973 break;
6974
6975 }
6976
6977 infos[i] = new UiccSlotInfo(
6978 slot.isActive(),
6979 slot.isEuicc(),
6980 cardId,
6981 cardState,
6982 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006983 slot.isExtendedApduSupported(),
6984 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 }
6986 return infos;
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006989 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006990 }
6991
6992 @Override
6993 public boolean switchSlots(int[] physicalSlots) {
6994 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995
6996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007002 }
Jack Yu4c988042018-02-27 15:30:01 -08007003
7004 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007005 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007006 final long identity = Binder.clearCallingIdentity();
7007 try {
7008 return UiccController.getInstance().getCardIdForDefaultEuicc();
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
7011 }
7012 }
7013
7014 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007015 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7016 enforceModifyPermission();
7017 final Phone phone = getPhone(subId);
7018 if (phone == null) {
7019 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7020 return;
7021 }
7022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 phone.setRadioIndicationUpdateMode(filters, mode);
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
7028 }
Jack Yu4c988042018-02-27 15:30:01 -08007029 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007030
7031 /**
goneil47ffb6e2018-04-06 15:40:58 -07007032 * A test API to reload the UICC profile.
7033 *
7034 * <p>Requires that the calling app has permission
7035 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7036 * @hide
7037 */
7038 @Override
7039 public void refreshUiccProfile(int subId) {
7040 enforceModifyPermission();
7041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 Phone phone = getPhone(subId);
7045 if (phone == null) {
7046 return;
7047 }
7048 UiccCard uiccCard = phone.getUiccCard();
7049 if (uiccCard == null) {
7050 return;
7051 }
7052 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7053 if (uiccProfile == null) {
7054 return;
7055 }
7056 uiccProfile.refresh();
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
7059 }
7060 }
7061
7062 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007063 * Returns false if the mobile data is disabled by default, otherwise return true.
7064 */
7065 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007066 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007067 }
7068
7069 /**
7070 * Returns true if the data roaming is enabled by default, i.e the system property
7071 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7072 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7073 */
7074 private boolean getDefaultDataRoamingEnabled(int subId) {
7075 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007076 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007077 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007078 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7079 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7080 return isDataRoamingEnabled;
7081 }
7082
7083 /**
7084 * Returns the default network type for the given {@code subId}, if the default network type is
7085 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7086 */
7087 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007088 List<Integer> list = TelephonyProperties.default_network();
7089 int phoneId = mSubscriptionController.getPhoneId(subId);
7090 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7091 return list.get(phoneId);
7092 }
7093 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007094 }
fionaxua13278b2018-03-21 00:08:13 -07007095
7096 @Override
7097 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007098 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100
7101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 final Phone phone = getPhone(subId);
7104 if (phone == null) {
7105 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7106 return;
7107 }
chen xueaba88a2019-03-15 13:15:10 -07007108 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7109 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 } finally {
7111 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007112 }
fionaxua13278b2018-03-21 00:08:13 -07007113 }
7114
7115 @Override
7116 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007117 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 final Phone phone = getPhone(subId);
7122 if (phone == null) {
7123 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7124 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7125 }
7126 return phone.getCarrierIdListVersion();
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007129 }
fionaxua13278b2018-03-21 00:08:13 -07007130 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007131
7132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007133 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7134 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007136 mApp, subId, callingPackage, callingFeatureId,
7137 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007138 return -1;
7139 }
7140
7141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
7147 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007148
7149 @Override
7150 public int getCdmaRoamingMode(int subId) {
7151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7152 mApp, subId, "getCdmaRoamingMode");
7153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
7160 }
7161
7162 @Override
7163 public boolean setCdmaRoamingMode(int subId, int mode) {
7164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7165 mApp, subId, "setCdmaRoamingMode");
7166
7167 final long identity = Binder.clearCallingIdentity();
7168 try {
7169 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
7173 }
7174
7175 @Override
7176 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7178 mApp, subId, "setCdmaSubscriptionMode");
7179
7180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
7186 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007187
sqianc5eccab2018-10-19 18:46:41 -07007188 @Override
sqian8c685422019-02-22 15:55:18 -08007189 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007190 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007192 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7193 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007194 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7195 }
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
sqian854d44b2018-12-12 16:48:18 -08007198 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7199 for (Phone phone: PhoneFactory.getPhones()) {
7200 if (phone.getEmergencyNumberTracker() != null
7201 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7202 emergencyNumberListInternal.put(
7203 phone.getSubId(),
7204 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7205 }
sqian11b7a0e2018-12-05 18:48:28 -08007206 }
sqian854d44b2018-12-12 16:48:18 -08007207 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
sqianc5eccab2018-10-19 18:46:41 -07007211 }
7212
7213 @Override
sqian8c685422019-02-22 15:55:18 -08007214 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007215 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007216 if (!exactMatch) {
7217 TelephonyPermissions
7218 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007219 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007220 }
7221 final long identity = Binder.clearCallingIdentity();
7222 try {
sqian854d44b2018-12-12 16:48:18 -08007223 for (Phone phone: PhoneFactory.getPhones()) {
7224 if (phone.getEmergencyNumberTracker() != null
7225 && phone.getEmergencyNumberTracker() != null) {
7226 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7227 number, exactMatch)) {
7228 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007229 }
7230 }
sqian11b7a0e2018-12-05 18:48:28 -08007231 }
7232 return false;
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
7236 }
7237
sqianf4ca7ed2019-01-15 18:32:07 -08007238 /**
7239 * Update emergency number list for test mode.
7240 */
7241 @Override
7242 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7243 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7244 "updateEmergencyNumberListTestMode");
7245
7246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 for (Phone phone: PhoneFactory.getPhones()) {
7249 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7250 if (tracker != null) {
7251 tracker.executeEmergencyNumberTestModeCommand(action, num);
7252 }
7253 }
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 }
7258
7259 /**
7260 * Get the full emergency number list for test mode.
7261 */
7262 @Override
7263 public List<String> getEmergencyNumberListTestMode() {
7264 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7265 "getEmergencyNumberListTestMode");
7266
7267 final long identity = Binder.clearCallingIdentity();
7268 try {
7269 Set<String> emergencyNumbers = new HashSet<>();
7270 for (Phone phone: PhoneFactory.getPhones()) {
7271 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7272 if (tracker != null) {
7273 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7274 emergencyNumbers.add(num.getNumber());
7275 }
7276 }
7277 }
7278 return new ArrayList<>(emergencyNumbers);
7279 } finally {
7280 Binder.restoreCallingIdentity(identity);
7281 }
7282 }
7283
chen xud6b45bd2018-10-30 22:27:10 -07007284 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007285 public int getEmergencyNumberDbVersion(int subId) {
7286 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7287
7288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 final Phone phone = getPhone(subId);
7291 if (phone == null) {
7292 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7293 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7294 }
7295 return phone.getEmergencyNumberDbVersion();
7296 } finally {
7297 Binder.restoreCallingIdentity(identity);
7298 }
7299 }
7300
7301 @Override
7302 public void notifyOtaEmergencyNumberDbInstalled() {
7303 enforceModifyPermission();
7304
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 for (Phone phone: PhoneFactory.getPhones()) {
7308 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7309 if (tracker != null) {
7310 tracker.updateOtaEmergencyNumberDatabase();
7311 }
7312 }
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
7315 }
7316 }
7317
7318 @Override
7319 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7320 enforceActiveEmergencySessionPermission();
7321
7322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 for (Phone phone: PhoneFactory.getPhones()) {
7325 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7326 if (tracker != null) {
7327 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7328 }
7329 }
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
7333 }
7334
7335 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007336 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7337 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7338 Phone phone = getPhone(subId);
7339 if (phone == null) {
7340 return null;
7341 }
7342 final long identity = Binder.clearCallingIdentity();
7343 try {
7344 UiccProfile profile = UiccController.getInstance()
7345 .getUiccProfileForPhone(phone.getPhoneId());
7346 if (profile != null) {
7347 return profile.getCertsFromCarrierPrivilegeAccessRules();
7348 }
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
7351 }
7352 return null;
7353 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007354
7355 /**
7356 * Enable or disable a modem stack.
7357 */
7358 @Override
7359 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7360 enforceModifyPermission();
7361
7362 final long identity = Binder.clearCallingIdentity();
7363 try {
7364 Phone phone = PhoneFactory.getPhone(slotIndex);
7365 if (phone == null) {
7366 return false;
7367 } else {
7368 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7369 }
7370 } finally {
7371 Binder.restoreCallingIdentity(identity);
7372 }
7373 }
Michelecea4cf22018-12-21 15:00:11 -08007374
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007375 /**
7376 * Whether a modem stack is enabled or not.
7377 */
7378 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007379 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7380 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007381 Phone phone = PhoneFactory.getPhone(slotIndex);
7382 if (phone == null) return false;
7383
7384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007385 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7386 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007387 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7388 }
7389
7390 final long identity = Binder.clearCallingIdentity();
7391 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007392 try {
7393 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7394 } catch (NoSuchElementException ex) {
7395 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7396 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007397 } finally {
7398 Binder.restoreCallingIdentity(identity);
7399 }
7400 }
7401
Michelecea4cf22018-12-21 15:00:11 -08007402 @Override
Michele0ea7d782019-03-19 14:58:42 -07007403 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007404 enforceModifyPermission();
7405
7406 final long identity = Binder.clearCallingIdentity();
7407 try {
7408 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007409 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007410 .commit();
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
7414 }
7415
7416 @Override
Michele0ea7d782019-03-19 14:58:42 -07007417 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007420 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7421 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007422 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007423 }
Michelecea4cf22018-12-21 15:00:11 -08007424
7425 final long identity = Binder.clearCallingIdentity();
7426 try {
Michele0ea7d782019-03-19 14:58:42 -07007427 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007432
Michele0ea7d782019-03-19 14:58:42 -07007433 @TelephonyManager.IsMultiSimSupportedResult
7434 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007435 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7436 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7437 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007438 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7439 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007440 }
7441 // Check if the hardware supports multisim functionality. If usage of multisim is not
7442 // supported by the modem, indicate that it is restricted.
7443 PhoneCapability staticCapability =
7444 mPhoneConfigurationManager.getStaticPhoneCapability();
7445 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007446 loge("isMultiSimSupportedInternal: no static configuration available");
7447 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007448 }
7449 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007450 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7451 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007452 }
7453 // Check if support of multiple SIMs is restricted by carrier
7454 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007455 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007456 }
7457
Michele0ea7d782019-03-19 14:58:42 -07007458 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007459 }
7460
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007461 /**
7462 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007463 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7464 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7465 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007466 * @param numOfSims number of active sims we want to switch to
7467 */
7468 @Override
7469 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007470 if (numOfSims == 1) {
7471 enforceModifyPermission();
7472 } else {
7473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7474 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7475 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007476 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007477
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007478 try {
Michele30b57b22019-03-01 12:01:14 -08007479 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007480 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007481 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7482 return;
7483 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007484 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
7488 }
7489
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007490 @Override
7491 public boolean isApplicationOnUicc(int subId, int appType) {
7492 enforceReadPrivilegedPermission("isApplicationOnUicc");
7493 Phone phone = getPhone(subId);
7494 if (phone == null) {
7495 return false;
7496 }
7497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 UiccCard uiccCard = phone.getUiccCard();
7500 if (uiccCard == null) {
7501 return false;
7502 }
7503 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7504 if (uiccProfile == null) {
7505 return false;
7506 }
7507 if (TelephonyManager.APPTYPE_SIM <= appType
7508 && appType <= TelephonyManager.APPTYPE_ISIM) {
7509 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7510 }
7511 return false;
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
7515 }
7516
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007517 /**
chen xub4baa772019-04-03 10:23:41 -07007518 * Get whether making changes to modem configurations will trigger reboot.
7519 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007520 */
7521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007522 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7523 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007525 mApp, subId, callingPackage, callingFeatureId,
7526 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007527 return false;
7528 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
7535 }
7536
Nathan Harold29f5f052019-02-15 13:41:57 -08007537 private void updateModemStateMetrics() {
7538 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7539 // TODO: check the state for each modem if the api is ready.
7540 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7541 }
7542
Pengquan Meng3889a572019-01-23 11:16:29 -08007543 @Override
7544 public int[] getSlotsMapping() {
7545 enforceReadPrivilegedPermission("getSlotsMapping");
7546
7547 final long identity = Binder.clearCallingIdentity();
7548 try {
7549 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7550 // All logical slots should have a mapping to a physical slot.
7551 int[] logicalSlotsMapping = new int[phoneCount];
7552 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7553 for (int i = 0; i < slotInfos.length; i++) {
7554 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7555 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7556 }
7557 }
7558 return logicalSlotsMapping;
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
7562 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007563
7564 /**
7565 * Get the IRadio HAL Version
7566 */
7567 @Override
7568 public int getRadioHalVersion() {
7569 Phone phone = getDefaultPhone();
7570 if (phone == null) return -1;
7571 HalVersion hv = phone.getHalVersion();
7572 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7573 return hv.major * 100 + hv.minor;
7574 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007575
7576 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007577 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7578 * corresponding network requests on a subId.
7579 *
7580 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007581 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007582 * 2) APN is un-metered for this subscription, or
7583 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7584 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7585 *
7586 * @return whether data is allowed for a apn type.
7587 *
7588 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007589 */
7590 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007591 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007592 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7593 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007594
7595 // Now that all security checks passes, perform the operation as ourselves.
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 Phone phone = getPhone(subId);
7599 if (phone == null) return false;
7600
Jack Yu41407ee2019-05-13 16:54:09 -07007601 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007602 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
7605 }
7606 }
7607
7608 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007609 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007610 enforceReadPrivilegedPermission("isApnMetered");
7611
7612 // Now that all security checks passes, perform the operation as ourselves.
7613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 Phone phone = getPhone(subId);
7616 if (phone == null) return true; // By default return true.
7617
Jack Yu41407ee2019-05-13 16:54:09 -07007618 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
7622 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007623
7624 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007625 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7626 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7627 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7628 if (iccRecords == null) {
7629 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7630 return false;
7631 }
7632 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7633 }
7634
7635 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007636 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7637 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7638 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7639 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7640 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7641 }
7642 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7643 Intent intent = new Intent();
7644 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7645 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7646 // Bring up choose default SMS subscription dialog right now
7647 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7648 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7649 mApp.startActivity(intent);
7650 }
chen xud5ca2d52019-05-28 15:20:57 -07007651
7652 @Override
7653 public String getMmsUAProfUrl(int subId) {
7654 //TODO investigate if this API should require proper permission check in R b/133791609
7655 final long identity = Binder.clearCallingIdentity();
7656 try {
7657 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7658 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
7661 }
7662 }
7663
7664 @Override
7665 public String getMmsUserAgent(int subId) {
7666 //TODO investigate if this API should require proper permission check in R b/133791609
7667 final long identity = Binder.clearCallingIdentity();
7668 try {
7669 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7670 .getString(com.android.internal.R.string.config_mms_user_agent);
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
7674 }
Jack Yub07d4972019-05-28 16:12:25 -07007675
7676 @Override
7677 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7678 enforceModifyPermission();
7679
7680 // Now that all security checks passes, perform the operation as ourselves.
7681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 Phone phone = getPhone(subId);
7684 if (phone == null) return false;
7685
7686 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
7689 }
7690 }
7691
7692 @Override
7693 public boolean isDataAllowedInVoiceCall(int subId) {
7694 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7695
7696 // Now that all security checks passes, perform the operation as ourselves.
7697 final long identity = Binder.clearCallingIdentity();
7698 try {
7699 Phone phone = getPhone(subId);
7700 if (phone == null) return false;
7701
7702 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
7705 }
7706 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007707
7708 /**
7709 * Updates whether conference event pacakge handling is enabled.
7710 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7711 * otherwise.
7712 */
7713 @Override
7714 public void setCepEnabled(boolean isCepEnabled) {
7715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7716
7717 final long identity = Binder.clearCallingIdentity();
7718 try {
7719 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7720 for (Phone phone : PhoneFactory.getPhones()) {
7721 Phone defaultPhone = phone.getImsPhone();
7722 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7723 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7724 ImsPhoneCallTracker imsPhoneCallTracker =
7725 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7726 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7727 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7728 + imsPhone.getMsisdn());
7729 }
7730 }
7731 } finally {
7732 Binder.restoreCallingIdentity(identity);
7733 }
7734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007735}