blob: 84a61458e2719b523417f3047fcf95de5f22c838 [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;
allenwtsu46dcc572020-01-08 18:24:03 +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 Nalluri8ff344d2019-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 Kim8d298d42018-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 Xuc7b18ec2019-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 zhaod698b842019-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 Ebinger774ba362019-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 Ebinger77b832e2019-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;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800168import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700169import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800173import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700175import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800176
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700177import java.io.FileDescriptor;
178import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800180import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800181import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800182import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800183import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100184import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700186import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
189/**
190 * Implementation of the ITelephony interface.
191 */
Santos Cordon117fee72014-05-16 17:56:12 -0700192public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private static final String LOG_TAG = "PhoneInterfaceManager";
194 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
195 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
198 // Message codes used with mMainThreadHandler
199 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700200 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
201 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202 private static final int CMD_OPEN_CHANNEL = 9;
203 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
204 private static final int CMD_CLOSE_CHANNEL = 11;
205 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800206 private static final int CMD_NV_READ_ITEM = 13;
207 private static final int EVENT_NV_READ_ITEM_DONE = 14;
208 private static final int CMD_NV_WRITE_ITEM = 15;
209 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
210 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
211 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700212 private static final int CMD_RESET_MODEM_CONFIG = 19;
213 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800214 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
215 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
216 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
217 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800218 private static final int CMD_SEND_ENVELOPE = 25;
219 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000220 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
221 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700222 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
223 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
224 private static final int CMD_EXCHANGE_SIM_IO = 31;
225 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800226 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
227 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700228 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
229 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700230 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
231 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700232 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
233 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
234 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700236 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
237 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
238 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
239 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700240 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
242 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000243 private static final int CMD_SWITCH_SLOTS = 50;
244 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700245 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
246 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
247 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
248 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
249 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
250 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
251 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
252 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700253 private static final int CMD_GET_ALL_CELL_INFO = 60;
254 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
255 private static final int CMD_GET_CELL_LOCATION = 62;
256 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700257 private static final int CMD_MODEM_REBOOT = 64;
258 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700259 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
260 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800261 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
262 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700263 private static final int CMD_GET_MODEM_STATUS = 70;
264 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700265 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
266 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700267 private static final int CMD_ERASE_MODEM_CONFIG = 74;
268 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800270 // Parameters of select command.
271 private static final int SELECT_COMMAND = 0xA4;
272 private static final int SELECT_P1 = 0x04;
273 private static final int SELECT_P2 = 0;
274 private static final int SELECT_P3 = 0x10;
275
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 /** The singleton instance. */
277 private static PhoneInterfaceManager sInstance;
278
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800281 private ImsResolver mImsResolver;
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 Nalluri8ff344d2019-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) {
Chen Xu13851032019-09-10 18:49:52 -0700882 request.result = new ModemActivityInfo(0, 0, 0, null, 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 Wang6c08ecd2019-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 Wang6c08ecd2019-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 zhaod698b842019-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 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001224 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001225 case CMD_ERASE_MODEM_CONFIG:
1226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1228 defaultPhone.eraseModemConfig(onCompleted);
1229 break;
1230 case EVENT_ERASE_MODEM_CONFIG_DONE:
1231 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001232 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 default:
1234 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1235 break;
1236 }
1237 }
Jake Hambye994d462014-02-03 13:10:13 -08001238
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 private void notifyRequester(MainThreadRequest request) {
1240 synchronized (request) {
1241 request.notifyAll();
1242 }
1243 }
1244
Jake Hambye994d462014-02-03 13:10:13 -08001245 private void handleNullReturnEvent(Message msg, String command) {
1246 AsyncResult ar = (AsyncResult) msg.obj;
1247 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1248 if (ar.exception == null) {
1249 request.result = true;
1250 } else {
1251 request.result = false;
1252 if (ar.exception instanceof CommandException) {
1253 loge(command + ": CommandException: " + ar.exception);
1254 } else {
1255 loge(command + ": Unknown exception");
1256 }
1257 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001258 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 }
1261
1262 /**
1263 * Posts the specified command to be executed on the main thread,
1264 * waits for the request to complete, and returns the result.
1265 * @see #sendRequestAsync
1266 */
1267 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001268 return sendRequest(
1269 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001270 }
1271
1272 /**
1273 * Posts the specified command to be executed on the main thread,
1274 * waits for the request to complete, and returns the result.
1275 * @see #sendRequestAsync
1276 */
1277 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1278 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001279 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001280 }
1281
1282 /**
1283 * Posts the specified command to be executed on the main thread,
1284 * waits for the request to complete, and returns the result.
1285 * @see #sendRequestAsync
1286 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001287 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001288 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001289 }
1290
1291 /**
1292 * Posts the specified command to be executed on the main thread,
1293 * waits for the request to complete, and returns the result.
1294 * @see #sendRequestAsync
1295 */
Nathan Harold92bed182018-10-12 18:16:49 -07001296 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1297 return sendRequest(command, argument, subId, null, workSource);
1298 }
1299
1300 /**
1301 * Posts the specified command to be executed on the main thread,
1302 * waits for the request to complete, and returns the result.
1303 * @see #sendRequestAsync
1304 */
1305 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1306 return sendRequest(
1307 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1308 }
1309
1310 /**
1311 * Posts the specified command to be executed on the main thread,
1312 * waits for the request to complete, and returns the result.
1313 * @see #sendRequestAsync
1314 */
1315 private Object sendRequest(
1316 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1318 throw new RuntimeException("This method will deadlock if called from the main thread.");
1319 }
1320
Nathan Harold92bed182018-10-12 18:16:49 -07001321 MainThreadRequest request = null;
1322 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1323 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1324 } else if (phone != null) {
1325 request = new MainThreadRequest(argument, phone, workSource);
1326 } else {
1327 request = new MainThreadRequest(argument, subId, workSource);
1328 }
1329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 Message msg = mMainThreadHandler.obtainMessage(command, request);
1331 msg.sendToTarget();
1332
1333 // Wait for the request to complete
1334 synchronized (request) {
1335 while (request.result == null) {
1336 try {
1337 request.wait();
1338 } catch (InterruptedException e) {
1339 // Do nothing, go back and wait until the request is complete
1340 }
1341 }
1342 }
1343 return request.result;
1344 }
1345
1346 /**
1347 * Asynchronous ("fire and forget") version of sendRequest():
1348 * Posts the specified command to be executed on the main thread, and
1349 * returns immediately.
1350 * @see #sendRequest
1351 */
1352 private void sendRequestAsync(int command) {
1353 mMainThreadHandler.sendEmptyMessage(command);
1354 }
1355
1356 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001358 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001359 */
1360 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001361 sendRequestAsync(command, argument, null, null);
1362 }
1363
1364 /**
1365 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1366 * @see {@link #sendRequest(int,Object)}
1367 */
1368 private void sendRequestAsync(
1369 int command, Object argument, Phone phone, WorkSource workSource) {
1370 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001371 Message msg = mMainThreadHandler.obtainMessage(command, request);
1372 msg.sendToTarget();
1373 }
1374
1375 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 * Initialize the singleton PhoneInterfaceManager instance.
1377 * This is only done once, at startup, from PhoneApp.onCreate().
1378 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 synchronized (PhoneInterfaceManager.class) {
1381 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001382 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 } else {
1384 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1385 }
1386 return sInstance;
1387 }
1388 }
1389
1390 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001391 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001394 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001395 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1397 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001398 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001399 mTelephonySharedPreferences =
1400 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001401 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001402 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 publish();
1405 }
1406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001407 private Phone getDefaultPhone() {
1408 Phone thePhone = getPhone(getDefaultSubscription());
1409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1410 }
1411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 private void publish() {
1413 if (DBG) log("publish: " + this);
1414
1415 ServiceManager.addService("phone", this);
1416 }
1417
Stuart Scott584921c2015-01-15 17:10:34 -08001418 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001419 if (request.phone != null) {
1420 return request.phone;
1421 } else {
1422 return getPhoneFromSubId(request.subId);
1423 }
1424 }
1425
1426 private Phone getPhoneFromSubId(int subId) {
1427 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1428 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001429 }
1430
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001431 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1432 Phone phone = getPhoneFromRequest(request);
1433 return phone == null ? null :
1434 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1435 }
1436
Wink Saville36469e72014-06-11 15:17:00 -07001437 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001438 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001439 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001442 private void sendEraseModemConfig(Phone phone) {
1443 if (phone != null) {
1444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1445 mApp, phone.getSubId(), "eraseModemConfig");
1446 final long identity = Binder.clearCallingIdentity();
1447 try {
1448 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1449 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
1452 }
1453 }
1454 }
1455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001458 }
1459
Wink Savilleb564aae2014-10-23 10:18:09 -07001460 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 if (DBG) log("dial: " + number);
1462 // No permission check needed here: This is just a wrapper around the
1463 // ACTION_DIAL intent, which is available to any app since it puts up
1464 // the UI before it does anything.
1465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001466 final long identity = Binder.clearCallingIdentity();
1467 try {
1468 String url = createTelUrl(number);
1469 if (url == null) {
1470 return;
1471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001473 // PENDING: should we just silently fail if phone is offhook or ringing?
1474 PhoneConstants.State state = mCM.getState(subId);
1475 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1476 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1477 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1478 mApp.startActivity(intent);
1479 }
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483 }
1484
1485 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 if (DBG) log("call: " + number);
1491
1492 // This is just a wrapper around the ACTION_CALL intent, but we still
1493 // need to do a permission check since we're calling startActivity()
1494 // from the context of the phone app.
1495 enforceCallPermission();
1496
Jordan Liu1617b712019-07-10 15:06:26 -07001497 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 != AppOpsManager.MODE_ALLOWED) {
1499 return;
1500 }
1501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001502 final long identity = Binder.clearCallingIdentity();
1503 try {
1504 String url = createTelUrl(number);
1505 if (url == null) {
1506 return;
1507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001509 boolean isValid = false;
1510 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1511 if (slist != null) {
1512 for (SubscriptionInfo subInfoRecord : slist) {
1513 if (subInfoRecord.getSubscriptionId() == subId) {
1514 isValid = true;
1515 break;
1516 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001517 }
Wink Saville08874612014-08-31 19:19:58 -07001518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519 if (!isValid) {
1520 return;
1521 }
Wink Saville08874612014-08-31 19:19:58 -07001522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1524 intent.putExtra(SUBSCRIPTION_KEY, subId);
1525 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1526 mApp.startActivity(intent);
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
1529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001534 }
1535
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001537 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001538 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1539 }
1540
1541 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001543 }
1544
Wink Savilleb564aae2014-10-23 10:18:09 -07001545 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001546 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001547 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1548 }
1549
1550 /** {@hide} */
1551 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001552 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001557
1558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1561 checkSimPin.start();
1562 return checkSimPin.unlockSim(null, pin);
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
1565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
Wink Saville9de0f752013-10-22 19:04:03 -07001568 /** {@hide} */
1569 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001570 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001571 }
1572
Wink Savilleb564aae2014-10-23 10:18:09 -07001573 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001575
1576 final long identity = Binder.clearCallingIdentity();
1577 try {
1578 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1579 checkSimPuk.start();
1580 return checkSimPuk.unlockSim(puk, pin);
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
1586 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001587 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 * a synchronous one.
1589 */
1590 private static class UnlockSim extends Thread {
1591
1592 private final IccCard mSimCard;
1593
1594 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001595 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1596 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597
1598 // For replies from SimCard interface
1599 private Handler mHandler;
1600
1601 // For async handler to identify request type
1602 private static final int SUPPLY_PIN_COMPLETE = 100;
1603
1604 public UnlockSim(IccCard simCard) {
1605 mSimCard = simCard;
1606 }
1607
1608 @Override
1609 public void run() {
1610 Looper.prepare();
1611 synchronized (UnlockSim.this) {
1612 mHandler = new Handler() {
1613 @Override
1614 public void handleMessage(Message msg) {
1615 AsyncResult ar = (AsyncResult) msg.obj;
1616 switch (msg.what) {
1617 case SUPPLY_PIN_COMPLETE:
1618 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1619 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001620 mRetryCount = msg.arg1;
1621 if (ar.exception != null) {
1622 if (ar.exception instanceof CommandException &&
1623 ((CommandException)(ar.exception)).getCommandError()
1624 == CommandException.Error.PASSWORD_INCORRECT) {
1625 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1626 } else {
1627 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1628 }
1629 } else {
1630 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 mDone = true;
1633 UnlockSim.this.notifyAll();
1634 }
1635 break;
1636 }
1637 }
1638 };
1639 UnlockSim.this.notifyAll();
1640 }
1641 Looper.loop();
1642 }
1643
1644 /*
1645 * Use PIN or PUK to unlock SIM card
1646 *
1647 * If PUK is null, unlock SIM card with PIN
1648 *
1649 * If PUK is not null, unlock SIM card with PUK and set PIN code
1650 */
Wink Saville9de0f752013-10-22 19:04:03 -07001651 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652
1653 while (mHandler == null) {
1654 try {
1655 wait();
1656 } catch (InterruptedException e) {
1657 Thread.currentThread().interrupt();
1658 }
1659 }
1660 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1661
1662 if (puk == null) {
1663 mSimCard.supplyPin(pin, callback);
1664 } else {
1665 mSimCard.supplyPuk(puk, pin, callback);
1666 }
1667
1668 while (!mDone) {
1669 try {
1670 Log.d(LOG_TAG, "wait for done");
1671 wait();
1672 } catch (InterruptedException e) {
1673 // Restore the interrupted status
1674 Thread.currentThread().interrupt();
1675 }
1676 }
1677 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001678 int[] resultArray = new int[2];
1679 resultArray[0] = mResult;
1680 resultArray[1] = mRetryCount;
1681 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683 }
1684
1685 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001686 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001687
1688 }
1689
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 // No permission check needed here: this call is harmless, and it's
1692 // needed for the ServiceState.requestStateUpdate() call (which is
1693 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 phone.updateServiceLocation();
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001705 @Override
1706 public boolean isRadioOn(String callingPackage) {
1707 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
1709
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001710 @Override
1711 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001713 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001714 return false;
1715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 return isRadioOnForSubscriber(subId);
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
1722 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001723 }
1724
1725 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
1730 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1731 } else {
1732 return false;
1733 }
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
1739 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001740 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
Wink Saville36469e72014-06-11 15:17:00 -07001742
Wink Savilleb564aae2014-10-23 10:18:09 -07001743 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745
1746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 final Phone phone = getPhone(subId);
1749 if (phone != null) {
1750 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1751 }
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755 }
1756
1757 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001758 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001759 }
1760
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763
1764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 final Phone phone = getPhone(subId);
1767 if (phone == null) {
1768 return false;
1769 }
1770 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1771 toggleRadioOnOffForSubscriber(subId);
1772 }
1773 return true;
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
Wink Saville36469e72014-06-11 15:17:00 -07001778
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001780 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001781 /*
1782 * If any of the Radios are available, it will need to be
1783 * shutdown. So return true if any Radio is available.
1784 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1788 Phone phone = PhoneFactory.getPhone(i);
1789 if (phone != null && phone.isRadioAvailable()) return true;
1790 }
1791 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1792 return false;
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 }
1797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001799 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 enforceModifyPermission();
1801
1802 final long identity = Binder.clearCallingIdentity();
1803 try {
1804 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1805 logv("Shutting down Phone " + i);
1806 shutdownRadioUsingPhoneId(i);
1807 }
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 }
1811 }
1812
1813 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001814 Phone phone = PhoneFactory.getPhone(phoneId);
1815 if (phone != null && phone.isRadioAvailable()) {
1816 phone.shutdownRadio();
1817 }
1818 }
1819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822
1823 final long identity = Binder.clearCallingIdentity();
1824 try {
1825 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1826 if (defaultPhone != null) {
1827 defaultPhone.setRadioPower(turnOn);
1828 return true;
1829 } else {
1830 loge("There's no default phone.");
1831 return false;
1832 }
1833 } finally {
1834 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001835 }
Wink Saville36469e72014-06-11 15:17:00 -07001836 }
1837
Wink Savilleb564aae2014-10-23 10:18:09 -07001838 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001840
1841 final long identity = Binder.clearCallingIdentity();
1842 try {
1843 final Phone phone = getPhone(subId);
1844 if (phone != null) {
1845 phone.setRadioPower(turnOn);
1846 return true;
1847 } else {
1848 return false;
1849 }
1850 } finally {
1851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 }
1854
Wink Saville36469e72014-06-11 15:17:00 -07001855 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 public boolean enableDataConnectivity() {
1858 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001859
1860 final long identity = Binder.clearCallingIdentity();
1861 try {
1862 int subId = mSubscriptionController.getDefaultDataSubId();
1863 final Phone phone = getPhone(subId);
1864 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001865 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 return true;
1867 } else {
1868 return false;
1869 }
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Wink Saville36469e72014-06-11 15:17:00 -07001875 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 public boolean disableDataConnectivity() {
1878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001879
1880 final long identity = Binder.clearCallingIdentity();
1881 try {
1882 int subId = mSubscriptionController.getDefaultDataSubId();
1883 final Phone phone = getPhone(subId);
1884 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001885 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001886 return true;
1887 } else {
1888 return false;
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001896 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001901 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902 } else {
1903 return false;
1904 }
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
1910 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001911 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
pkanwarae03a6b2016-11-06 20:37:09 -08001914 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 enforceCallPermission();
1916
1917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1920 return;
1921 }
1922 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1923 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1924 } finally {
1925 Binder.restoreCallingIdentity(identity);
1926 }
pkanwar32d516d2016-10-14 19:37:38 -07001927 };
1928
Wink Savilleb564aae2014-10-23 10:18:09 -07001929 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931
1932 final long identity = Binder.clearCallingIdentity();
1933 try {
1934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1935 return false;
1936 }
1937 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1938 } finally {
1939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001944 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001945 }
1946
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001947 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948 final long identity = Binder.clearCallingIdentity();
1949 try {
1950 Phone phone = PhoneFactory.getPhone(slotIndex);
1951 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1952 PhoneConstantConversions.convertCallState(phone.getState());
1953 } finally {
1954 Binder.restoreCallingIdentity(identity);
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
1957
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001959 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001960 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1961 }
1962
1963 @Override
1964 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 final long identity = Binder.clearCallingIdentity();
1966 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001967 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 if (phone != null) {
1969 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1970 } else {
1971 return PhoneConstantConversions.convertDataState(
1972 PhoneConstants.DataState.DISCONNECTED);
1973 }
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001980 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001981 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1982 }
1983
1984 @Override
1985 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001988 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 if (phone != null) {
1990 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1991 } else {
1992 return TelephonyManager.DATA_ACTIVITY_NONE;
1993 }
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002000 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002001 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002002 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002003
2004 LocationAccessPolicy.LocationPermissionResult locationResult =
2005 LocationAccessPolicy.checkLocationPermission(mApp,
2006 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2007 .setCallingPackage(callingPackage)
2008 .setCallingPid(Binder.getCallingPid())
2009 .setCallingUid(Binder.getCallingUid())
2010 .setMethod("getCellLocation")
2011 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2012 .build());
2013 switch (locationResult) {
2014 case DENIED_HARD:
2015 throw new SecurityException("Not allowed to access cell location");
2016 case DENIED_SOFT:
2017 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 }
2019
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 if (DBG_LOC) log("getCellLocation: is active user");
2024 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002025 int subId = mSubscriptionController.getDefaultDataSubId();
2026 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2027 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028 return data;
2029 } finally {
2030 Binder.restoreCallingIdentity(identity);
2031 }
Svetoslav64fad262015-04-14 14:35:21 -07002032 }
2033
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 @Override
Jack Yu7c5d91a2019-09-26 11:48:33 -07002035 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2036 if (!TextUtils.isEmpty(callingPackage)) {
2037 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2039 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2040 return "";
2041 }
2042 }
2043
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002044 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2045 // registered cell info, so return a NULL country instead.
2046 final long identity = Binder.clearCallingIdentity();
2047 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002048 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2049 // Get default phone in this case.
2050 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2051 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002053 // Todo: fix this when we can get the actual cellular network info when the device
2054 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 if (TelephonyManager.NETWORK_TYPE_IWLAN
2056 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2057 return "";
2058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 Phone phone = PhoneFactory.getPhone(phoneId);
2060 if (phone != null) {
2061 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002062 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063 if (sst != null) {
2064 LocaleTracker lt = sst.getLocaleTracker();
2065 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002066 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2067 return lt.getCurrentCountry();
2068 } else if (emergencyNumberTracker != null) {
2069 return emergencyNumberTracker.getEmergencyCountryIso();
2070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071 }
2072 }
2073 }
2074 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002075 } finally {
2076 Binder.restoreCallingIdentity(identity);
2077 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002078 }
2079
2080 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002082 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002083 }
2084
Sanket Padawe356d7632015-06-22 14:03:32 -07002085 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002086 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 mApp.enforceCallingOrSelfPermission(
2088 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002089
2090 final long identity = Binder.clearCallingIdentity();
2091 try {
2092 final Phone phone = getPhone(subId);
2093 if (phone != null) {
2094 phone.enableLocationUpdates();
2095 }
2096 } finally {
2097 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 }
2100
2101 @Override
2102 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002103 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002104 }
2105
Sanket Padawe356d7632015-06-22 14:03:32 -07002106 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002107 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 mApp.enforceCallingOrSelfPermission(
2109 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002110
2111 final long identity = Binder.clearCallingIdentity();
2112 try {
2113 final Phone phone = getPhone(subId);
2114 if (phone != null) {
2115 phone.disableLocationUpdates();
2116 }
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121
Nathan Harold31d7ff32018-10-15 20:20:30 -07002122 /**
2123 * Returns the target SDK version number for a given package name.
2124 *
Nathan Haroldec184742019-07-10 17:04:16 -07002125 * This call MUST be invoked before clearing the calling UID.
2126 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002127 * @return target SDK if the package is found or INT_MAX.
2128 */
2129 private int getTargetSdk(String packageName) {
2130 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002131 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002132 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002133 if (ai != null) return ai.targetSdkVersion;
2134 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002135 loge("Failed to get package info for pkg="
2136 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002137 }
2138 return Integer.MAX_VALUE;
2139 }
2140
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 @Override
2142 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002143 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2144 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002145 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2146 throw new SecurityException(
2147 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2148 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002149
Jordan Liu1617b712019-07-10 15:06:26 -07002150 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2152 return null;
2153 }
Svetoslav64fad262015-04-14 14:35:21 -07002154
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002155 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156
Nathan Haroldf180aac2018-06-01 18:43:55 -07002157 List<CellInfo> info = getAllCellInfo(callingPackage);
2158 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159
Nathan Haroldf180aac2018-06-01 18:43:55 -07002160 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2161 for (CellInfo ci : info) {
2162 if (ci instanceof CellInfoGsm) {
2163 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2164 } else if (ci instanceof CellInfoWcdma) {
2165 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002168 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002171 private List<CellInfo> getCachedCellInfo() {
2172 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2173 for (Phone phone : PhoneFactory.getPhones()) {
2174 List<CellInfo> info = phone.getAllCellInfo();
2175 if (info != null) cellInfos.addAll(info);
2176 }
2177 return cellInfos;
2178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179
2180 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002181 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002182 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002183 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002184
2185 LocationAccessPolicy.LocationPermissionResult locationResult =
2186 LocationAccessPolicy.checkLocationPermission(mApp,
2187 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2188 .setCallingPackage(callingPackage)
2189 .setCallingPid(Binder.getCallingPid())
2190 .setCallingUid(Binder.getCallingUid())
2191 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2194 .build());
2195 switch (locationResult) {
2196 case DENIED_HARD:
2197 throw new SecurityException("Not allowed to access cell info");
2198 case DENIED_SOFT:
2199 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002202 final int targetSdk = getTargetSdk(callingPackage);
2203 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2204 return getCachedCellInfo();
2205 }
2206
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002207 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2212 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002213 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002214 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 if (info != null) cellInfos.addAll(info);
2216 }
2217 return cellInfos;
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002224 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2225 requestCellInfoUpdateInternal(
2226 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2227 }
2228
2229 @Override
2230 public void requestCellInfoUpdateWithWorkSource(
2231 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2232 enforceModifyPermission();
2233 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2234 }
2235
2236 private void requestCellInfoUpdateInternal(
2237 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002238 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002239 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002240
2241 LocationAccessPolicy.LocationPermissionResult locationResult =
2242 LocationAccessPolicy.checkLocationPermission(mApp,
2243 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2244 .setCallingPackage(callingPackage)
2245 .setCallingPid(Binder.getCallingPid())
2246 .setCallingUid(Binder.getCallingUid())
2247 .setMethod("requestCellInfoUpdate")
2248 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2249 .build());
2250 switch (locationResult) {
2251 case DENIED_HARD:
2252 throw new SecurityException("Not allowed to access cell info");
2253 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002254 try {
2255 cb.onCellInfo(new ArrayList<CellInfo>());
2256 } catch (RemoteException re) {
2257 // Drop without consequences
2258 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002259 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002260 }
2261
Nathan Harolda939a962019-05-09 10:13:47 -07002262
2263 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002264 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2265
2266 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2267 }
2268
2269 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002271 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273
2274 final long identity = Binder.clearCallingIdentity();
2275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002276 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 } finally {
2278 Binder.restoreCallingIdentity(identity);
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
Shishir Agrawala9f32182016-04-12 12:00:16 -07002282 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002283 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 Phone phone = PhoneFactory.getPhone(slotIndex);
2285 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002286 return null;
2287 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002288 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002289 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2290 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002291 return null;
2292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 return phone.getImei();
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002300 }
2301
2302 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002303 public String getTypeAllocationCodeForSlot(int slotIndex) {
2304 Phone phone = PhoneFactory.getPhone(slotIndex);
2305 String tac = null;
2306 if (phone != null) {
2307 String imei = phone.getImei();
2308 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2309 }
2310 return tac;
2311 }
2312
2313 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002314 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002315 Phone phone = PhoneFactory.getPhone(slotIndex);
2316 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002317 return null;
2318 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002319
Jeff Davidson913390f2018-02-23 17:11:49 -08002320 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002321 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2322 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002323 return null;
2324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325
2326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 return phone.getMeid();
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
2331 }
Jack Yu2af8d712017-03-15 17:14:14 -07002332 }
2333
2334 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002335 public String getManufacturerCodeForSlot(int slotIndex) {
2336 Phone phone = PhoneFactory.getPhone(slotIndex);
2337 String manufacturerCode = null;
2338 if (phone != null) {
2339 String meid = phone.getMeid();
2340 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2341 }
2342 return manufacturerCode;
2343 }
2344
2345 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002346 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002347 Phone phone = PhoneFactory.getPhone(slotIndex);
2348 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002349 return null;
2350 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002351 int subId = phone.getSubId();
2352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2353 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2354 return null;
2355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 return phone.getDeviceSvn();
2360 } finally {
2361 Binder.restoreCallingIdentity(identity);
2362 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002363 }
2364
fionaxu43304da2017-11-27 22:51:16 -08002365 @Override
2366 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 final Phone phone = getPhone(subId);
2370 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
2373 }
fionaxu43304da2017-11-27 22:51:16 -08002374 }
2375
2376 @Override
2377 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 final Phone phone = getPhone(subId);
2381 return phone == null ? null : phone.getCarrierName();
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
2384 }
fionaxu43304da2017-11-27 22:51:16 -08002385 }
2386
calvinpanffe225e2018-11-01 19:43:06 +08002387 @Override
chen xu0026ca62019-03-06 15:28:50 -08002388 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 final Phone phone = getPhone(subId);
2392 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002393 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
2397 }
2398
2399 @Override
chen xu0026ca62019-03-06 15:28:50 -08002400 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002404 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
2408 }
2409
chen xu651eec72018-11-11 19:03:44 -08002410 @Override
chen xu864e11c2018-12-06 22:10:03 -08002411 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2412 if (!isSubscriptionMccMnc) {
2413 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2414 }
chen xu651eec72018-11-11 19:03:44 -08002415 final Phone phone = PhoneFactory.getPhone(slotIndex);
2416 if (phone == null) {
2417 return TelephonyManager.UNKNOWN_CARRIER_ID;
2418 }
2419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2422 } finally {
2423 Binder.restoreCallingIdentity(identity);
2424 }
2425 }
2426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 //
2428 // Internal helper methods.
2429 //
2430
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002431 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2433 *
2434 * @throws SecurityException if the caller does not have the required permission
2435 */
2436 private void enforceModifyPermission() {
2437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2438 }
2439
Shuo Qianf2b2df42019-11-13 17:43:31 -08002440 private void enforceActiveEmergencySessionPermission() {
2441 mApp.enforceCallingOrSelfPermission(
2442 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2443 }
2444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 /**
2446 * Make sure the caller has the CALL_PHONE permission.
2447 *
2448 * @throws SecurityException if the caller does not have the required permission
2449 */
2450 private void enforceCallPermission() {
2451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2452 }
2453
paulhu423b5f22019-08-23 19:17:33 +08002454 private void enforceSettingsPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002456 }
2457
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 private String createTelUrl(String number) {
2459 if (TextUtils.isEmpty(number)) {
2460 return null;
2461 }
2462
Jake Hambye994d462014-02-03 13:10:13 -08002463 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
Ihab Awadf9e92732013-12-05 18:02:52 -08002466 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2468 }
2469
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002470 private static void logv(String msg) {
2471 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2472 }
2473
Ihab Awadf9e92732013-12-05 18:02:52 -08002474 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2476 }
2477
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002478 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002480 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002481 }
2482
Sanket Padawe356d7632015-06-22 14:03:32 -07002483 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002484 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 final Phone phone = PhoneFactory.getPhone(slotIndex);
2488 if (phone == null) {
2489 return PhoneConstants.PHONE_TYPE_NONE;
2490 } else {
2491 return phone.getPhoneType();
2492 }
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
2497
2498 /**
2499 * Returns the CDMA ERI icon index to display
2500 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002501 @Override
2502 public int getCdmaEriIconIndex(String callingPackage) {
2503 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002504 }
2505
Sanket Padawe356d7632015-06-22 14:03:32 -07002506 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002507 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002509 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002510 return -1;
2511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512
2513 final long identity = Binder.clearCallingIdentity();
2514 try {
2515 final Phone phone = getPhone(subId);
2516 if (phone != null) {
2517 return phone.getCdmaEriIconIndex();
2518 } else {
2519 return -1;
2520 }
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
2526 /**
2527 * Returns the CDMA ERI icon mode,
2528 * 0 - ON
2529 * 1 - FLASHING
2530 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 @Override
2532 public int getCdmaEriIconMode(String callingPackage) {
2533 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002534 }
2535
Sanket Padawe356d7632015-06-22 14:03:32 -07002536 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002537 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002539 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002540 return -1;
2541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542
2543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 final Phone phone = getPhone(subId);
2546 if (phone != null) {
2547 return phone.getCdmaEriIconMode();
2548 } else {
2549 return -1;
2550 }
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
2555
2556 /**
2557 * Returns the CDMA ERI text,
2558 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002559 @Override
2560 public String getCdmaEriText(String callingPackage) {
2561 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002562 }
2563
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002565 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002567 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002568 return null;
2569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null) {
2575 return phone.getCdmaEriText();
2576 } else {
2577 return null;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
2584 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002585 * Returns the CDMA MDN.
2586 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002587 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002588 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2590 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002595 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 return phone.getLine1Number();
2597 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002598 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 return null;
2600 }
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002603 }
2604 }
2605
2606 /**
2607 * Returns the CDMA MIN.
2608 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002610 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2612 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613
2614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 final Phone phone = getPhone(subId);
2617 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2618 return phone.getCdmaMin();
2619 } else {
2620 return null;
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002624 }
2625 }
2626
Hall Liud892bec2018-11-30 14:51:45 -08002627 @Override
2628 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2629 INumberVerificationCallback callback, String callingPackage) {
2630 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2631 != PERMISSION_GRANTED) {
2632 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2633 }
2634 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2635
2636 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2637 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2638 throw new SecurityException("Calling package must be configured in the device config");
2639 }
2640
2641 if (range == null) {
2642 throw new NullPointerException("Range must be non-null");
2643 }
2644
2645 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002646 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002647
2648 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2649 }
2650
Junda Liuca05d5d2014-08-14 22:36:34 -07002651 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 * Returns true if CDMA provisioning needs to run.
2653 */
2654 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002657 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
2662
2663 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002664 * Sets the voice mail number of a given subId.
2665 */
2666 @Override
2667 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002668 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
2672 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2673 new Pair<String, String>(alphaTag, number), new Integer(subId));
2674 return success;
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
2677 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002678 }
2679
Ta-wei Yen87c49842016-05-13 21:19:52 -07002680 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002681 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002683 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2684 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002685 if (!TextUtils.equals(callingPackage, systemDialer)) {
2686 throw new SecurityException("caller must be system dialer");
2687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2692 if (phoneAccountHandle == null) {
2693 return null;
2694 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002695 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002698 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002699 }
2700
2701 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002702 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002705 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002706 return null;
2707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002709 final long identity = Binder.clearCallingIdentity();
2710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002711 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002715 }
2716
2717 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002718 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2719 VisualVoicemailSmsFilterSettings settings) {
2720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721
2722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } finally {
2727 Binder.restoreCallingIdentity(identity);
2728 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002729 }
2730
2731 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002732 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
2735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002738 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 } finally {
2740 Binder.restoreCallingIdentity(identity);
2741 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002742 }
2743
2744 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002745 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2746 String callingPackage, int subId) {
2747 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748
2749 final long identity = Binder.clearCallingIdentity();
2750 try {
2751 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002752 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753 } finally {
2754 Binder.restoreCallingIdentity(identity);
2755 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002756 }
2757
2758 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002759 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002760 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002765 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 } finally {
2767 Binder.restoreCallingIdentity(identity);
2768 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002769 }
2770
2771 @Override
2772 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2773 String number, int port, String text, PendingIntent sentIntent) {
2774 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002775 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002776 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002777 SmsController smsController = PhoneFactory.getSmsController();
2778 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2779 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002780 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002781
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002782 /**
fionaxu0152e512016-11-14 13:36:14 -08002783 * Sets the voice activation state of a given subId.
2784 */
2785 @Override
2786 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2788 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789
2790 final long identity = Binder.clearCallingIdentity();
2791 try {
2792 final Phone phone = getPhone(subId);
2793 if (phone != null) {
2794 phone.setVoiceActivationState(activationState);
2795 } else {
2796 loge("setVoiceActivationState fails with invalid subId: " + subId);
2797 }
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002800 }
2801 }
2802
2803 /**
2804 * Sets the data activation state of a given subId.
2805 */
2806 @Override
2807 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2809 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 final Phone phone = getPhone(subId);
2814 if (phone != null) {
2815 phone.setDataActivationState(activationState);
2816 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002817 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002821 }
2822 }
2823
2824 /**
2825 * Returns the voice activation state of a given subId.
2826 */
2827 @Override
2828 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002829 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830
fionaxu0152e512016-11-14 13:36:14 -08002831 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 if (phone != null) {
2835 return phone.getVoiceActivationState();
2836 } else {
2837 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002841 }
2842 }
2843
2844 /**
2845 * Returns the data activation state of a given subId.
2846 */
2847 @Override
2848 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002849 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
fionaxu0152e512016-11-14 13:36:14 -08002851 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 if (phone != null) {
2855 return phone.getDataActivationState();
2856 } else {
2857 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2858 }
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002861 }
2862 }
2863
2864 /**
Wink Saville36469e72014-06-11 15:17:00 -07002865 * Returns the unread count of voicemails for a subId
2866 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002867 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002868 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2870 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2871 return 0;
2872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 final Phone phone = getPhone(subId);
2876 if (phone != null) {
2877 return phone.getVoiceMessageCount();
2878 } else {
2879 return 0;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
2886 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002887 * returns true, if the device is in a state where both voice and data
2888 * are supported simultaneously. This can change based on location or network condition.
2889 */
2890 @Override
2891 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 final Phone phone = getPhone(subId);
2895 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002899 }
2900
2901 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002902 * Send the dialer code if called from the current default dialer or the caller has
2903 * carrier privilege.
2904 * @param inputCode The dialer code to send
2905 */
2906 @Override
2907 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002908 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002910 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2911 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002912 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002913 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2914 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002919 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 } finally {
2921 Binder.restoreCallingIdentity(identity);
2922 }
fionaxu235cc5e2017-03-06 22:25:57 -08002923 }
2924
Pengquan Menga1bb6272018-09-06 09:59:22 -07002925 @Override
2926 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002927 if (!isActiveSubscription(subId)) {
2928 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2929 }
2930
Pengquan Menga1bb6272018-09-06 09:59:22 -07002931 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2932 }
2933
Brad Ebinger35c841c2018-10-01 10:40:55 -07002934 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002935 public boolean isInEmergencySmsMode() {
2936 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 for (Phone phone : PhoneFactory.getPhones()) {
2940 if (phone.isInEmergencySmsMode()) {
2941 return true;
2942 }
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
2947 return false;
2948 }
2949
2950 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002951 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2952 throws RemoteException {
2953 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002954 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2955 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2956 "IMS not available on device.");
2957 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 final long token = Binder.clearCallingIdentity();
2959 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002961 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002962 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002963 } catch (ImsException e) {
2964 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 } finally {
2966 Binder.restoreCallingIdentity(token);
2967 }
2968 }
2969
2970 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002971 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2972 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002973 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2974 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2975 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002976 final long token = Binder.clearCallingIdentity();
2977 try {
2978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2980 .removeRegistrationCallbackForSubscription(c, subId);
2981 } catch (ImsException e) {
2982 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2983 + "is inactive, ignoring unregister.");
2984 // If the subscription is no longer active, just return, since the callback
2985 // will already have been removed internally.
2986 } finally {
2987 Binder.restoreCallingIdentity(token);
2988 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002989 }
2990
Brad Ebinger774ba362019-10-22 17:36:18 -07002991 /**
2992 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2993 */
2994 @Override
2995 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2996 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2997 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2998 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2999 "IMS not available on device.");
3000 }
3001 final long token = Binder.clearCallingIdentity();
3002 try {
3003 Phone phone = getPhone(subId);
3004 if (phone == null) {
3005 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3006 + subId + "'");
3007 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3008 }
3009 phone.getImsRegistrationState(regState -> {
3010 try {
3011 consumer.accept((regState == null)
3012 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3013 } catch (RemoteException e) {
3014 // Ignore if the remote process is no longer available to call back.
3015 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3016 }
3017 });
3018 } finally {
3019 Binder.restoreCallingIdentity(token);
3020 }
3021 }
3022
3023 /**
3024 * Get the transport type for the IMS service registration state.
3025 */
3026 @Override
3027 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3028 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3031 "IMS not available on device.");
3032 }
3033 final long token = Binder.clearCallingIdentity();
3034 try {
3035 Phone phone = getPhone(subId);
3036 if (phone == null) {
3037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3038 + subId + "'");
3039 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3040 }
3041 phone.getImsRegistrationTech(regTech -> {
3042 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3043 int regTechConverted = (regTech == null)
3044 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3045 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3046 regTechConverted);
3047 try {
3048 consumer.accept(regTechConverted);
3049 } catch (RemoteException e) {
3050 // Ignore if the remote process is no longer available to call back.
3051 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3052 }
3053 });
3054 } finally {
3055 Binder.restoreCallingIdentity(token);
3056 }
3057 }
3058
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003060 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3061 throws RemoteException {
3062 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003063 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3064 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3065 "IMS not available on device.");
3066 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3068 final long token = Binder.clearCallingIdentity();
3069 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003070 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003072 } catch (ImsException e) {
3073 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 } finally {
3075 Binder.restoreCallingIdentity(token);
3076 }
3077 }
3078
3079 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003080 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3081 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003082 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3083 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3084 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003085
3086 final long token = Binder.clearCallingIdentity();
3087 try {
3088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3089 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003090 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003091 } catch (ImsException e) {
3092 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3093 + "is inactive, ignoring unregister.");
3094 // If the subscription is no longer active, just return, since the callback
3095 // will already have been removed internally.
3096 } finally {
3097 Binder.restoreCallingIdentity(token);
3098 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 }
3100
3101 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003102 public boolean isCapable(int subId, int capability, int regTech) {
3103 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3105 final long token = Binder.clearCallingIdentity();
3106 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003109 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003110 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3111 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003112 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003113 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3114 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 } finally {
3116 Binder.restoreCallingIdentity(token);
3117 }
3118 }
3119
3120 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003121 public boolean isAvailable(int subId, int capability, int regTech) {
3122 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003123 final long token = Binder.clearCallingIdentity();
3124 try {
3125 Phone phone = getPhone(subId);
3126 if (phone == null) return false;
3127 return phone.isImsCapabilityAvailable(capability, regTech);
3128 } finally {
3129 Binder.restoreCallingIdentity(token);
3130 }
3131 }
3132
Brad Ebinger77b832e2019-10-17 17:03:22 -07003133 /**
3134 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3135 * subscription.
3136 * @param subId The subscription to use to check the configuration.
3137 * @param callback The callback that will be used to send the result.
3138 * @param capability The MmTelFeature capability that will be used to send the result.
3139 * @param transportType The transport type of the MmTelFeature capability.
3140 */
3141 @Override
3142 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3143 int transportType) {
3144 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3145 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3146 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3147 "IMS not available on device.");
3148 }
3149 final long token = Binder.clearCallingIdentity();
3150 try {
3151 int slotId = getSlotIndex(subId);
3152 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3153 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3154 + subId + "'");
3155 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3156 }
3157 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3158 transportType, aBoolean -> {
3159 try {
3160 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3161 } catch (RemoteException e) {
3162 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3163 + "running. Ignore");
3164 }
3165 });
3166 } finally {
3167 Binder.restoreCallingIdentity(token);
3168 }
3169 }
3170
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 @Override
3172 public boolean isAdvancedCallingSettingEnabled(int subId) {
3173 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3174 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3175 final long token = Binder.clearCallingIdentity();
3176 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003178 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003179 } catch (ImsException e) {
3180 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 } finally {
3182 Binder.restoreCallingIdentity(token);
3183 }
3184 }
3185
3186 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003187 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003189 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003194 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003195 } catch (ImsException e) {
3196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
3200 }
3201
3202 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003203 public boolean isVtSettingEnabled(int subId) {
3204 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003208 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3209 } catch (ImsException e) {
3210 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
3214 }
3215
3216 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003217 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003219 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003224 } catch (ImsException e) {
3225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
3229 }
3230
3231 @Override
3232 public boolean isVoWiFiSettingEnabled(int subId) {
3233 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003237 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003239 } catch (ImsException e) {
3240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
3246 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003247 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003249 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003254 } catch (ImsException e) {
3255 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
3259 }
3260
3261 @Override
3262 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3263 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003267 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003269 } catch (ImsException e) {
3270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 } finally {
3272 Binder.restoreCallingIdentity(identity);
3273 }
3274 }
3275
3276 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003277 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003279 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003283 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003285 } catch (ImsException e) {
3286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
3290 }
3291
3292 @Override
3293 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3295 "setVoWiFiNonPersistent");
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003299 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003300 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003301 } catch (ImsException e) {
3302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
3306 }
3307
3308 @Override
3309 public int getVoWiFiModeSetting(int subId) {
3310 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003314 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003316 } catch (ImsException e) {
3317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
3324 public void setVoWiFiModeSetting(int subId, int mode) {
3325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3326 "setVoWiFiModeSetting");
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003330 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003331 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003332 } catch (ImsException e) {
3333 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
3337 }
3338
3339 @Override
3340 public int getVoWiFiRoamingModeSetting(int subId) {
3341 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003345 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003346 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003347 } catch (ImsException e) {
3348 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
3352 }
3353
3354 @Override
3355 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3357 "setVoWiFiRoamingModeSetting");
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003363 } catch (ImsException e) {
3364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
3368 }
3369
3370 @Override
3371 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3373 "setRttCapabilityEnabled");
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003377 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3378 } catch (ImsException e) {
3379 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
3383 }
3384
3385 @Override
3386 public boolean isTtyOverVolteEnabled(int subId) {
3387 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003391 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003392 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003393 } catch (ImsException e) {
3394 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
3398 }
3399
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003400 @Override
3401 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3402 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003406 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003407 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003408 } catch (ImsException e) {
3409 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
3413 }
3414
3415 @Override
3416 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3417 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3418 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003419 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3420 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3421 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003422 try {
3423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003425 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003426 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003427 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3428 + "is inactive, ignoring unregister.");
3429 // If the subscription is no longer active, just return, since the callback will already
3430 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
3436 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003437 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3438 boolean isProvisioned) {
3439 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3440 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3441 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3442 }
3443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3444 "setProvisioningStatusForCapability");
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3448 Phone phone = getPhone(subId);
3449 if (phone == null) {
3450 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3451 + subId);
3452 return;
3453 }
3454 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3455 return;
3456 }
3457
3458 // this capability requires provisioning, route to the correct API.
3459 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3460 switch (capability) {
3461 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3462 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3463 ims.setVolteProvisioned(isProvisioned);
3464 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3465 ims.setWfcProvisioned(isProvisioned);
3466 }
3467 break;
3468 }
3469 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3470 // There is currently no difference in VT provisioning type.
3471 ims.setVtProvisioned(isProvisioned);
3472 break;
3473 }
3474 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3475 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3476 // change the capability of the feature instead if needed.
3477 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3478 == isProvisioned) {
3479 // No change in provisioning.
3480 return;
3481 }
3482 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3483 try {
3484 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003485 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003486 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3487 + ", Exception" + e.getMessage());
3488 }
3489 break;
3490 }
3491 default: {
3492 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3493 + capability + "', which does not require provisioning.");
3494 }
3495 }
3496
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
3500 }
3501
3502 @Override
3503 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3504 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3505 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3506 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3507 }
3508 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3512 Phone phone = getPhone(subId);
3513 if (phone == null) {
3514 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3515 + subId);
3516 // We will fail with "true" as the provisioning status because this is the default
3517 // if we do not require provisioning.
3518 return true;
3519 }
3520
3521 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3522 return true;
3523 }
3524
3525 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3526 switch (capability) {
3527 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3528 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3529 return ims.isVolteProvisionedOnDevice();
3530 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3531 return ims.isWfcProvisionedOnDevice();
3532 }
3533 // This should never happen, since we are checking tech above to make sure it
3534 // is either LTE or IWLAN.
3535 throw new IllegalArgumentException("Invalid radio technology for voice "
3536 + "capability.");
3537 }
3538 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3539 // There is currently no difference in VT provisioning type.
3540 return ims.isVtProvisionedOnDevice();
3541 }
3542 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3543 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3544 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3545 }
3546 default: {
3547 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3548 + capability + "', which does not require provisioning.");
3549 }
3550 }
3551
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
3555 }
3556
3557 @Override
3558 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3559 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3560 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3561 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3562 }
3563 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3564 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3565 return (provisionedBits & capability) > 0;
3566 }
3567
3568 @Override
3569 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3570 boolean isProvisioned) {
3571 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3572 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3573 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3574 }
3575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3576 "setProvisioningStatusForCapability");
3577 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3578 // If the current provisioning status for capability already matches isProvisioned,
3579 // do nothing.
3580 if (((provisionedBits & capability) > 0) == isProvisioned) {
3581 return;
3582 }
3583 if (isProvisioned) {
3584 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3585 } else {
3586 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3587 }
3588 }
3589
3590 /**
3591 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3592 * technology. The bitfield should mirror the bitfield defined by
3593 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3594 */
3595 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3596 String key = getMmTelProvisioningKey(subId, tech);
3597 // Default is no capabilities are provisioned.
3598 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3599 }
3600
3601 /**
3602 * Sets the MmTel capability provisioning bitfield (defined by
3603 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3604 * technology specified.
3605 *
3606 * Note: This is a synchronous command and should not be called on UI thread.
3607 */
3608 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3609 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3610 String key = getMmTelProvisioningKey(subId, tech);
3611 editor.putInt(key, newField);
3612 editor.commit();
3613 }
3614
3615 private static String getMmTelProvisioningKey(int subId, int tech) {
3616 // resulting key is provision_ims_mmtel_{subId}_{tech}
3617 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3618 }
3619
3620 /**
3621 * Query CarrierConfig to see if the specified capability requires provisioning for the
3622 * carrier associated with the subscription id.
3623 */
3624 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3625 int capability) {
3626 CarrierConfigManager configManager = new CarrierConfigManager(context);
3627 PersistableBundle c = configManager.getConfigForSubId(subId);
3628 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003629 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003630 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3631 false);
3632 boolean requireVoiceVtProvisioning = c.getBoolean(
3633 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3634
3635 // First check to make sure that the capability requires provisioning.
3636 switch (capability) {
3637 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3638 // intentional fallthrough
3639 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3640 if (requireVoiceVtProvisioning) {
3641 // Voice and Video requires provisioning
3642 return true;
3643 }
3644 break;
3645 }
3646 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3647 if (requireUtProvisioning) {
3648 // UT requires provisioning
3649 return true;
3650 }
3651 break;
3652 }
3653 }
3654 return false;
3655 }
3656
3657 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003658 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003659 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3660 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3661 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003662 enforceReadPrivilegedPermission("getImsProvisioningInt");
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003666 int slotId = getSlotIndex(subId);
3667 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3668 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3669 + subId + "' for key:" + key);
3670 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3671 }
3672 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003673 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003674 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3675 + subId + "' for key:" + key);
3676 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
3680 }
3681
3682 @Override
3683 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3685 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3686 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003687 enforceReadPrivilegedPermission("getImsProvisioningString");
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003691 int slotId = getSlotIndex(subId);
3692 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3693 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3694 + subId + "' for key:" + key);
3695 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3696 }
3697 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003698 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003699 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3700 + subId + "' for key:" + key);
3701 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
3705 }
3706
3707 @Override
3708 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3710 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3711 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3713 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003717 int slotId = getSlotIndex(subId);
3718 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3719 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3720 + subId + "' for key:" + key);
3721 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3722 }
3723 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003725 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3726 + "' for key:" + key);
3727 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003728 } finally {
3729 Binder.restoreCallingIdentity(identity);
3730 }
3731 }
3732
3733 @Override
3734 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003735 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3736 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3737 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3739 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003743 int slotId = getSlotIndex(subId);
3744 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3745 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3746 + subId + "' for key:" + key);
3747 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3748 }
3749 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003750 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003751 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3752 + "' for key:" + key);
3753 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
3757 }
3758
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 int slotId = SubscriptionManager.getSlotIndex(subId);
3761 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3763 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003764 }
3765 return slotId;
3766 }
3767
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003768 private int getSlotIndex(int subId) {
3769 int slotId = SubscriptionManager.getSlotIndex(subId);
3770 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3771 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3772 }
3773 return slotId;
3774 }
3775
Wink Saville36469e72014-06-11 15:17:00 -07003776 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003777 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003778 */
3779 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003780 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003781 final int targetSdk = getTargetSdk(callingPackage);
3782 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3783 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3784 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003785 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3786 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003787 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3788 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 final Phone phone = getPhone(subId);
3793 if (phone != null) {
3794 return phone.getServiceState().getDataNetworkType();
3795 } else {
3796 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3797 }
3798 } finally {
3799 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003801 }
3802
3803 /**
3804 * Returns the data network type
3805 */
3806 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003807 public int getDataNetworkType(String callingPackage) {
3808 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003809 }
3810
3811 /**
3812 * Returns the data network type for a subId
3813 */
3814 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003815 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003816 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003817 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003818 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3819 }
3820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 final Phone phone = getPhone(subId);
3824 if (phone != null) {
3825 return phone.getServiceState().getDataNetworkType();
3826 } else {
3827 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3828 }
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003832 }
3833
3834 /**
Wink Saville36469e72014-06-11 15:17:00 -07003835 * Returns the Voice network type for a subId
3836 */
3837 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003838 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003840 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003841 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3842 }
3843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 final Phone phone = getPhone(subId);
3847 if (phone != null) {
3848 return phone.getServiceState().getVoiceNetworkType();
3849 } else {
3850 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3851 }
3852 } finally {
3853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855 }
3856
3857 /**
3858 * @return true if a ICC card is present
3859 */
3860 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003861 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003862 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3863 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003864 }
3865
3866 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003867 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003868 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003869 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003870 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 final Phone phone = PhoneFactory.getPhone(slotIndex);
3874 if (phone != null) {
3875 return phone.getIccCard().hasIccCard();
3876 } else {
3877 return false;
3878 }
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003882 }
3883
3884 /**
3885 * Return if the current radio is LTE on CDMA. This
3886 * is a tri-state return value as for a period of time
3887 * the mode may be unknown.
3888 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003889 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003890 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003891 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003892 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003893 @Override
3894 public int getLteOnCdmaMode(String callingPackage) {
3895 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003896 }
3897
Sanket Padawe356d7632015-06-22 14:03:32 -07003898 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003899 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003901 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003902 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3903 }
3904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 final Phone phone = getPhone(subId);
3908 if (phone == null) {
3909 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3910 } else {
3911 return phone.getLteOnCdmaMode();
3912 }
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003915 }
Wink Saville36469e72014-06-11 15:17:00 -07003916 }
3917
Wink Saville36469e72014-06-11 15:17:00 -07003918 /**
3919 * {@hide}
3920 * Returns Default subId, 0 in the case of single standby.
3921 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003922 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003923 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003924 }
3925
Shishir Agrawala9f32182016-04-12 12:00:16 -07003926 private int getSlotForDefaultSubscription() {
3927 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3928 }
3929
Wink Savilleb564aae2014-10-23 10:18:09 -07003930 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003931 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003932 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003933
Pengquan Menge92a50d2018-09-21 15:54:48 -07003934 private boolean isActiveSubscription(int subId) {
3935 return mSubscriptionController.isActiveSubId(subId);
3936 }
3937
Ihab Awadf2177b72013-11-25 13:33:23 -08003938 /**
3939 * @see android.telephony.TelephonyManager.WifiCallingChoices
3940 */
3941 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003944 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3946 getWhenToMakeWifiCallsDefaultPreference());
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003950 }
3951
3952 /**
3953 * @see android.telephony.TelephonyManager.WifiCallingChoices
3954 */
3955 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003959 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003964 }
3965
Sailesh Nepald1e68152013-12-12 19:08:02 -08003966 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003967 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003968 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003969 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003970
Jordan Liu4c733742019-02-28 12:03:40 -08003971 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3972 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3973 if (phoneId == -1) {
3974 throw new IllegalArgumentException("Given slot index: " + slotIndex
3975 + " does not correspond to an active phone");
3976 }
3977 return PhoneFactory.getPhone(phoneId);
3978 }
3979
Shishir Agrawal566b7612013-10-28 14:41:00 -07003980 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003981 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3982 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3984 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003986 if (DBG) {
3987 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3988 }
3989 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3990 p2);
3991 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003992
Jordan Liu4c733742019-02-28 12:03:40 -08003993
3994 @Override
3995 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3996 int slotIndex, String callingPackage, String aid, int p2) {
3997 enforceModifyPermission();
3998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3999 if (DBG) {
4000 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4001 }
4002 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4003 callingPackage, aid, p2);
4004 }
4005
4006 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4007 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 if (TextUtils.equals(ISDR_AID, aid)) {
4011 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004012 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4013 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 if (bestComponent == null
4015 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4016 loge("The calling package is not allowed to access ISD-R.");
4017 throw new SecurityException(
4018 "The calling package is not allowed to access ISD-R.");
4019 }
Derek Tan740e1672017-06-27 14:56:27 -07004020 }
Derek Tan740e1672017-06-27 14:56:27 -07004021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004023 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4024 null /* workSource */);
4025 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004026 return response;
4027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004030 }
4031
4032 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004033 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4035 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004036 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4037 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4038 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004039
Jordan Liu4c733742019-02-28 12:03:40 -08004040 @Override
4041 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4042 enforceModifyPermission();
4043 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4044 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4045 channel);
4046 }
4047
4048 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 final long identity = Binder.clearCallingIdentity();
4050 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051 if (channel < 0) {
4052 return false;
4053 }
Jordan Liu4c733742019-02-28 12:03:40 -08004054 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4055 null /* workSource */);
4056 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 return success;
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004060 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004061 }
4062
4063 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004064 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004065 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4067 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004068 if (DBG) {
4069 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4070 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4071 + p3 + " data=" + data);
4072 }
4073 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4074 command, p1, p2, p3, data);
4075 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004076
Jordan Liu4c733742019-02-28 12:03:40 -08004077 @Override
4078 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4079 int command, int p1, int p2, int p3, String data) {
4080 enforceModifyPermission();
4081 if (DBG) {
4082 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4083 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4084 + p3 + " data=" + data);
4085 }
4086 return iccTransmitApduLogicalChannelWithPermission(
4087 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4088 data);
4089 }
4090
4091 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4092 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004095 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 return "";
4097 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004100 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4101 null /* workSource */);
4102 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 // Append the returned status code to the end of the response payload.
4105 String s = Integer.toHexString(
4106 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4107 if (response.payload != null) {
4108 s = IccUtils.bytesToHexString(response.payload) + s;
4109 }
4110 return s;
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004113 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004114 }
Jake Hambye994d462014-02-03 13:10:13 -08004115
Evan Charltonc66da362014-05-16 14:06:40 -07004116 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004117 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4118 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4120 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004122 if (DBG) {
4123 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4124 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4125 }
4126 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4127 cla, command, p1, p2, p3, data);
4128 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004129
Jordan Liu4c733742019-02-28 12:03:40 -08004130 @Override
4131 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4132 int command, int p1, int p2, int p3, String data) {
4133 enforceModifyPermission();
4134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4135 if (DBG) {
4136 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4137 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4138 + " data=" + data);
4139 }
4140
4141 return iccTransmitApduBasicChannelWithPermission(
4142 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4143 p2, p3, data);
4144 }
4145
4146 // open APDU basic channel assuming the caller has sufficient permissions
4147 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4148 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4152 && TextUtils.equals(ISDR_AID, data)) {
4153 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004154 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4155 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156 if (bestComponent == null
4157 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4158 loge("The calling package is not allowed to select ISD-R.");
4159 throw new SecurityException(
4160 "The calling package is not allowed to select ISD-R.");
4161 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004162 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004165 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4166 null /* workSource */);
4167 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 // Append the returned status code to the end of the response payload.
4170 String s = Integer.toHexString(
4171 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4172 if (response.payload != null) {
4173 s = IccUtils.bytesToHexString(response.payload) + s;
4174 }
4175 return s;
4176 } finally {
4177 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004178 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004179 }
4180
4181 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004182 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004183 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4185 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 if (DBG) {
4190 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4191 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4192 }
4193
4194 IccIoResult response =
4195 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4196 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4197 subId);
4198
4199 if (DBG) {
4200 log("Exchange SIM_IO [R]" + response);
4201 }
4202
4203 byte[] result = null;
4204 int length = 2;
4205 if (response.payload != null) {
4206 length = 2 + response.payload.length;
4207 result = new byte[length];
4208 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4209 } else {
4210 result = new byte[length];
4211 }
4212
4213 result[length - 1] = (byte) response.sw2;
4214 result[length - 2] = (byte) response.sw1;
4215 return result;
4216 } finally {
4217 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004218 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004219 }
4220
Nathan Haroldb3014052017-01-25 15:57:32 -08004221 /**
4222 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4223 * on a particular subscription
4224 */
sqianb6e41952018-03-12 14:54:01 -07004225 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4227 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4228 return null;
4229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230
4231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 if (appType != TelephonyManager.APPTYPE_USIM
4234 && appType != TelephonyManager.APPTYPE_SIM) {
4235 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4236 return null;
4237 }
4238 Object response = sendRequest(
4239 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4240 if (response instanceof String[]) {
4241 return (String[]) response;
4242 }
yincheng zhaod698b842019-09-06 17:06:54 -07004243 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004245 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 } finally {
4247 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004248 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004249 }
4250
yincheng zhaod698b842019-09-06 17:06:54 -07004251 /**
4252 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4253 * subscription.
4254 *
4255 * @param subId the id of the subscription.
4256 * @param appType the uicc app type, must be USIM or SIM.
4257 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4258 * @param callingPackage the op Package name.
4259 * @return number of fplmns that is successfully written to the SIM.
4260 */
4261 public int setForbiddenPlmns(
4262 int subId, int appType, List<String> fplmns, String callingPackage) {
4263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4264 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4265 if (DBG) logv("no permissions for setForbiddenplmns");
4266 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4267 }
4268 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4269 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4270 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4271 }
4272 if (fplmns == null) {
4273 throw new IllegalArgumentException("Fplmn List provided is null");
4274 }
4275 for (String fplmn : fplmns) {
4276 if (!CellIdentity.isValidPlmn(fplmn)) {
4277 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4278 }
4279 }
4280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 Object response = sendRequest(
4283 CMD_SET_FORBIDDEN_PLMNS,
4284 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4285 subId);
4286 return (int) response;
4287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
4290 }
4291
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004293 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4295 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 final long identity = Binder.clearCallingIdentity();
4298 try {
4299 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4300 if (response.payload == null) {
4301 return "";
4302 }
Evan Charltonc66da362014-05-16 14:06:40 -07004303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 // Append the returned status code to the end of the response payload.
4305 String s = Integer.toHexString(
4306 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4307 s = IccUtils.bytesToHexString(response.payload) + s;
4308 return s;
4309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
Evan Charltonc66da362014-05-16 14:06:40 -07004312 }
4313
Jake Hambye994d462014-02-03 13:10:13 -08004314 /**
4315 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4316 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4317 *
4318 * @param itemID the ID of the item to read
4319 * @return the NV item as a String, or null on error.
4320 */
4321 @Override
4322 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004323 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4325 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004330 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4332 return value;
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
Jake Hambye994d462014-02-03 13:10:13 -08004336 }
4337
4338 /**
4339 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4340 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4341 *
4342 * @param itemID the ID of the item to read
4343 * @param itemValue the value to write, as a String
4344 * @return true on success; false on any failure
4345 */
4346 @Override
4347 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4350 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351
4352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4355 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004356 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4358 return success;
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
Jake Hambye994d462014-02-03 13:10:13 -08004362 }
4363
4364 /**
4365 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4366 * Used for device configuration by some CDMA operators.
4367 *
4368 * @param preferredRoamingList byte array containing the new PRL
4369 * @return true on success; false on any failure
4370 */
4371 @Override
4372 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4374 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375
4376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4379 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4380 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4381 return success;
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
Jake Hambye994d462014-02-03 13:10:13 -08004385 }
4386
4387 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004388 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004389 * Used for device configuration by some CDMA operators.
4390 *
chen xu6dac5ab2018-10-26 17:39:23 -07004391 * @param slotIndex - device slot.
4392 *
Jake Hambye994d462014-02-03 13:10:13 -08004393 * @return true on success; false on any failure
4394 */
4395 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004396 public boolean resetModemConfig(int slotIndex) {
4397 Phone phone = PhoneFactory.getPhone(slotIndex);
4398 if (phone != null) {
4399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4400 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401
chen xu6dac5ab2018-10-26 17:39:23 -07004402 final long identity = Binder.clearCallingIdentity();
4403 try {
4404 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4405 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4406 return success;
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 }
chen xu6dac5ab2018-10-26 17:39:23 -07004411 return false;
4412 }
4413
4414 /**
4415 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4416 *
4417 * @param slotIndex - device slot.
4418 *
4419 * @return true on success; false on any failure
4420 */
4421 @Override
4422 public boolean rebootModem(int slotIndex) {
4423 Phone phone = PhoneFactory.getPhone(slotIndex);
4424 if (phone != null) {
4425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, phone.getSubId(), "rebootModem");
4427
4428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4431 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4432 return success;
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
4436 }
4437 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004438 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004439
Svet Ganovb320e182015-04-16 12:30:10 -07004440 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004441 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004443 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004444 return new String[0];
4445 }
4446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 final long identity = Binder.clearCallingIdentity();
4448 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004449 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
Wink Saville36469e72014-06-11 15:17:00 -07004453 }
4454
Brad Ebinger51f743a2017-01-23 13:50:20 -08004455 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004456 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4457 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004458 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004459 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004460 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004464 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004465 // may happen if the device does not support IMS.
4466 return;
4467 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004468 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004472 }
4473
4474 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004475 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4476 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004477 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004478 public void disableIms(int slotId) {
4479 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480
4481 final long identity = Binder.clearCallingIdentity();
4482 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004483 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004484 // may happen if the device does not support IMS.
4485 return;
4486 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004487 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004491 }
4492
4493 /**
4494 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4495 * feature or {@link null} if the service is not available. If the feature is available, the
4496 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4497 */
4498 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004499 IImsServiceFeatureCallback callback) {
4500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501
4502 final long identity = Binder.clearCallingIdentity();
4503 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004504 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004505 // may happen if the device does not support IMS.
4506 return null;
4507 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004508 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004512 }
4513
4514 /**
4515 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4516 * feature during emergency calling or {@link null} if the service is not available. If the
4517 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4518 * listener for feature updates.
4519 */
4520 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522
4523 final long identity = Binder.clearCallingIdentity();
4524 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004525 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004526 // may happen if the device does not support IMS.
4527 return null;
4528 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004529 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004533 }
4534
Brad Ebinger5f64b052017-12-14 14:26:15 -08004535 /**
4536 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004537 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004538 */
4539 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541
4542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004544 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004545 // may happen if the device does not support IMS.
4546 return null;
4547 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004548 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004552 }
4553
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004554 /**
4555 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004556 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004557 */
4558 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560
4561 final long identity = Binder.clearCallingIdentity();
4562 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004563 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004564 // may happen if the device does not support IMS.
4565 return null;
4566 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004567 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 } finally {
4569 Binder.restoreCallingIdentity(identity);
4570 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004571 }
4572
Brad Ebinger884c07b2018-02-15 16:17:40 -08004573 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004574 * Sets the ImsService Package Name that Telephony will bind to.
4575 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004576 * @param slotIndex the slot ID that the ImsService should bind for.
4577 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004578 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004579 * @param featureTypes An integer array of feature types associated with a packageName.
4580 * @param packageName The name of the package that the current configuration will be replaced
4581 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004582 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004583 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004584 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4585 int[] featureTypes, String packageName) {
4586 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4587 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4589 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004590 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004594 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004595 // may happen if the device does not support IMS.
4596 return false;
4597 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004598 Map<Integer, String> featureConfig = new HashMap<>();
4599 for (int featureType : featureTypes) {
4600 featureConfig.put(featureType, packageName);
4601 }
4602 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4603 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604 } finally {
4605 Binder.restoreCallingIdentity(identity);
4606 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004607 }
4608
4609 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004610 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004611 *
4612 * @param slotId The slot that the ImsService is associated with.
4613 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4614 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004615 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004616 * @return the package name of the ImsService configuration.
4617 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004618 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4619 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004620 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004621 TelephonyPermissions
4622 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4623 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4624 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 final long identity = Binder.clearCallingIdentity();
4627 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004628 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004629 // may happen if the device does not support IMS.
4630 return "";
4631 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004632 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004633 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4634 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004638 }
4639
Brad Ebinger77b832e2019-10-17 17:03:22 -07004640 /**
4641 * Get the MmTelFeature state associated with the requested subscription id.
4642 * @param subId The subscription that the MmTelFeature is associated with.
4643 * @param callback A callback with an integer containing the
4644 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4645 */
4646 @Override
4647 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4648 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4649 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4650 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4651 "IMS not available on device.");
4652 }
4653 final long token = Binder.clearCallingIdentity();
4654 try {
4655 int slotId = getSlotIndex(subId);
4656 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4657 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4658 + subId + "'");
4659 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4660 }
4661 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4662 try {
4663 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4664 } catch (RemoteException e) {
4665 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4666 + "Ignore");
4667 }
4668 });
4669 } finally {
4670 Binder.restoreCallingIdentity(token);
4671 }
4672 }
4673
Wink Saville36469e72014-06-11 15:17:00 -07004674 public void setImsRegistrationState(boolean registered) {
4675 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004676
4677 final long identity = Binder.clearCallingIdentity();
4678 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004679 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
Wink Saville36469e72014-06-11 15:17:00 -07004683 }
4684
4685 /**
Stuart Scott54788802015-03-30 13:18:01 -07004686 * Set the network selection mode to automatic.
4687 *
4688 */
4689 @Override
4690 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4692 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693
Pengquan Menge92a50d2018-09-21 15:54:48 -07004694 if (!isActiveSubscription(subId)) {
4695 return;
4696 }
4697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4701 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
Stuart Scott54788802015-03-30 13:18:01 -07004705 }
4706
Pengquan Mengea84e042018-09-20 14:57:26 -07004707 /**
4708 * Ask the radio to connect to the input network and change selection mode to manual.
4709 *
4710 * @param subId the id of the subscription.
4711 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4712 * the operator to attach to.
4713 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4714 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4715 * normal network selection next time.
4716 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004717 */
4718 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004719 public boolean setNetworkSelectionModeManual(
4720 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4722 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004723
4724 if (!isActiveSubscription(subId)) {
4725 return false;
4726 }
4727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 final long identity = Binder.clearCallingIdentity();
4729 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004730 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004732 if (DBG) {
4733 log("setNetworkSelectionModeManual: subId: " + subId
4734 + " operator: " + operatorInfo);
4735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004740 }
4741
4742 /**
4743 * Scans for available networks.
4744 */
4745 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004746 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4748 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004749 LocationAccessPolicy.LocationPermissionResult locationResult =
4750 LocationAccessPolicy.checkLocationPermission(mApp,
4751 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4752 .setCallingPackage(callingPackage)
4753 .setCallingPid(Binder.getCallingPid())
4754 .setCallingUid(Binder.getCallingUid())
4755 .setMethod("getCellNetworkScanResults")
4756 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4757 .build());
4758 switch (locationResult) {
4759 case DENIED_HARD:
4760 throw new SecurityException("Not allowed to access scan results -- location");
4761 case DENIED_SOFT:
4762 return null;
4763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764
Pengquan Menga1bb6272018-09-06 09:59:22 -07004765 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 try {
4767 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004768 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
4772 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004773 }
4774
4775 /**
yinxub1bed742017-04-17 11:45:04 -07004776 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004777 *
yinxub1bed742017-04-17 11:45:04 -07004778 * @param subId id of the subscription
4779 * @param request contains the radio access networks with bands/channels to scan
4780 * @param messenger callback messenger for scan results or errors
4781 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004782 * @return the id of the requested scan which can be used to stop the scan.
4783 */
4784 @Override
4785 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004786 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4788 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004789 LocationAccessPolicy.LocationPermissionResult locationResult =
4790 LocationAccessPolicy.checkLocationPermission(mApp,
4791 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4792 .setCallingPackage(callingPackage)
4793 .setCallingPid(Binder.getCallingPid())
4794 .setCallingUid(Binder.getCallingUid())
4795 .setMethod("requestNetworkScan")
4796 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4797 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004798 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004799 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004800 if (e != null) {
4801 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4802 throw e;
4803 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004804 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004805 return TelephonyScanManager.INVALID_SCAN_ID;
4806 }
4807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004808 }
Hall Liu912dfd32019-04-25 14:02:26 -07004809 int callingUid = Binder.getCallingUid();
4810 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004811 final long identity = Binder.clearCallingIdentity();
4812 try {
4813 return mNetworkScanRequestTracker.startNetworkScan(
4814 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004815 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
yinxu504e1392017-04-12 16:03:22 -07004819 }
4820
Hall Liub2ac8ef2019-02-28 15:56:23 -08004821 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004822 NetworkScanRequest request, int subId) {
4823 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4824 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4825 boolean hasNetworkScanPermission =
4826 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4827 == PERMISSION_GRANTED;
4828
4829 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4830 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4831 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004832 }
4833
4834 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4835 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004836 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4837 return new SecurityException("Specific channels must not be"
4838 + " scanned without location access.");
4839 }
4840 }
4841 }
4842
Hall Liub2ac8ef2019-02-28 15:56:23 -08004843 return null;
4844 }
4845
yinxu504e1392017-04-12 16:03:22 -07004846 /**
4847 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004848 *
4849 * @param subId id of the subscription
4850 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004851 */
4852 @Override
4853 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4855 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856
Hall Liu912dfd32019-04-25 14:02:26 -07004857 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 final long identity = Binder.clearCallingIdentity();
4859 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004860 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
yinxu504e1392017-04-12 16:03:22 -07004864 }
4865
4866 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004867 * Get the calculated preferred network type.
4868 * Used for debugging incorrect network type.
4869 *
4870 * @return the preferred network type, defined in RILConstants.java.
4871 */
4872 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004873 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004874 final Phone defaultPhone = getDefaultPhone();
4875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4876 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004877 return RILConstants.PREFERRED_NETWORK_MODE;
4878 }
4879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004883 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
Junda Liu84d15a22014-07-02 11:21:04 -07004887 }
4888
4889 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004890 * Get the preferred network type.
4891 * Used for device configuration by some CDMA operators.
4892 *
4893 * @return the preferred network type, defined in RILConstants.java.
4894 */
4895 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004896 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004897 TelephonyPermissions
4898 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4899 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900
4901 final long identity = Binder.clearCallingIdentity();
4902 try {
4903 if (DBG) log("getPreferredNetworkType");
4904 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4905 int networkType = (result != null ? result[0] : -1);
4906 if (DBG) log("getPreferredNetworkType: " + networkType);
4907 return networkType;
4908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004911 }
4912
4913 /**
4914 * Set the preferred network type.
4915 * Used for device configuration by some CDMA operators.
4916 *
4917 * @param networkType the preferred network type, defined in RILConstants.java.
4918 * @return true on success; false on any failure.
4919 */
4920 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004921 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4923 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924
4925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4928 Boolean success = (Boolean) sendRequest(
4929 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4930 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4931 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004932 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4934 }
4935 return success;
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004938 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004939 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004940
4941 /**
Miaoa84611c2019-03-15 09:21:10 +08004942 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004943 *
Miaoa84611c2019-03-15 09:21:10 +08004944 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004945 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004946 * @hide
4947 */
4948 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004949 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004950 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004952 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 try {
Miaoa84611c2019-03-15 09:21:10 +08004954 if (phone != null) {
4955 return phone.hasMatchedTetherApnSetting();
4956 } else {
4957 return false;
4958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004961 }
Junda Liu475951f2014-11-07 16:45:03 -08004962 }
4963
4964 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004965 * Set mobile data enabled
4966 * Used by the user through settings etc to turn on/off mobile data
4967 *
4968 * @param enable {@code true} turn turn data on, else {@code false}
4969 */
4970 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004971 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4973 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 final long identity = Binder.clearCallingIdentity();
4976 try {
4977 int phoneId = mSubscriptionController.getPhoneId(subId);
4978 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4979 Phone phone = PhoneFactory.getPhone(phoneId);
4980 if (phone != null) {
4981 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004982 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004984 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 }
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004988 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004989 }
4990
4991 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004992 * Get the user enabled state of Mobile Data.
4993 *
4994 * TODO: remove and use isUserDataEnabled.
4995 * This can't be removed now because some vendor codes
4996 * calls through ITelephony directly while they should
4997 * use TelephonyManager.
4998 *
4999 * @return true on enabled
5000 */
5001 @Override
5002 public boolean getDataEnabled(int subId) {
5003 return isUserDataEnabled(subId);
5004 }
5005
5006 /**
5007 * Get whether mobile data is enabled per user setting.
5008 *
5009 * There are other factors deciding whether mobile data is actually enabled, but they are
5010 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005011 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005012 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005013 *
5014 * @return {@code true} if data is enabled else {@code false}
5015 */
5016 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005017 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005018 try {
5019 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5020 null);
5021 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5023 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 int phoneId = mSubscriptionController.getPhoneId(subId);
5029 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5030 Phone phone = PhoneFactory.getPhone(phoneId);
5031 if (phone != null) {
5032 boolean retVal = phone.isUserDataEnabled();
5033 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5034 return retVal;
5035 } else {
5036 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5037 return false;
5038 }
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005041 }
5042 }
5043
5044 /**
5045 * Get whether mobile data is enabled.
5046 *
5047 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5048 * whether mobile data is actually enabled.
5049 *
5050 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5051 *
5052 * @return {@code true} if data is enabled else {@code false}
5053 */
5054 @Override
5055 public boolean isDataEnabled(int subId) {
5056 try {
5057 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5058 null);
5059 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5061 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063
5064 final long identity = Binder.clearCallingIdentity();
5065 try {
5066 int phoneId = mSubscriptionController.getPhoneId(subId);
5067 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5068 Phone phone = PhoneFactory.getPhone(phoneId);
5069 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005070 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5072 return retVal;
5073 } else {
5074 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5075 return false;
5076 }
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005079 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005080 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005081
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005082 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5083 Phone phone) {
5084 //load access rules from carrier configs, and check those as well: b/139133814
5085 SubscriptionController subController = SubscriptionController.getInstance();
5086 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5087 || subController == null) return privilegeFromSim;
5088
5089 int uid = Binder.getCallingUid();
5090 PackageManager pkgMgr = phone.getContext().getPackageManager();
5091 String[] packages = pkgMgr.getPackagesForUid(uid);
5092
5093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5096 SubscriptionManager subManager = (SubscriptionManager)
5097 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5098 for (String pkg : packages) {
5099 if (subManager.canManageSubscription(subInfo, pkg)) {
5100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5101 }
5102 }
5103 return privilegeFromSim;
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
5107 }
5108
5109 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5110 String pkgName) {
5111 //load access rules from carrier configs, and check those as well: b/139133814
5112 SubscriptionController subController = SubscriptionController.getInstance();
5113 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5114 || subController == null) return privilegeFromSim;
5115
5116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5119 SubscriptionManager subManager = (SubscriptionManager)
5120 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5121 return subManager.canManageSubscription(subInfo, pkgName)
5122 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
5126 }
5127
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005128 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005129 public int getCarrierPrivilegeStatus(int subId) {
5130 final Phone phone = getPhone(subId);
5131 if (phone == null) {
5132 loge("getCarrierPrivilegeStatus: Invalid subId");
5133 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5134 }
5135 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005136 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005137 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005138 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5139 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005140
5141 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5142 card.getCarrierPrivilegeStatusForCurrentTransaction(
5143 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005144 }
Junda Liu29340342014-07-10 15:23:27 -07005145
5146 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005147 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5148 final Phone phone = getPhone(subId);
5149 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005150 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5152 }
5153 UiccProfile profile =
5154 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5155 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005156 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005157 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5158 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005159 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5160 profile.getCarrierPrivilegeStatusForUid(
5161 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005162 }
5163
5164 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005165 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5166 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005167 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005168 }
5169
5170 int phoneId = SubscriptionManager.getPhoneId(subId);
5171 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005172 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005173 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5175 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005176 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5177 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5178 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005179 }
5180
5181 @Override
5182 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005183 if (TextUtils.isEmpty(pkgName))
5184 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005185 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5186 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5187 UiccCard card = UiccController.getInstance().getUiccCard(i);
5188 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005189 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005190 continue;
5191 }
5192
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005193 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5194 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5195 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005196 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5197 break;
5198 }
5199 }
5200
5201 return result;
Junda Liu29340342014-07-10 15:23:27 -07005202 }
Derek Tan89e89d42014-07-08 17:00:10 -07005203
5204 @Override
Junda Liue64de782015-04-16 17:19:16 -07005205 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5206 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5207 loge("phoneId " + phoneId + " is not valid.");
5208 return null;
5209 }
5210 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005211 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005212 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005213 return null ;
5214 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005215 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005216 }
5217
Amith Yamasani6e118872016-02-19 12:53:51 -08005218 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005219 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005220 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005221 List<String> privilegedPackages = new ArrayList<>();
5222 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005223 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5224 // has UICC in that slot.
5225 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005226 if (card.hasCarrierPrivilegeRules()) {
5227 if (packages == null) {
5228 // Only check packages in user 0 for now
5229 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005230 PackageManager.MATCH_DISABLED_COMPONENTS
5231 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005232 | PackageManager.GET_SIGNING_CERTIFICATES,
5233 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005234 }
5235 for (int p = packages.size() - 1; p >= 0; p--) {
5236 PackageInfo pkgInfo = packages.get(p);
5237 if (pkgInfo != null && pkgInfo.packageName != null
5238 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005239 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005240 privilegedPackages.add(pkgInfo.packageName);
5241 }
5242 }
5243 }
5244 }
5245 return privilegedPackages;
5246 }
5247
chen xuf7e9fe82019-05-09 19:31:02 -07005248 @Override
5249 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005250 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5251
5252 final long identity = Binder.clearCallingIdentity();
5253
chen xuf7e9fe82019-05-09 19:31:02 -07005254 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005255 try {
5256 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5257 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5258 }
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005261 }
5262 return privilegedPackages;
5263 }
5264
Wink Savilleb564aae2014-10-23 10:18:09 -07005265 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005266 final Phone phone = getPhone(subId);
5267 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005268 if (card == null) {
5269 loge("getIccId: No UICC");
5270 return null;
5271 }
5272 String iccId = card.getIccId();
5273 if (TextUtils.isEmpty(iccId)) {
5274 loge("getIccId: ICC ID is null or empty.");
5275 return null;
5276 }
5277 return iccId;
5278 }
5279
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005280 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005281 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5282 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005283 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5284 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
5288 final String iccId = getIccId(subId);
5289 final Phone phone = getPhone(subId);
5290 if (phone == null) {
5291 return false;
5292 }
5293 final String subscriberId = phone.getSubscriberId();
5294
5295 if (DBG_MERGE) {
5296 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5297 + subscriberId + " to " + number);
5298 }
5299
5300 if (TextUtils.isEmpty(iccId)) {
5301 return false;
5302 }
5303
5304 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5305
5306 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5307 if (alphaTag == null) {
5308 editor.remove(alphaTagPrefKey);
5309 } else {
5310 editor.putString(alphaTagPrefKey, alphaTag);
5311 }
5312
5313 // Record both the line number and IMSI for this ICCID, since we need to
5314 // track all merged IMSIs based on line number
5315 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5316 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5317 if (number == null) {
5318 editor.remove(numberPrefKey);
5319 editor.remove(subscriberPrefKey);
5320 } else {
5321 editor.putString(numberPrefKey, number);
5322 editor.putString(subscriberPrefKey, subscriberId);
5323 }
5324
5325 editor.commit();
5326 return true;
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005329 }
Derek Tan7226c842014-07-02 17:42:23 -07005330 }
5331
5332 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005333 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005334 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005336 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005337 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005338 return null;
5339 }
Derek Tan97ebb422014-09-05 16:55:38 -07005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 String iccId = getIccId(subId);
5344 if (iccId != null) {
5345 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5346 if (DBG_MERGE) {
5347 log("getLine1NumberForDisplay returning "
5348 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5349 }
5350 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5353 return null;
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005356 }
Derek Tan7226c842014-07-02 17:42:23 -07005357 }
5358
5359 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005360 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005362 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005363 return null;
5364 }
Derek Tan97ebb422014-09-05 16:55:38 -07005365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 final long identity = Binder.clearCallingIdentity();
5367 try {
5368 String iccId = getIccId(subId);
5369 if (iccId != null) {
5370 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5371 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5372 }
5373 return null;
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005376 }
Derek Tan7226c842014-07-02 17:42:23 -07005377 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005378
5379 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005380 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005381 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5382 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005384 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5385 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005386 return null;
5387 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005388
Jordan Liub49b04b2019-05-06 14:45:15 -07005389 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5390 // the process, where TelephonyManager was instantiated.
5391 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005392 final long identity = Binder.clearCallingIdentity();
5393 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005394 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 final TelephonyManager tele = TelephonyManager.from(context);
5396 final SubscriptionManager sub = SubscriptionManager.from(context);
5397
5398 // Figure out what subscribers are currently active
5399 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400
Jordan Liub49b04b2019-05-06 14:45:15 -07005401 // Only consider subs which match the current subId
5402 // This logic can be simplified. See b/131189269 for progress.
5403 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005404 activeSubscriberIds.add(tele.getSubscriberId(subId));
5405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406
5407 // First pass, find a number override for an active subscriber
5408 String mergeNumber = null;
5409 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5410 for (String key : prefs.keySet()) {
5411 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5412 final String subscriberId = (String) prefs.get(key);
5413 if (activeSubscriberIds.contains(subscriberId)) {
5414 final String iccId = key.substring(
5415 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5416 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5417 mergeNumber = (String) prefs.get(numberKey);
5418 if (DBG_MERGE) {
5419 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5420 + " for active subscriber " + subscriberId);
5421 }
5422 if (!TextUtils.isEmpty(mergeNumber)) {
5423 break;
5424 }
5425 }
5426 }
5427 }
5428
5429 // Shortcut when no active merged subscribers
5430 if (TextUtils.isEmpty(mergeNumber)) {
5431 return null;
5432 }
5433
5434 // Second pass, find all subscribers under that line override
5435 final ArraySet<String> result = new ArraySet<>();
5436 for (String key : prefs.keySet()) {
5437 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5438 final String number = (String) prefs.get(key);
5439 if (mergeNumber.equals(number)) {
5440 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5441 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5442 final String subscriberId = (String) prefs.get(subscriberKey);
5443 if (!TextUtils.isEmpty(subscriberId)) {
5444 result.add(subscriberId);
5445 }
5446 }
5447 }
5448 }
5449
5450 final String[] resultArray = result.toArray(new String[result.size()]);
5451 Arrays.sort(resultArray);
5452 if (DBG_MERGE) {
5453 Slog.d(LOG_TAG,
5454 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5455 }
5456 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005459 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005460 }
5461
5462 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005463 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5464 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 final TelephonyManager telephonyManager = mApp.getSystemService(
5469 TelephonyManager.class);
5470 String subscriberId = telephonyManager.getSubscriberId(subId);
5471 if (subscriberId == null) {
5472 if (DBG) {
5473 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5474 + subId);
5475 }
5476 return null;
5477 }
5478
5479 final SubscriptionInfo info = SubscriptionController.getInstance()
5480 .getSubscriptionInfo(subId);
5481 final ParcelUuid groupUuid = info.getGroupUuid();
5482 // If it doesn't belong to any group, return just subscriberId of itself.
5483 if (groupUuid == null) {
5484 return new String[]{subscriberId};
5485 }
5486
5487 // Get all subscriberIds from the group.
5488 final List<String> mergedSubscriberIds = new ArrayList<>();
5489 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5490 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5491 for (SubscriptionInfo subInfo : groupInfos) {
5492 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5493 if (subscriberId != null) {
5494 mergedSubscriberIds.add(subscriberId);
5495 }
5496 }
5497
5498 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501
5502 }
5503 }
5504
5505 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005506 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005507 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5508 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509
5510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 final Phone phone = getPhone(subId);
5513 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005517 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005518
5519 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005520 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005521 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5522 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005523 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524
5525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 final Phone phone = getPhone(subId);
5528 if (phone == null) {
5529 return false;
5530 }
5531 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5532 cdmaNonRoamingList);
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005535 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005536 }
5537
5538 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005539 @Deprecated
5540 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5541 enforceModifyPermission();
5542
5543 int returnValue = 0;
5544 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005545 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005546 if(result.exception == null) {
5547 if (result.result != null) {
5548 byte[] responseData = (byte[])(result.result);
5549 if(responseData.length > oemResp.length) {
5550 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5551 responseData.length + "bytes. Buffer Size is " +
5552 oemResp.length + "bytes.");
5553 }
5554 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5555 returnValue = responseData.length;
5556 }
5557 } else {
5558 CommandException ex = (CommandException) result.exception;
5559 returnValue = ex.getCommandError().ordinal();
5560 if(returnValue > 0) returnValue *= -1;
5561 }
5562 } catch (RuntimeException e) {
5563 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5564 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5565 if(returnValue > 0) returnValue *= -1;
5566 }
5567
5568 return returnValue;
5569 }
5570
5571 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005572 public void setRadioCapability(RadioAccessFamily[] rafs) {
5573 try {
5574 ProxyController.getInstance().setRadioCapability(rafs);
5575 } catch (RuntimeException e) {
5576 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5577 }
5578 }
5579
5580 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005581 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005582 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005583 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005584 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005585 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 final long identity = Binder.clearCallingIdentity();
5588 try {
chen xub97461a2018-10-26 14:17:57 -07005589 TelephonyPermissions
5590 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5591 mApp, phone.getSubId(), "getRadioAccessFamily");
5592 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
chen xub97461a2018-10-26 14:17:57 -07005596 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005597 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005598
5599 @Override
5600 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005601 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005602 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005606 ImsManager.getInstance(defaultPhone.getContext(),
5607 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005611 }
5612
5613 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005614 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005615 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005617 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005618 return false;
5619 }
Svet Ganovb320e182015-04-16 12:30:10 -07005620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 // Check the user preference and the system-level IMS setting. Even if the user has
5624 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5625 // In the long run, we may instead need to check if there exists a connection service
5626 // which can support video calling.
5627 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005628 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 return imsManager.isVtEnabledByPlatform()
5630 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5631 && imsManager.isVtEnabledByUser();
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005635 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005636
Andrew Leea1239f22015-03-02 17:44:07 -08005637 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5640 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5641 return false;
5642 }
5643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 CarrierConfigManager configManager =
5647 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005648 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Andrew Leea1239f22015-03-02 17:44:07 -08005653 }
5654
5655 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 public boolean isWorldPhone(int subId, String callingPackage) {
5657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5658 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5659 return false;
5660 }
5661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 CarrierConfigManager configManager =
5665 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005666 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Andrew Leea1239f22015-03-02 17:44:07 -08005671 }
5672
Andrew Lee9431b832015-03-09 18:46:45 -07005673 @Override
5674 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005675 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005676 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005677 }
5678
5679 @Override
5680 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 final long identity = Binder.clearCallingIdentity();
5682 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005683 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
Andrew Lee9431b832015-03-09 18:46:45 -07005687 }
5688
Hall Liuf6668912018-10-31 17:05:23 -07005689 /**
5690 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5691 * support for the feature and device firmware support.
5692 *
5693 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5694 */
5695 @Override
5696 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005698 final Phone phone = getPhone(subscriptionId);
5699 if (phone == null) {
5700 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5701 return false;
5702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005704 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5706 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005707 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 return isCarrierSupported && isDeviceSupported;
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Hall Liu98187582018-01-22 19:15:32 -08005712 }
5713
Hall Liuf6668912018-10-31 17:05:23 -07005714 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005715 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5716 * RTT setting, will return true if the device and carrier both support RTT.
5717 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005718 */
5719 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 final long identity = Binder.clearCallingIdentity();
5721 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005722 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005726 }
5727
Sanket Padawe7310cc72015-01-14 09:53:20 -08005728 /**
5729 * Returns the unique device ID of phone, for example, the IMEI for
5730 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5731 *
5732 * <p>Requires Permission:
5733 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5734 */
5735 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005736 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005737 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005738 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005739 return null;
5740 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005741 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005742 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5743 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005744 return null;
5745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 return phone.getDeviceId();
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005753 }
5754
Ping Sunc67b7c22016-03-02 19:16:45 +08005755 /**
5756 * {@hide}
5757 * Returns the IMS Registration Status on a particular subid
5758 *
5759 * @param subId
5760 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005761 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005762 Phone phone = getPhone(subId);
5763 if (phone != null) {
5764 return phone.isImsRegistered();
5765 } else {
5766 return false;
5767 }
5768 }
5769
Santos Cordon7a1885b2015-02-03 11:15:19 -08005770 @Override
5771 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005778 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005779
Tyler Gunnf70ed162019-04-03 15:28:53 -07005780 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005781 public int getSubIdForPhoneAccountHandle(
5782 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5784 callingPackage, "getSubIdForPhoneAccountHandle")) {
5785 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5786 }
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
5793 }
5794
5795 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005796 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 Phone phone = getPhone(subscriptionId);
5800 if (phone == null) {
5801 return null;
5802 }
5803 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
5807 }
5808
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005809 /**
5810 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005811 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005812 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 final long identity = Binder.clearCallingIdentity();
5814 try {
5815 Phone phone = getPhone(subId);
5816 if (phone != null) {
5817 return phone.isWifiCallingEnabled();
5818 } else {
5819 return false;
5820 }
5821 } finally {
5822 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005823 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005824 }
5825
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005826 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005827 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005828 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005829 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 Phone phone = getPhone(subId);
5833 if (phone != null) {
5834 return phone.isVideoEnabled();
5835 } else {
5836 return false;
5837 }
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005840 }
5841 }
5842
5843 /**
5844 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5845 * defined in {@link ImsRegistrationImplBase}.
5846 */
5847 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 Phone phone = getPhone(subId);
5851 if (phone != null) {
5852 return phone.getImsRegistrationTech();
5853 } else {
5854 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5855 }
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005858 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005859 }
5860
Stuart Scott8eef64f2015-04-08 15:13:54 -07005861 @Override
5862 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005863 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005864 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5865 return;
5866 }
5867
Svet Ganovcc087f82015-05-12 20:35:54 -07005868 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005869
Svet Ganovcc087f82015-05-12 20:35:54 -07005870 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005871 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5872 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005873 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005874 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005875 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005876 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5877 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005878 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005879 // There has been issues when Sms raw table somehow stores orphan
5880 // fragments. They lead to garbled message when new fragments come
5881 // in and combined with those stale ones. In case this happens again,
5882 // user can reset all network settings which will clean up this table.
5883 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005884 // Clean up IMS settings as well here.
5885 int slotId = getSlotIndex(subId);
5886 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5887 ImsManager.getInstance(mApp, slotId).factoryReset();
5888 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005889
5890 // Erase modem config if erase modem on network setting is enabled.
5891 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5892 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5893 if (configValue != null && Boolean.parseBoolean(configValue)) {
5894 sendEraseModemConfig(getDefaultPhone());
5895 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005896 } finally {
5897 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005898 }
5899 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005900
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005901 private void cleanUpSmsRawTable(Context context) {
5902 ContentResolver resolver = context.getContentResolver();
5903 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5904 resolver.delete(uri, null, null);
5905 }
5906
Narayan Kamath1c496c22015-04-16 14:40:19 +01005907 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005908 public String getSimLocaleForSubscriber(int subId) {
5909 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5910 final Phone phone = getPhone(subId);
5911 if (phone == null) {
5912 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005913 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 final long identity = Binder.clearCallingIdentity();
5916 try {
chen xu5d3637b2019-01-21 23:31:38 -08005917 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5918 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005919 if (info == null) {
5920 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5921 return null;
5922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 // Try and fetch the locale from the carrier properties or from the SIM language
5924 // preferences (EF-PL and EF-LI)...
5925 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005927 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5928 if (localeFromDefaultSim != null) {
5929 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5930 if (DBG) log("Using locale from subId: " + subId + " locale: "
5931 + localeFromDefaultSim);
5932 return localeFromDefaultSim.toLanguageTag();
5933 } else {
5934 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 }
5936 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 // The SIM language preferences only store a language (e.g. fr = French), not an
5939 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5940 // the SIM and carrier preferences does not include a country we add the country
5941 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08005942 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005944 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 return mccLocale.toLanguageTag();
5946 }
5947
5948 if (DBG) log("No locale found - returning null");
5949 return null;
5950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005953 }
5954
5955 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005956 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005957 }
5958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 /**
5960 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5961 */
5962 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005963 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005964 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005965
Chenjie Yu1ba97252018-01-11 18:16:20 -08005966 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07005967 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005968
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005969 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005970 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5971 * representing the state of the modem.
5972 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005973 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5974 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005975 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005976 */
5977 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005978 public void requestModemActivityInfo(ResultReceiver result) {
5979 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005980 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981
5982 final long identity = Binder.clearCallingIdentity();
5983 try {
5984 ModemActivityInfo ret = null;
5985 synchronized (mLastModemActivityInfo) {
5986 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5987 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005988 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005989 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07005991 int[] txTimeMs = info.getTransmitTimeMillis();
5992 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07005994 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 }
5996 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005997 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5998 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 mLastModemActivityInfo.setIdleTimeMillis(
6000 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006001 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6002 mLastModemActivityInfo.setReceiveTimeMillis(
6003 info.getReceiveTimeMillis() + mLastModemActivityInfo
6004 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006005 }
Chen Xu13851032019-09-10 18:49:52 -07006006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6008 mLastModemActivityInfo.getSleepTimeMillis(),
6009 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006010 mLastModemActivityInfo.getTransmitTimeMillis(),
6011 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 Bundle bundle = new Bundle();
6014 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6015 result.send(0, bundle);
6016 } finally {
6017 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006018 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006019 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006020
Siddharth Rayb8114062018-06-17 15:02:38 -07006021 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6022 // less than total activity duration.
6023 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6024 if (info == null) {
6025 return false;
6026 }
6027 int activityDurationMs =
6028 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6029 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006030 int[] txTimeMs = info.getTransmitTimeMillis();
6031 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6032 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006033 }
6034 return (info.isValid()
6035 && (info.getSleepTimeMillis() <= activityDurationMs)
6036 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006037 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006038 && (totalTxTimeMs <= activityDurationMs));
6039 }
6040
Jack Yu85bd38a2015-11-09 11:34:32 -08006041 /**
6042 * {@hide}
6043 * Returns the service state information on specified subscription.
6044 */
6045 @Override
6046 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006048 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006049 return null;
6050 }
6051
Hall Liuf19c44f2018-11-27 14:38:17 -08006052 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6053 LocationAccessPolicy.checkLocationPermission(mApp,
6054 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6055 .setCallingPackage(callingPackage)
6056 .setCallingPid(Binder.getCallingPid())
6057 .setCallingUid(Binder.getCallingUid())
6058 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006059 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006060 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6061 .build());
6062
6063 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6064 LocationAccessPolicy.checkLocationPermission(mApp,
6065 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6066 .setCallingPackage(callingPackage)
6067 .setCallingPid(Binder.getCallingPid())
6068 .setCallingUid(Binder.getCallingUid())
6069 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006070 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006071 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6072 .build());
6073 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6074 boolean hasFinePermission =
6075 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6076 boolean hasCoarsePermission =
6077 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 final long identity = Binder.clearCallingIdentity();
6080 try {
6081 final Phone phone = getPhone(subId);
6082 if (phone == null) {
6083 return null;
6084 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006085
Hall Liuf19c44f2018-11-27 14:38:17 -08006086 ServiceState ss = phone.getServiceState();
6087
6088 // Scrub out the location info in ServiceState depending on what level of access
6089 // the caller has.
6090 if (hasFinePermission) return ss;
6091 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6092 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 } finally {
6094 Binder.restoreCallingIdentity(identity);
6095 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006096 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006097
6098 /**
6099 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6100 *
6101 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6102 * voicemail ringtone.
6103 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6104 * PhoneAccount.
6105 */
6106 @Override
6107 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6111 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006112 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6116 } finally {
6117 Binder.restoreCallingIdentity(identity);
6118 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006119 }
6120
6121 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006122 * Sets the per-account voicemail ringtone.
6123 *
6124 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6125 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6126 *
6127 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6128 * voicemail ringtone.
6129 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6130 * PhoneAccount.
6131 */
6132 @Override
6133 public void setVoicemailRingtoneUri(String callingPackage,
6134 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006135 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006136 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006137 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6138 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6140 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6141 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143
6144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6147 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006148 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 }
6150 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6151 } finally {
6152 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006153 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006154 }
6155
6156 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006157 * Returns whether vibration is set for voicemail notification in Phone settings.
6158 *
6159 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6160 * voicemail vibration setting.
6161 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6162 */
6163 @Override
6164 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 final long identity = Binder.clearCallingIdentity();
6166 try {
6167 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6168 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006169 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6173 } finally {
6174 Binder.restoreCallingIdentity(identity);
6175 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006176 }
6177
Youhan Wange64578a2016-05-02 15:32:42 -07006178 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006179 * Sets the per-account voicemail vibration.
6180 *
6181 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6182 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6183 *
6184 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6185 * voicemail vibration setting.
6186 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6187 * specific PhoneAccount.
6188 */
6189 @Override
6190 public void setVoicemailVibrationEnabled(String callingPackage,
6191 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006192 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006193 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006194 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6195 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6197 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6198 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006199 }
6200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6204 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006205 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206 }
6207 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6208 } finally {
6209 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006210 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006211 }
6212
6213 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006214 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6215 *
6216 * @throws SecurityException if the caller does not have the required permission
6217 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006218 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006219 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006220 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006221 }
6222
6223 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006224 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6225 * permission.
6226 *
6227 * @throws SecurityException if the caller does not have the required permission
6228 */
6229 private void enforceSendSmsPermission() {
6230 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6231 }
6232
6233 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006234 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006235 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006236 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006237 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006238 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006242 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 if (componentName == null) {
6244 throw new SecurityException(
6245 "Caller not current active visual voicemail package[null]");
6246 }
6247 String vvmPackage = componentName.getPackageName();
6248 if (!callingPackage.equals(vvmPackage)) {
6249 throw new SecurityException("Caller not current active visual voicemail package["
6250 + vvmPackage + "]");
6251 }
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006254 }
6255 }
6256
6257 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006258 * Return the application ID for the app type.
6259 *
6260 * @param subId the subscription ID that this request applies to.
6261 * @param appType the uicc app type.
6262 * @return Application ID for specificied app type, or null if no uicc.
6263 */
6264 @Override
6265 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006266 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006267 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268
6269 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006270 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271 if (phone == null) {
6272 return null;
6273 }
6274 String aid = null;
6275 try {
6276 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6277 .getApplicationByType(appType).getAid();
6278 } catch (Exception e) {
6279 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6280 }
6281 return aid;
6282 } finally {
6283 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006284 }
Youhan Wange64578a2016-05-02 15:32:42 -07006285 }
6286
Youhan Wang4001d252016-05-11 10:29:41 -07006287 /**
6288 * Return the Electronic Serial Number.
6289 *
6290 * @param subId the subscription ID that this request applies to.
6291 * @return ESN or null if error.
6292 */
6293 @Override
6294 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006295 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006296 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297
6298 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006299 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 if (phone == null) {
6301 return null;
6302 }
6303 String esn = null;
6304 try {
6305 esn = phone.getEsn();
6306 } catch (Exception e) {
6307 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6308 }
6309 return esn;
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006312 }
Youhan Wang4001d252016-05-11 10:29:41 -07006313 }
6314
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006315 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006316 * Return the Preferred Roaming List Version.
6317 *
6318 * @param subId the subscription ID that this request applies to.
6319 * @return PRLVersion or null if error.
6320 */
6321 @Override
6322 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006323 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006324 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325
6326 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006327 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 if (phone == null) {
6329 return null;
6330 }
6331 String cdmaPrlVersion = null;
6332 try {
6333 cdmaPrlVersion = phone.getCdmaPrlVersion();
6334 } catch (Exception e) {
6335 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6336 }
6337 return cdmaPrlVersion;
6338 } finally {
6339 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006340 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006341 }
6342
6343 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006344 * Get snapshot of Telephony histograms
6345 * @return List of Telephony histograms
6346 * @hide
6347 */
6348 @Override
6349 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6351 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 return RIL.getTelephonyRILTimingHistograms();
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006359 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006360
6361 /**
6362 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006363 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6364 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006365 * Require system privileges. In the future we may add this to carrier APIs.
6366 *
Michele Berionne482f8202018-11-27 18:57:59 -08006367 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006368 */
6369 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006370 @TelephonyManager.SetCarrierRestrictionResult
6371 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006372 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006373 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006374
Michele Berionne482f8202018-11-27 18:57:59 -08006375 if (carrierRestrictionRules == null) {
6376 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006377 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 final long identity = Binder.clearCallingIdentity();
6380 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006381 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006382 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006386 }
6387
6388 /**
6389 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006390 * Get the allowed carrier list and the excluded carrier list, including the priority between
6391 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006392 * Require system privileges. In the future we may add this to carrier APIs.
6393 *
Michele Berionne482f8202018-11-27 18:57:59 -08006394 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006395 */
6396 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006397 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006398 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006399 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006403 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6404 if (response instanceof CarrierRestrictionRules) {
6405 return (CarrierRestrictionRules) response;
6406 }
6407 // Response is an Exception of some kind,
6408 // which is signalled to the user as a NULL retval
6409 return null;
6410 } catch (Exception e) {
6411 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6412 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006416 }
6417
fionaxu59545b42016-05-25 15:53:37 -07006418 /**
6419 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6420 * @param subId the subscription ID that this action applies to.
6421 * @param enabled control enable or disable metered apns.
6422 * {@hide}
6423 */
6424 @Override
6425 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6426 enforceModifyPermission();
6427 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428
6429 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006430 if (phone == null) {
6431 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6432 return;
6433 }
6434 try {
6435 phone.carrierActionSetMeteredApnsEnabled(enabled);
6436 } catch (Exception e) {
6437 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438 } finally {
6439 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006440 }
6441 }
6442
6443 /**
6444 * Action set from carrier signalling broadcast receivers to enable/disable radio
6445 * @param subId the subscription ID that this action applies to.
6446 * @param enabled control enable or disable radio.
6447 * {@hide}
6448 */
6449 @Override
6450 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6451 enforceModifyPermission();
6452 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453
6454 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006455 if (phone == null) {
6456 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6457 return;
6458 }
6459 try {
6460 phone.carrierActionSetRadioEnabled(enabled);
6461 } catch (Exception e) {
6462 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006463 } finally {
6464 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006465 }
6466 }
6467
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006468 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006469 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6470 * network status based on which carrier apps could apply actions accordingly,
6471 * enable/disable default url handler for example.
6472 *
6473 * @param subId the subscription ID that this action applies to.
6474 * @param report control start/stop reporting the default network status.
6475 * {@hide}
6476 */
6477 @Override
6478 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6479 enforceModifyPermission();
6480 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481
6482 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006483 if (phone == null) {
6484 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6485 return;
6486 }
6487 try {
6488 phone.carrierActionReportDefaultNetworkStatus(report);
6489 } catch (Exception e) {
6490 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 } finally {
6492 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006493 }
6494 }
6495
6496 /**
fionaxud9622282017-07-17 17:51:30 -07006497 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6498 * @param subId the subscription ID that this action applies to.
6499 * {@hide}
6500 */
6501 @Override
6502 public void carrierActionResetAll(int subId) {
6503 enforceModifyPermission();
6504 final Phone phone = getPhone(subId);
6505 if (phone == null) {
6506 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6507 return;
6508 }
6509 try {
6510 phone.carrierActionResetAll();
6511 } catch (Exception e) {
6512 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6513 }
6514 }
6515
6516 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006517 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6518 * bug report is being generated.
6519 */
6520 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006521 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006522 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6523 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006524 writer.println("Permission Denial: can't dump Phone from pid="
6525 + Binder.getCallingPid()
6526 + ", uid=" + Binder.getCallingUid()
6527 + "without permission "
6528 + android.Manifest.permission.DUMP);
6529 return;
6530 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006531 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006532 }
Jack Yueb89b242016-06-22 13:27:47 -07006533
Brad Ebingerdac2f002018-04-03 15:17:52 -07006534 @Override
6535 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6536 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6537 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006538 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6539 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006540 }
6541
Jack Yueb89b242016-06-22 13:27:47 -07006542 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006543 * Get aggregated video call data usage since boot.
6544 *
6545 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6546 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006547 * {@hide}
6548 */
6549 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006550 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006551 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6552 null);
6553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 // NetworkStatsService keeps tracking the active network interface and identity. It
6557 // records the delta with the corresponding network identity.
6558 // We just return the total video call data usage snapshot since boot.
6559 Phone phone = getPhone(subId);
6560 if (phone != null) {
6561 return phone.getVtDataUsage(perUidStats);
6562 }
6563 return null;
6564 } finally {
6565 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006566 }
Jack Yueb89b242016-06-22 13:27:47 -07006567 }
Jack Yu75ab2952016-07-08 14:29:33 -07006568
6569 /**
6570 * Policy control of data connection. Usually used when data limit is passed.
6571 * @param enabled True if enabling the data, otherwise disabling.
6572 * @param subId Subscription index
6573 * {@hide}
6574 */
6575 @Override
6576 public void setPolicyDataEnabled(boolean enabled, int subId) {
6577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578
6579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 Phone phone = getPhone(subId);
6582 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006583 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 }
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006587 }
6588 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006589
6590 /**
6591 * Get Client request stats
6592 * @return List of Client Request Stats
6593 * @hide
6594 */
6595 @Override
6596 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006598 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006599 return null;
6600 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006601 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 final long identity = Binder.clearCallingIdentity();
6604 try {
6605 if (phone != null) {
6606 return phone.getClientRequestStats();
6607 }
6608
6609 return null;
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006613 }
6614
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006615 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006616 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006617 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006618 }
Jack Yueb4124c2017-02-16 15:32:43 -08006619
6620 /**
Grace Chen70990072017-03-24 17:21:30 -07006621 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006622 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006623 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006624 * @param state State of SIM (power down, power up, pass through)
6625 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6626 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6627 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006628 *
6629 **/
6630 @Override
Grace Chen70990072017-03-24 17:21:30 -07006631 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006632 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006633 Phone phone = PhoneFactory.getPhone(slotIndex);
6634
vagdeviaf9a5b92018-08-15 16:01:53 -07006635 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006640 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006641 }
6642 } finally {
6643 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006644 }
6645 }
Shuo Qiandd210312017-04-12 22:11:33 +00006646
Tyler Gunn65d45c22017-06-05 11:22:26 -07006647 private boolean isUssdApiAllowed(int subId) {
6648 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006649 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006650 if (configManager == null) {
6651 return false;
6652 }
6653 PersistableBundle pb = configManager.getConfigForSubId(subId);
6654 if (pb == null) {
6655 return false;
6656 }
6657 return pb.getBoolean(
6658 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6659 }
6660
Shuo Qiandd210312017-04-12 22:11:33 +00006661 /**
6662 * Check if phone is in emergency callback mode
6663 * @return true if phone is in emergency callback mode
6664 * @param subId sub id
6665 */
goneil9c5f4872017-12-05 14:07:56 -08006666 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006667 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006668 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006669 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670
6671 final long identity = Binder.clearCallingIdentity();
6672 try {
6673 if (phone != null) {
6674 return phone.isInEcm();
6675 } else {
6676 return false;
6677 }
6678 } finally {
6679 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006680 }
6681 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006682
6683 /**
6684 * Get the current signal strength information for the given subscription.
6685 * Because this information is not updated when the device is in a low power state
6686 * it should not be relied-upon to be current.
6687 * @param subId Subscription index
6688 * @return the most recent cached signal strength info from the modem
6689 */
6690 @Override
6691 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 final long identity = Binder.clearCallingIdentity();
6693 try {
6694 Phone p = getPhone(subId);
6695 if (p == null) {
6696 return null;
6697 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 return p.getSignalStrength();
6700 } finally {
6701 Binder.restoreCallingIdentity(identity);
6702 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006703 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006704
Pengquan Meng77b7f132018-08-22 14:49:57 -07006705 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006706 * Get the current modem radio state for the given slot.
6707 * @param slotIndex slot index.
6708 * @param callingPackage the name of the package making the call.
6709 * @return the current radio power state from the modem
6710 */
6711 @Override
6712 public int getRadioPowerState(int slotIndex, String callingPackage) {
6713 Phone phone = PhoneFactory.getPhone(slotIndex);
6714 if (phone != null) {
6715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6716 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6717 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6718 }
6719
6720 final long identity = Binder.clearCallingIdentity();
6721 try {
6722 return phone.getRadioPowerState();
6723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
6726 }
6727 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6728 }
6729
6730 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006731 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6732 *
6733 * <p>Requires one of the following permissions:
6734 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6735 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6736 * privileges.
6737 *
6738 * @param subId subscription id
6739 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6740 * {@code false}.
6741 */
6742 @Override
6743 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006744 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6745 null /* message */);
6746
Pengquan Menga1bb6272018-09-06 09:59:22 -07006747 boolean isEnabled = false;
6748 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006749 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006750 Phone phone = getPhone(subId);
6751 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006752 } catch (Exception e) {
6753 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6754 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006755 } finally {
6756 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006757 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006758 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006759 }
6760
6761
6762 /**
6763 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6764 *
6765 * <p> Requires permission:
6766 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6767 * privileges.
6768 *
6769 * @param subId subscription id
6770 * @param isEnabled {@code true} means enable, {@code false} means disable.
6771 */
6772 @Override
6773 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6775 mApp, subId, "setDataRoamingEnabled");
6776
Pengquan Menga1bb6272018-09-06 09:59:22 -07006777 final long identity = Binder.clearCallingIdentity();
6778 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006779 Phone phone = getPhone(subId);
6780 if (phone != null) {
6781 phone.setDataRoamingEnabled(isEnabled);
6782 }
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006785 }
6786 }
6787
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006788 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006789 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006790 TelephonyPermissions
6791 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006792 mApp, subId, "isManualNetworkSelectionAllowed");
6793
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006794 boolean isAllowed = true;
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006797 Phone phone = getPhone(subId);
6798 if (phone != null) {
6799 isAllowed = phone.isCspPlmnEnabled();
6800 }
6801 } finally {
6802 Binder.restoreCallingIdentity(identity);
6803 }
6804 return isAllowed;
6805 }
6806
6807 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006808 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006809 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006810 try {
6811 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006812 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006813 } catch (SecurityException e) {
6814 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6815 // has carrier privileges on an active UICC
6816 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6817 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006818 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006819 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006820 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006821
6822 final long identity = Binder.clearCallingIdentity();
6823 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006824 UiccController uiccController = UiccController.getInstance();
6825 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006826 if (hasReadPermission) {
6827 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006828 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006829
6830 // Remove private info if the caller doesn't have access
6831 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6832 for (UiccCardInfo cardInfo : cardInfos) {
6833 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6834 // is available
6835 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6836 if (card == null || card.getUiccProfile() == null) {
6837 // assume no access if the card or profile is unavailable
6838 filteredInfos.add(cardInfo.getUnprivileged());
6839 continue;
6840 }
6841 UiccProfile profile = card.getUiccProfile();
6842 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6843 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6844 filteredInfos.add(cardInfo);
6845 } else {
6846 filteredInfos.add(cardInfo.getUnprivileged());
6847 }
6848 }
6849 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
6853 }
6854
6855 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006856 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006857 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 final long identity = Binder.clearCallingIdentity();
6860 try {
6861 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6862 if (slots == null) {
6863 Rlog.i(LOG_TAG, "slots is null.");
6864 return null;
6865 }
6866
6867 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6868 for (int i = 0; i < slots.length; i++) {
6869 UiccSlot slot = slots[i];
6870 if (slot == null) {
6871 continue;
6872 }
6873
Jordan Liu7be7e652019-05-06 18:55:02 +00006874 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875 UiccCard card = slot.getUiccCard();
6876 if (card != null) {
6877 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006878 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006879 cardId = slot.getEid();
6880 if (TextUtils.isEmpty(cardId)) {
6881 cardId = slot.getIccId();
6882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 }
6884
Jordan Liu857451f2019-05-09 16:35:35 -07006885 if (cardId != null) {
6886 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6887 // if cardId is an EID, it's all digits so this is fine
6888 cardId = IccUtils.stripTrailingFs(cardId);
6889 }
6890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 int cardState = 0;
6892 switch (slot.getCardState()) {
6893 case CARDSTATE_ABSENT:
6894 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6895 break;
6896 case CARDSTATE_PRESENT:
6897 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6898 break;
6899 case CARDSTATE_ERROR:
6900 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6901 break;
6902 case CARDSTATE_RESTRICTED:
6903 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6904 break;
6905 default:
6906 break;
6907
6908 }
6909
6910 infos[i] = new UiccSlotInfo(
6911 slot.isActive(),
6912 slot.isEuicc(),
6913 cardId,
6914 cardState,
6915 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006916 slot.isExtendedApduSupported(),
6917 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918 }
6919 return infos;
6920 } finally {
6921 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006922 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006923 }
6924
6925 @Override
6926 public boolean switchSlots(int[] physicalSlots) {
6927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928
6929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6932 } finally {
6933 Binder.restoreCallingIdentity(identity);
6934 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006935 }
Jack Yu4c988042018-02-27 15:30:01 -08006936
6937 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006938 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 return UiccController.getInstance().getCardIdForDefaultEuicc();
6942 } finally {
6943 Binder.restoreCallingIdentity(identity);
6944 }
6945 }
6946
6947 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006948 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6949 enforceModifyPermission();
6950 final Phone phone = getPhone(subId);
6951 if (phone == null) {
6952 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6953 return;
6954 }
6955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 phone.setRadioIndicationUpdateMode(filters, mode);
6959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
Jack Yu4c988042018-02-27 15:30:01 -08006962 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006963
6964 /**
goneil47ffb6e2018-04-06 15:40:58 -07006965 * A test API to reload the UICC profile.
6966 *
6967 * <p>Requires that the calling app has permission
6968 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6969 * @hide
6970 */
6971 @Override
6972 public void refreshUiccProfile(int subId) {
6973 enforceModifyPermission();
6974
6975 final long identity = Binder.clearCallingIdentity();
6976 try {
6977 Phone phone = getPhone(subId);
6978 if (phone == null) {
6979 return;
6980 }
6981 UiccCard uiccCard = phone.getUiccCard();
6982 if (uiccCard == null) {
6983 return;
6984 }
6985 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6986 if (uiccProfile == null) {
6987 return;
6988 }
6989 uiccProfile.refresh();
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
6992 }
6993 }
6994
6995 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006996 * Returns false if the mobile data is disabled by default, otherwise return true.
6997 */
6998 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09006999 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007000 }
7001
7002 /**
7003 * Returns true if the data roaming is enabled by default, i.e the system property
7004 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7005 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7006 */
7007 private boolean getDefaultDataRoamingEnabled(int subId) {
7008 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007009 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007010 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007011 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7012 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7013 return isDataRoamingEnabled;
7014 }
7015
7016 /**
7017 * Returns the default network type for the given {@code subId}, if the default network type is
7018 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7019 */
7020 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007021 List<Integer> list = TelephonyProperties.default_network();
7022 int phoneId = mSubscriptionController.getPhoneId(subId);
7023 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7024 return list.get(phoneId);
7025 }
7026 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007027 }
fionaxua13278b2018-03-21 00:08:13 -07007028
7029 @Override
7030 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007031 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007032 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033
7034 final long identity = Binder.clearCallingIdentity();
7035 try {
7036 final Phone phone = getPhone(subId);
7037 if (phone == null) {
7038 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7039 return;
7040 }
chen xueaba88a2019-03-15 13:15:10 -07007041 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7042 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 } finally {
7044 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007045 }
fionaxua13278b2018-03-21 00:08:13 -07007046 }
7047
7048 @Override
7049 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007050 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051
7052 final long identity = Binder.clearCallingIdentity();
7053 try {
7054 final Phone phone = getPhone(subId);
7055 if (phone == null) {
7056 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7057 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7058 }
7059 return phone.getCarrierIdListVersion();
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007062 }
fionaxua13278b2018-03-21 00:08:13 -07007063 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007064
7065 @Override
7066 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7068 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7069 return -1;
7070 }
7071
7072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7075 } finally {
7076 Binder.restoreCallingIdentity(identity);
7077 }
7078 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007079
7080 @Override
7081 public int getCdmaRoamingMode(int subId) {
7082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7083 mApp, subId, "getCdmaRoamingMode");
7084
7085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
7090 }
7091 }
7092
7093 @Override
7094 public boolean setCdmaRoamingMode(int subId, int mode) {
7095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7096 mApp, subId, "setCdmaRoamingMode");
7097
7098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
7104 }
7105
7106 @Override
7107 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7109 mApp, subId, "setCdmaSubscriptionMode");
7110
7111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
7116 }
7117 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007118
sqianc5eccab2018-10-19 18:46:41 -07007119 @Override
sqian8c685422019-02-22 15:55:18 -08007120 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007121 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007123 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007124 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7125 }
7126 final long identity = Binder.clearCallingIdentity();
7127 try {
sqian854d44b2018-12-12 16:48:18 -08007128 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7129 for (Phone phone: PhoneFactory.getPhones()) {
7130 if (phone.getEmergencyNumberTracker() != null
7131 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7132 emergencyNumberListInternal.put(
7133 phone.getSubId(),
7134 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7135 }
sqian11b7a0e2018-12-05 18:48:28 -08007136 }
sqian854d44b2018-12-12 16:48:18 -08007137 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007138 } finally {
7139 Binder.restoreCallingIdentity(identity);
7140 }
sqianc5eccab2018-10-19 18:46:41 -07007141 }
7142
7143 @Override
sqian8c685422019-02-22 15:55:18 -08007144 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007145 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007146 if (!exactMatch) {
7147 TelephonyPermissions
7148 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007149 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007150 }
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
sqian854d44b2018-12-12 16:48:18 -08007153 for (Phone phone: PhoneFactory.getPhones()) {
7154 if (phone.getEmergencyNumberTracker() != null
7155 && phone.getEmergencyNumberTracker() != null) {
7156 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7157 number, exactMatch)) {
7158 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007159 }
7160 }
sqian11b7a0e2018-12-05 18:48:28 -08007161 }
7162 return false;
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
7166 }
7167
sqianf4ca7ed2019-01-15 18:32:07 -08007168 /**
7169 * Update emergency number list for test mode.
7170 */
7171 @Override
7172 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7173 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7174 "updateEmergencyNumberListTestMode");
7175
7176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 for (Phone phone: PhoneFactory.getPhones()) {
7179 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7180 if (tracker != null) {
7181 tracker.executeEmergencyNumberTestModeCommand(action, num);
7182 }
7183 }
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
7187 }
7188
7189 /**
7190 * Get the full emergency number list for test mode.
7191 */
7192 @Override
7193 public List<String> getEmergencyNumberListTestMode() {
7194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7195 "getEmergencyNumberListTestMode");
7196
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 Set<String> emergencyNumbers = new HashSet<>();
7200 for (Phone phone: PhoneFactory.getPhones()) {
7201 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7202 if (tracker != null) {
7203 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7204 emergencyNumbers.add(num.getNumber());
7205 }
7206 }
7207 }
7208 return new ArrayList<>(emergencyNumbers);
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
7211 }
7212 }
7213
chen xud6b45bd2018-10-30 22:27:10 -07007214 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007215 public int getEmergencyNumberDbVersion(int subId) {
7216 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7217
7218 final long identity = Binder.clearCallingIdentity();
7219 try {
7220 final Phone phone = getPhone(subId);
7221 if (phone == null) {
7222 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7223 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7224 }
7225 return phone.getEmergencyNumberDbVersion();
7226 } finally {
7227 Binder.restoreCallingIdentity(identity);
7228 }
7229 }
7230
7231 @Override
7232 public void notifyOtaEmergencyNumberDbInstalled() {
7233 enforceModifyPermission();
7234
7235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 for (Phone phone: PhoneFactory.getPhones()) {
7238 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7239 if (tracker != null) {
7240 tracker.updateOtaEmergencyNumberDatabase();
7241 }
7242 }
7243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
7246 }
7247
7248 @Override
7249 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7250 enforceActiveEmergencySessionPermission();
7251
7252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 for (Phone phone: PhoneFactory.getPhones()) {
7255 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7256 if (tracker != null) {
7257 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7258 }
7259 }
7260 } finally {
7261 Binder.restoreCallingIdentity(identity);
7262 }
7263 }
7264
7265 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007266 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7267 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7268 Phone phone = getPhone(subId);
7269 if (phone == null) {
7270 return null;
7271 }
7272 final long identity = Binder.clearCallingIdentity();
7273 try {
7274 UiccProfile profile = UiccController.getInstance()
7275 .getUiccProfileForPhone(phone.getPhoneId());
7276 if (profile != null) {
7277 return profile.getCertsFromCarrierPrivilegeAccessRules();
7278 }
7279 } finally {
7280 Binder.restoreCallingIdentity(identity);
7281 }
7282 return null;
7283 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007284
7285 /**
7286 * Enable or disable a modem stack.
7287 */
7288 @Override
7289 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7290 enforceModifyPermission();
7291
7292 final long identity = Binder.clearCallingIdentity();
7293 try {
7294 Phone phone = PhoneFactory.getPhone(slotIndex);
7295 if (phone == null) {
7296 return false;
7297 } else {
7298 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7299 }
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
7303 }
Michelecea4cf22018-12-21 15:00:11 -08007304
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007305 /**
7306 * Whether a modem stack is enabled or not.
7307 */
7308 @Override
7309 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7310 Phone phone = PhoneFactory.getPhone(slotIndex);
7311 if (phone == null) return false;
7312
7313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7314 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7315 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7316 }
7317
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007320 try {
7321 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7322 } catch (NoSuchElementException ex) {
7323 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7324 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
7328 }
7329
Michelecea4cf22018-12-21 15:00:11 -08007330 @Override
Michele0ea7d782019-03-19 14:58:42 -07007331 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007332 enforceModifyPermission();
7333
7334 final long identity = Binder.clearCallingIdentity();
7335 try {
7336 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007337 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007338 .commit();
7339 } finally {
7340 Binder.restoreCallingIdentity(identity);
7341 }
7342 }
7343
7344 @Override
Michele0ea7d782019-03-19 14:58:42 -07007345 @TelephonyManager.IsMultiSimSupportedResult
7346 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007348 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7349 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007350 }
Michelecea4cf22018-12-21 15:00:11 -08007351
7352 final long identity = Binder.clearCallingIdentity();
7353 try {
Michele0ea7d782019-03-19 14:58:42 -07007354 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007355 } finally {
7356 Binder.restoreCallingIdentity(identity);
7357 }
7358 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007359
Michele0ea7d782019-03-19 14:58:42 -07007360 @TelephonyManager.IsMultiSimSupportedResult
7361 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007362 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7363 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7364 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007365 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7366 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007367 }
7368 // Check if the hardware supports multisim functionality. If usage of multisim is not
7369 // supported by the modem, indicate that it is restricted.
7370 PhoneCapability staticCapability =
7371 mPhoneConfigurationManager.getStaticPhoneCapability();
7372 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007373 loge("isMultiSimSupportedInternal: no static configuration available");
7374 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007375 }
7376 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007377 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7378 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007379 }
7380 // Check if support of multiple SIMs is restricted by carrier
7381 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007382 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007383 }
7384
Michele0ea7d782019-03-19 14:58:42 -07007385 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007386 }
7387
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007388 /**
7389 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007390 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7391 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7392 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007393 * @param numOfSims number of active sims we want to switch to
7394 */
7395 @Override
7396 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007397 if (numOfSims == 1) {
7398 enforceModifyPermission();
7399 } else {
7400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7401 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7402 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007403 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007404
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007405 try {
Michele30b57b22019-03-01 12:01:14 -08007406 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007407 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007408 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7409 return;
7410 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007411 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
7415 }
7416
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007417 @Override
7418 public boolean isApplicationOnUicc(int subId, int appType) {
7419 enforceReadPrivilegedPermission("isApplicationOnUicc");
7420 Phone phone = getPhone(subId);
7421 if (phone == null) {
7422 return false;
7423 }
7424 final long identity = Binder.clearCallingIdentity();
7425 try {
7426 UiccCard uiccCard = phone.getUiccCard();
7427 if (uiccCard == null) {
7428 return false;
7429 }
7430 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7431 if (uiccProfile == null) {
7432 return false;
7433 }
7434 if (TelephonyManager.APPTYPE_SIM <= appType
7435 && appType <= TelephonyManager.APPTYPE_ISIM) {
7436 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7437 }
7438 return false;
7439 } finally {
7440 Binder.restoreCallingIdentity(identity);
7441 }
7442 }
7443
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007444 /**
chen xub4baa772019-04-03 10:23:41 -07007445 * Get whether making changes to modem configurations will trigger reboot.
7446 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007447 */
7448 @Override
chen xub4baa772019-04-03 10:23:41 -07007449 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7451 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7452 return false;
7453 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007454 final long identity = Binder.clearCallingIdentity();
7455 try {
7456 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
7460 }
7461
Nathan Harold29f5f052019-02-15 13:41:57 -08007462 private void updateModemStateMetrics() {
7463 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7464 // TODO: check the state for each modem if the api is ready.
7465 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7466 }
7467
Pengquan Meng3889a572019-01-23 11:16:29 -08007468 @Override
7469 public int[] getSlotsMapping() {
7470 enforceReadPrivilegedPermission("getSlotsMapping");
7471
7472 final long identity = Binder.clearCallingIdentity();
7473 try {
7474 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7475 // All logical slots should have a mapping to a physical slot.
7476 int[] logicalSlotsMapping = new int[phoneCount];
7477 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7478 for (int i = 0; i < slotInfos.length; i++) {
7479 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7480 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7481 }
7482 }
7483 return logicalSlotsMapping;
7484 } finally {
7485 Binder.restoreCallingIdentity(identity);
7486 }
7487 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007488
7489 /**
7490 * Get the IRadio HAL Version
7491 */
7492 @Override
7493 public int getRadioHalVersion() {
7494 Phone phone = getDefaultPhone();
7495 if (phone == null) return -1;
7496 HalVersion hv = phone.getHalVersion();
7497 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7498 return hv.major * 100 + hv.minor;
7499 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007500
7501 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007502 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7503 * corresponding network requests on a subId.
7504 *
7505 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007506 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007507 * 2) APN is un-metered for this subscription, or
7508 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7509 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7510 *
7511 * @return whether data is allowed for a apn type.
7512 *
7513 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007514 */
7515 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007516 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007517 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7518 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007519
7520 // Now that all security checks passes, perform the operation as ourselves.
7521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 Phone phone = getPhone(subId);
7524 if (phone == null) return false;
7525
Jack Yu41407ee2019-05-13 16:54:09 -07007526 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007527 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
7531 }
7532
7533 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007534 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007535 enforceReadPrivilegedPermission("isApnMetered");
7536
7537 // Now that all security checks passes, perform the operation as ourselves.
7538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 Phone phone = getPhone(subId);
7541 if (phone == null) return true; // By default return true.
7542
Jack Yu41407ee2019-05-13 16:54:09 -07007543 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
7547 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007548
7549 @Override
7550 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7551 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7552 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7553 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7554 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7555 }
7556 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7557 Intent intent = new Intent();
7558 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7559 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7560 // Bring up choose default SMS subscription dialog right now
7561 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7562 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7563 mApp.startActivity(intent);
7564 }
chen xud5ca2d52019-05-28 15:20:57 -07007565
7566 @Override
7567 public String getMmsUAProfUrl(int subId) {
7568 //TODO investigate if this API should require proper permission check in R b/133791609
7569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7572 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
7576 }
7577
7578 @Override
7579 public String getMmsUserAgent(int subId) {
7580 //TODO investigate if this API should require proper permission check in R b/133791609
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7584 .getString(com.android.internal.R.string.config_mms_user_agent);
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
7587 }
7588 }
Jack Yub07d4972019-05-28 16:12:25 -07007589
7590 @Override
7591 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7592 enforceModifyPermission();
7593
7594 // Now that all security checks passes, perform the operation as ourselves.
7595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = getPhone(subId);
7598 if (phone == null) return false;
7599
7600 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
7604 }
7605
7606 @Override
7607 public boolean isDataAllowedInVoiceCall(int subId) {
7608 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7609
7610 // Now that all security checks passes, perform the operation as ourselves.
7611 final long identity = Binder.clearCallingIdentity();
7612 try {
7613 Phone phone = getPhone(subId);
7614 if (phone == null) return false;
7615
7616 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007621
7622 /**
7623 * Updates whether conference event pacakge handling is enabled.
7624 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7625 * otherwise.
7626 */
7627 @Override
7628 public void setCepEnabled(boolean isCepEnabled) {
7629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7630
7631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7634 for (Phone phone : PhoneFactory.getPhones()) {
7635 Phone defaultPhone = phone.getImsPhone();
7636 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7637 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7638 ImsPhoneCallTracker imsPhoneCallTracker =
7639 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7640 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7641 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7642 + imsPhone.getMsisdn());
7643 }
7644 }
7645 } finally {
7646 Binder.restoreCallingIdentity(identity);
7647 }
7648 }
allenwtsu46dcc572020-01-08 18:24:03 +08007649
7650 /**
7651 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7652 *
7653 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7654 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7655 * before being read.
7656 */
7657 @Override
7658 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7659 isCompressed) {
7660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7661 mApp, subId, "notifyRcsAutoConfigurationReceived");
7662 try {
7663 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7664 if (configBinder == null) {
7665 Rlog.e(LOG_TAG, "null result for getImsConfig");
7666 } else {
7667 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7668 }
7669 } catch (RemoteException e) {
7670 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7671 }
7672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007673}