blob: ab03c80e1b15ef1b678ccc1b3018c0fce5bfdead [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;
Hall Liua1548bd2019-12-24 14:14:12 -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;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
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;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import 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;
Hall Liu73f5d362020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800170import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700171import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800175import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700177import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800178import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700180import java.io.FileDescriptor;
181import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800184import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800186import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100187import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700189import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800191import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800192import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
194/**
195 * Implementation of the ITelephony interface.
196 */
Santos Cordon117fee72014-05-16 17:56:12 -0700197public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 private static final String LOG_TAG = "PhoneInterfaceManager";
199 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
200 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
203 // Message codes used with mMainThreadHandler
204 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700205 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
206 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700207 private static final int CMD_OPEN_CHANNEL = 9;
208 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
209 private static final int CMD_CLOSE_CHANNEL = 11;
210 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800211 private static final int CMD_NV_READ_ITEM = 13;
212 private static final int EVENT_NV_READ_ITEM_DONE = 14;
213 private static final int CMD_NV_WRITE_ITEM = 15;
214 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
215 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
216 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700217 private static final int CMD_RESET_MODEM_CONFIG = 19;
218 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800219 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
220 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
221 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
222 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800223 private static final int CMD_SEND_ENVELOPE = 25;
224 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000225 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
226 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700227 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
228 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
229 private static final int CMD_EXCHANGE_SIM_IO = 31;
230 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800231 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
232 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700233 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700235 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
236 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700237 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
238 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
239 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
240 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700241 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
242 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
243 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
244 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700245 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800246 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
247 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000248 private static final int CMD_SWITCH_SLOTS = 50;
249 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700250 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
251 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
252 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
253 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
254 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
255 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
256 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
257 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700258 private static final int CMD_GET_ALL_CELL_INFO = 60;
259 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
260 private static final int CMD_GET_CELL_LOCATION = 62;
261 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700262 private static final int CMD_MODEM_REBOOT = 64;
263 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700264 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
265 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800266 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
267 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700268 private static final int CMD_GET_MODEM_STATUS = 70;
269 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700270 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
271 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700272 private static final int CMD_ERASE_MODEM_CONFIG = 74;
273 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800274 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
275 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
276 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
277 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800278 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
279 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800280 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800282 // Parameters of select command.
283 private static final int SELECT_COMMAND = 0xA4;
284 private static final int SELECT_P1 = 0x04;
285 private static final int SELECT_P2 = 0;
286 private static final int SELECT_P3 = 0x10;
287
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 /** The singleton instance. */
289 private static PhoneInterfaceManager sInstance;
290
Wink Saville3ab207e2014-11-20 13:07:20 -0800291 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800292 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800293 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700294 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800295 private AppOpsManager mAppOps;
296 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800297 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800298 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700299 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
Peter Wangdafb9ac2020-01-15 14:13:38 -0800301 /** User Activity */
302 private AtomicBoolean mNotifyUserActivity;
303 private static final String ACTION_USER_ACTIVITY_NOTIFICATION =
304 "android.intent.action.USER_ACTIVITY_NOTIFICATION";
305 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
306
Derek Tan97ebb422014-09-05 16:55:38 -0700307 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
308 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800309 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800310 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700311
Michelecea4cf22018-12-21 15:00:11 -0800312 // String to store multi SIM allowed
313 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
314
Derek Tan740e1672017-06-27 14:56:27 -0700315 // The AID of ISD-R.
316 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
317
yinxub1bed742017-04-17 11:45:04 -0700318 private NetworkScanRequestTracker mNetworkScanRequestTracker;
319
David Kelly5e06a7f2018-03-12 14:10:59 +0000320 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
321 private static final int MANUFACTURER_CODE_LENGTH = 8;
322
Derek Tan89e89d42014-07-08 17:00:10 -0700323 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700324 * Experiment flag to enable erase modem config on reset network, default value is false
325 */
326 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
327 "reset_network_erase_modem_config_enabled";
328
329 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class IccAPDUArgument {
333 public int channel, cla, command, p1, p2, p3;
334 public String data;
335
336 public IccAPDUArgument(int channel, int cla, int command,
337 int p1, int p2, int p3, String data) {
338 this.channel = channel;
339 this.cla = cla;
340 this.command = command;
341 this.p1 = p1;
342 this.p2 = p2;
343 this.p3 = p3;
344 this.data = data;
345 }
346 }
347
348 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700349 * A request object to use for transmitting data to an ICC.
350 */
351 private static final class ManualNetworkSelectionArgument {
352 public OperatorInfo operatorInfo;
353 public boolean persistSelection;
354
355 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
356 this.operatorInfo = operatorInfo;
357 this.persistSelection = persistSelection;
358 }
359 }
360
361 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
363 * request after sending. The main thread will notify the request when it is complete.
364 */
365 private static final class MainThreadRequest {
366 /** The argument to use for the request */
367 public Object argument;
368 /** The result of the request that is run on the main thread */
369 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800370 // The subscriber id that this request applies to. Defaults to
371 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
372 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Nathan Harold92bed182018-10-12 18:16:49 -0700374 // In cases where subId is unavailable, the caller needs to specify the phone.
375 public Phone phone;
376
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 public WorkSource workSource;
378
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 public MainThreadRequest(Object argument) {
380 this.argument = argument;
381 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
384 this.argument = argument;
385 if (phone != null) {
386 this.phone = phone;
387 }
388 this.workSource = workSource;
389 }
390
vagdeviaf9a5b92018-08-15 16:01:53 -0700391 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800392 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800393 if (subId != null) {
394 this.subId = subId;
395 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700396 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 }
399
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800400 private static final class IncomingThirdPartyCallArgs {
401 public final ComponentName component;
402 public final String callId;
403 public final String callerDisplayName;
404
405 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
406 String callerDisplayName) {
407 this.component = component;
408 this.callId = callId;
409 this.callerDisplayName = callerDisplayName;
410 }
411 }
412
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 /**
414 * A handler that processes messages on the main thread in the phone process. Since many
415 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
416 * inbound binder threads to the main thread in the phone process. The Binder thread
417 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
418 * on, which will be notified when the operation completes and will contain the result of the
419 * request.
420 *
421 * <p>If a MainThreadRequest object is provided in the msg.obj field,
422 * note that request.result must be set to something non-null for the calling thread to
423 * unblock.
424 */
425 private final class MainThreadHandler extends Handler {
426 @Override
427 public void handleMessage(Message msg) {
428 MainThreadRequest request;
429 Message onCompleted;
430 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800431 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800433 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
435 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 case CMD_HANDLE_USSD_REQUEST: {
437 request = (MainThreadRequest) msg.obj;
438 final Phone phone = getPhoneFromRequest(request);
439 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
440 String ussdRequest = ussdObject.first;
441 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700442
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 if (!isUssdApiAllowed(request.subId)) {
444 // Carrier does not support use of this API, return failure.
445 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
446 UssdResponse response = new UssdResponse(ussdRequest, null);
447 Bundle returnData = new Bundle();
448 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
449 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 request.result = true;
452 notifyRequester(request);
453 return;
454 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700455
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 try {
457 request.result = phone != null
458 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
459 } catch (CallStateException cse) {
460 request.result = false;
461 }
462 // Wake up the requesting thread
463 notifyRequester(request);
464 break;
pkanwar32d516d2016-10-14 19:37:38 -0700465 }
466
Yorke Lee716f67e2015-06-17 15:39:16 -0700467 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700469 final Phone phone = getPhoneFromRequest(request);
470 request.result = phone != null ?
471 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
472 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700482 if (uiccCard == null) {
483 loge("iccTransmitApduLogicalChannel: No UICC");
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700486 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
488 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700489 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 iccArgument.channel, iccArgument.cla, iccArgument.command,
491 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 ar = (AsyncResult) msg.obj;
498 request = (MainThreadRequest) ar.userObj;
499 if (ar.exception == null && ar.result != null) {
500 request.result = ar.result;
501 } else {
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 if (ar.result == null) {
504 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800505 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800507 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 } else {
509 loge("iccTransmitApduLogicalChannel: Unknown exception");
510 }
511 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 break;
514
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccTransmitApduBasicChannel: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 } else {
524 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
525 request);
526 uiccCard.iccTransmitApduBasicChannel(
527 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
528 iccArgument.p3, iccArgument.data, onCompleted);
529 }
530 break;
531
532 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("iccTransmitApduBasicChannel: Empty response");
541 } else if (ar.exception instanceof CommandException) {
542 loge("iccTransmitApduBasicChannel: CommandException: " +
543 ar.exception);
544 } else {
545 loge("iccTransmitApduBasicChannel: Unknown exception");
546 }
547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 break;
550
551 case CMD_EXCHANGE_SIM_IO:
552 request = (MainThreadRequest) msg.obj;
553 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (uiccCard == null) {
556 loge("iccExchangeSimIO: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
561 request);
562 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
563 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
564 iccArgument.data, onCompleted);
565 }
566 break;
567
568 case EVENT_EXCHANGE_SIM_IO_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
573 } else {
574 request.result = new IccIoResult(0x6f, 0, (byte[])null);
575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 break;
578
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 case CMD_SEND_ENVELOPE:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 if (uiccCard == null) {
583 loge("sendEnvelopeWithStatus: No UICC");
584 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 } else {
587 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
588 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
592 case EVENT_SEND_ENVELOPE_DONE:
593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800597 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("sendEnvelopeWithStatus: Empty response");
601 } else if (ar.exception instanceof CommandException) {
602 loge("sendEnvelopeWithStatus: CommandException: " +
603 ar.exception);
604 } else {
605 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
606 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800609 break;
610
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 case CMD_OPEN_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800613 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800614 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 if (uiccCard == null) {
616 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800617 request.result = new IccOpenLogicalChannelResponse(-1,
618 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 } else {
621 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800622 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
623 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
627 case EVENT_OPEN_CHANNEL_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 int[] result = (int[]) ar.result;
633 int channelId = result[0];
634 byte[] selectResponse = null;
635 if (result.length > 1) {
636 selectResponse = new byte[result.length - 1];
637 for (int i = 1; i < result.length; ++i) {
638 selectResponse[i - 1] = (byte) result[i];
639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 if (ar.result == null) {
645 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.exception != null) {
648 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
649 }
650
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700652 if (ar.exception instanceof CommandException) {
653 CommandException.Error error =
654 ((CommandException) (ar.exception)).getCommandError();
655 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700656 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700657 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700658 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 }
660 }
661 openChannelResp = new IccOpenLogicalChannelResponse(
662 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700664 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 break;
667
668 case CMD_CLOSE_CHANNEL:
669 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800670 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 if (uiccCard == null) {
672 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900673 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 } else {
676 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
677 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
678 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
681 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800682 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
683 break;
684
685 case CMD_NV_READ_ITEM:
686 request = (MainThreadRequest) msg.obj;
687 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800688 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
689 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800690 break;
691
692 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800698 request.result = "";
699 if (ar.result == null) {
700 loge("nvReadItem: Empty response");
701 } else if (ar.exception instanceof CommandException) {
702 loge("nvReadItem: CommandException: " +
703 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800705 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 }
707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 break;
710
Jake Hambye994d462014-02-03 13:10:13 -0800711 case CMD_NV_WRITE_ITEM:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
714 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800715 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700716 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
719 case EVENT_NV_WRITE_ITEM_DONE:
720 handleNullReturnEvent(msg, "nvWriteItem");
721 break;
722
723 case CMD_NV_WRITE_CDMA_PRL:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
729 case EVENT_NV_WRITE_CDMA_PRL_DONE:
730 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
731 break;
732
chen xu6dac5ab2018-10-26 17:39:23 -0700733 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800734 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700735 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
chen xu6dac5ab2018-10-26 17:39:23 -0700739 case EVENT_RESET_MODEM_CONFIG_DONE:
740 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800741 break;
742
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 case CMD_GET_PREFERRED_NETWORK_TYPE:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700746 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
750 ar = (AsyncResult) msg.obj;
751 request = (MainThreadRequest) ar.userObj;
752 if (ar.exception == null && ar.result != null) {
753 request.result = ar.result; // Integer
754 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800755 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 if (ar.result == null) {
757 loge("getPreferredNetworkType: Empty response");
758 } else if (ar.exception instanceof CommandException) {
759 loge("getPreferredNetworkType: CommandException: " +
760 ar.exception);
761 } else {
762 loge("getPreferredNetworkType: Unknown exception");
763 }
764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800766 break;
767
768 case CMD_SET_PREFERRED_NETWORK_TYPE:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
771 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700772 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800773 break;
774
775 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
776 handleNullReturnEvent(msg, "setPreferredNetworkType");
777 break;
778
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000779 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
780 request = (MainThreadRequest)msg.obj;
781 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000783 break;
784
785 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
786 ar = (AsyncResult)msg.obj;
787 request = (MainThreadRequest)ar.userObj;
788 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000790 break;
791
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800792 case CMD_SET_VOICEMAIL_NUMBER:
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
795 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800796 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
797 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800798 break;
799
800 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
801 handleNullReturnEvent(msg, "setVoicemailNumber");
802 break;
803
Stuart Scott54788802015-03-30 13:18:01 -0700804 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
807 request);
808 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
809 break;
810
811 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
812 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
813 break;
814
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 case CMD_PERFORM_NETWORK_SCAN:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
818 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
819 break;
820
821 case EVENT_PERFORM_NETWORK_SCAN_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 CellNetworkScanResult cellScanResult;
825 if (ar.exception == null && ar.result != null) {
826 cellScanResult = new CellNetworkScanResult(
827 CellNetworkScanResult.STATUS_SUCCESS,
828 (List<OperatorInfo>) ar.result);
829 } else {
830 if (ar.result == null) {
831 loge("getCellNetworkScanResults: Empty response");
832 }
833 if (ar.exception != null) {
834 loge("getCellNetworkScanResults: Exception: " + ar.exception);
835 }
836 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
837 if (ar.exception instanceof CommandException) {
838 CommandException.Error error =
839 ((CommandException) (ar.exception)).getCommandError();
840 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
841 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
842 } else if (error == CommandException.Error.GENERIC_FAILURE) {
843 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
844 }
845 }
846 cellScanResult = new CellNetworkScanResult(errorCode, null);
847 }
848 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700849 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700850 break;
851
852 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
853 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700854 ManualNetworkSelectionArgument selArg =
855 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
857 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700858 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
859 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700860 break;
861
862 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null) {
866 request.result = true;
867 } else {
868 request.result = false;
869 loge("setNetworkSelectionModeManual " + ar.exception);
870 }
871 notifyRequester(request);
872 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700873 break;
874
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700875 case CMD_GET_MODEM_ACTIVITY_INFO:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700878 if (defaultPhone != null) {
879 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
880 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700881 break;
882
883 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 if (ar.result == null) {
890 loge("queryModemActivityInfo: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("queryModemActivityInfo: CommandException: " +
893 ar.exception);
894 } else {
895 loge("queryModemActivityInfo: Unknown exception");
896 }
897 }
Amit Mahajand4766222016-01-28 15:28:28 -0800898 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
899 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800900 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800901 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700902 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700903 break;
904
Meng Wang1a7c35a2016-05-05 20:56:15 -0700905 case CMD_SET_ALLOWED_CARRIERS:
906 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800907 CarrierRestrictionRules argument =
908 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800910 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 break;
912
913 case EVENT_SET_ALLOWED_CARRIERS_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800919 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
920 if (ar.exception instanceof CommandException) {
921 loge("setAllowedCarriers: CommandException: " + ar.exception);
922 CommandException.Error error =
923 ((CommandException) (ar.exception)).getCommandError();
924 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
925 request.result =
926 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
927 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700928 } else {
929 loge("setAllowedCarriers: Unknown exception");
930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 break;
934
935 case CMD_GET_ALLOWED_CARRIERS:
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800938 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
941 case EVENT_GET_ALLOWED_CARRIERS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800947 request.result = new IllegalStateException(
948 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700949 if (ar.result == null) {
950 loge("getAllowedCarriers: Empty response");
951 } else if (ar.exception instanceof CommandException) {
952 loge("getAllowedCarriers: CommandException: " +
953 ar.exception);
954 } else {
955 loge("getAllowedCarriers: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700959 break;
960
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 if (ar.exception == null && ar.result != null) {
965 request.result = ar.result;
966 } else {
967 request.result = new IllegalArgumentException(
968 "Failed to retrieve Forbidden Plmns");
969 if (ar.result == null) {
970 loge("getForbiddenPlmns: Empty response");
971 } else {
972 loge("getForbiddenPlmns: Unknown exception");
973 }
974 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977
978 case CMD_GET_FORBIDDEN_PLMNS:
979 request = (MainThreadRequest) msg.obj;
980 uiccCard = getUiccCardFromRequest(request);
981 if (uiccCard == null) {
982 loge("getForbiddenPlmns() UiccCard is null");
983 request.result = new IllegalArgumentException(
984 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700985 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800986 break;
987 }
988 Integer appType = (Integer) request.argument;
989 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
990 if (uiccApp == null) {
991 loge("getForbiddenPlmns() no app with specified type -- "
992 + appType);
993 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700994 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800995 break;
996 } else {
997 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
998 + " specified type -- " + appType);
999 }
1000 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1001 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1002 onCompleted);
1003 break;
1004
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001005 case CMD_SWITCH_SLOTS:
1006 request = (MainThreadRequest) msg.obj;
1007 int[] physicalSlots = (int[]) request.argument;
1008 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1009 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1010 break;
1011
1012 case EVENT_SWITCH_SLOTS_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001016 notifyRequester(request);
1017 break;
1018 case CMD_GET_NETWORK_SELECTION_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1021 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1022 break;
1023
1024 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1029 } else {
1030 int mode = ((int[]) ar.result)[0];
1031 if (mode == 0) {
1032 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1033 } else {
1034 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1035 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001036 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001037 notifyRequester(request);
1038 break;
1039 case CMD_GET_CDMA_ROAMING_MODE:
1040 request = (MainThreadRequest) msg.obj;
1041 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1042 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1043 break;
1044 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 if (ar.exception != null) {
1048 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1049 } else {
1050 request.result = ((int[]) ar.result)[0];
1051 }
1052 notifyRequester(request);
1053 break;
1054 case CMD_SET_CDMA_ROAMING_MODE:
1055 request = (MainThreadRequest) msg.obj;
1056 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1057 int mode = (int) request.argument;
1058 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1059 break;
1060 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 request.result = ar.exception == null;
1064 notifyRequester(request);
1065 break;
1066 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1067 request = (MainThreadRequest) msg.obj;
1068 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1069 int subscriptionMode = (int) request.argument;
1070 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1071 break;
1072 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 request.result = ar.exception == null;
1076 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001077 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001078 case CMD_GET_ALL_CELL_INFO:
1079 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001080 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001081 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001082 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 case EVENT_GET_ALL_CELL_INFO_DONE:
1084 ar = (AsyncResult) msg.obj;
1085 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001086 // If a timeout occurs, the response will be null
1087 request.result = (ar.exception == null && ar.result != null)
1088 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 synchronized (request) {
1090 request.notifyAll();
1091 }
1092 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 case CMD_REQUEST_CELL_INFO_UPDATE:
1094 request = (MainThreadRequest) msg.obj;
1095 request.phone.requestCellInfoUpdate(request.workSource,
1096 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1097 break;
1098 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1102 try {
1103 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001104 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001105 cb.onError(
1106 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1107 ar.exception.getClass().getName(),
1108 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001111 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 } else {
1113 // use the result as returned
1114 cb.onCellInfo((List<CellInfo>) ar.result);
1115 }
1116 } catch (RemoteException re) {
1117 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1118 }
1119 break;
1120 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001121 request = (MainThreadRequest) msg.obj;
1122 WorkSource ws = (WorkSource) request.argument;
1123 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001124 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001125 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001126 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 if (ar.exception == null) {
1130 request.result = ar.result;
1131 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001132 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001133 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001134 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001135 }
1136
1137 synchronized (request) {
1138 request.notifyAll();
1139 }
1140 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001141 case CMD_MODEM_REBOOT:
1142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001144 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001145 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001146 case EVENT_CMD_MODEM_REBOOT_DONE:
1147 handleNullReturnEvent(msg, "rebootModem");
1148 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001149 case CMD_REQUEST_ENABLE_MODEM:
1150 request = (MainThreadRequest) msg.obj;
1151 boolean enable = (boolean) request.argument;
1152 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001153 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001154 PhoneConfigurationManager.getInstance()
1155 .enablePhone(request.phone, enable, onCompleted);
1156 break;
1157 case EVENT_ENABLE_MODEM_DONE:
1158 ar = (AsyncResult) msg.obj;
1159 request = (MainThreadRequest) ar.userObj;
1160 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001161 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001162 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001163 if ((boolean) request.result) {
1164 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1165 updateModemStateMetrics();
1166 } else {
1167 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1168 + ar.exception);
1169 }
1170 notifyRequester(request);
1171 break;
1172 case CMD_GET_MODEM_STATUS:
1173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1175 PhoneConfigurationManager.getInstance()
1176 .getPhoneStatusFromModem(request.phone, onCompleted);
1177 break;
1178 case EVENT_GET_MODEM_STATUS_DONE:
1179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
1181 int id = request.phone.getPhoneId();
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 //update the cache as modem status has changed
1185 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1186 (boolean) request.result);
1187 } else {
1188 // Return true if modem status cannot be retrieved. For most cases,
1189 // modem status is on. And for older version modems, GET_MODEM_STATUS
1190 // and disable modem are not supported. Modem is always on.
1191 // TODO: this should be fixed in R to support a third
1192 // status UNKNOWN b/131631629
1193 request.result = true;
1194 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1195 + ar.exception);
1196 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001197 notifyRequester(request);
1198 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001199 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1202 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1203 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1204 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1205 break;
1206 }
1207 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1211 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1212 args.second.accept(ar.exception == null);
1213 notifyRequester(request);
1214 break;
1215 }
yincheng zhao2737e882019-09-06 17:06:54 -07001216 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
1219 if (ar.exception == null && ar.result != null) {
1220 request.result = ar.result;
1221 } else {
1222 request.result = -1;
1223 loge("Failed to set Forbidden Plmns");
1224 if (ar.result == null) {
1225 loge("setForbidenPlmns: Empty response");
1226 } else if (ar.exception != null) {
1227 loge("setForbiddenPlmns: Exception: " + ar.exception);
1228 request.result = -1;
1229 } else {
1230 loge("setForbiddenPlmns: Unknown exception");
1231 }
1232 }
1233 notifyRequester(request);
1234 break;
1235 case CMD_SET_FORBIDDEN_PLMNS:
1236 request = (MainThreadRequest) msg.obj;
1237 uiccCard = getUiccCardFromRequest(request);
1238 if (uiccCard == null) {
1239 loge("setForbiddenPlmns: UiccCard is null");
1240 request.result = -1;
1241 notifyRequester(request);
1242 break;
1243 }
1244 Pair<Integer, List<String>> setFplmnsArgs =
1245 (Pair<Integer, List<String>>) request.argument;
1246 appType = setFplmnsArgs.first;
1247 List<String> fplmns = setFplmnsArgs.second;
1248 uiccApp = uiccCard.getApplicationByType(appType);
1249 if (uiccApp == null) {
1250 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1251 request.result = -1;
1252 loge("Failed to get UICC App");
1253 notifyRequester(request);
1254 } else {
1255 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1256 ((SIMRecords) uiccApp.getIccRecords())
1257 .setForbiddenPlmns(onCompleted, fplmns);
1258 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001259 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001260 case CMD_ERASE_MODEM_CONFIG:
1261 request = (MainThreadRequest) msg.obj;
1262 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1263 defaultPhone.eraseModemConfig(onCompleted);
1264 break;
1265 case EVENT_ERASE_MODEM_CONFIG_DONE:
1266 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001267 break;
zoey chene02881a2019-12-30 16:11:23 +08001268
1269 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1270 request = (MainThreadRequest) msg.obj;
1271 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1272 Pair<String, String> changed = (Pair<String, String>) request.argument;
1273 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1274 changed.first, changed.second, onCompleted);
1275 break;
1276 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
1279 if (ar.exception == null) {
1280 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1281 } else {
1282 request.result = msg.arg1;
1283 }
1284 notifyRequester(request);
1285 break;
1286
1287 case CMD_SET_ICC_LOCK_ENABLED:
1288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1290 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1291 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1292 enabled.first, enabled.second, onCompleted);
1293 break;
1294 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
1297 if (ar.exception == null) {
1298 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1299 } else {
1300 request.result = msg.arg1;
1301 }
1302 notifyRequester(request);
1303 break;
1304
Peter Wangdafb9ac2020-01-15 14:13:38 -08001305 case MSG_NOTIFY_USER_ACTIVITY:
1306 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
1307 Intent intent = new Intent(ACTION_USER_ACTIVITY_NOTIFICATION);
1308 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1309 getDefaultPhone().getContext().sendBroadcastAsUser(
1310 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1311 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 default:
1313 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1314 break;
1315 }
1316 }
Jake Hambye994d462014-02-03 13:10:13 -08001317
Pengquan Menga1bb6272018-09-06 09:59:22 -07001318 private void notifyRequester(MainThreadRequest request) {
1319 synchronized (request) {
1320 request.notifyAll();
1321 }
1322 }
1323
Jake Hambye994d462014-02-03 13:10:13 -08001324 private void handleNullReturnEvent(Message msg, String command) {
1325 AsyncResult ar = (AsyncResult) msg.obj;
1326 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1327 if (ar.exception == null) {
1328 request.result = true;
1329 } else {
1330 request.result = false;
1331 if (ar.exception instanceof CommandException) {
1332 loge(command + ": CommandException: " + ar.exception);
1333 } else {
1334 loge(command + ": Unknown exception");
1335 }
1336 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001337 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 }
1340
1341 /**
1342 * Posts the specified command to be executed on the main thread,
1343 * waits for the request to complete, and returns the result.
1344 * @see #sendRequestAsync
1345 */
1346 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001347 return sendRequest(
1348 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001349 }
1350
1351 /**
1352 * Posts the specified command to be executed on the main thread,
1353 * waits for the request to complete, and returns the result.
1354 * @see #sendRequestAsync
1355 */
1356 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1357 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001358 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
1361 /**
1362 * Posts the specified command to be executed on the main thread,
1363 * waits for the request to complete, and returns the result.
1364 * @see #sendRequestAsync
1365 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001366 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001367 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001368 }
1369
1370 /**
1371 * Posts the specified command to be executed on the main thread,
1372 * waits for the request to complete, and returns the result.
1373 * @see #sendRequestAsync
1374 */
Nathan Harold92bed182018-10-12 18:16:49 -07001375 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1376 return sendRequest(command, argument, subId, null, workSource);
1377 }
1378
1379 /**
1380 * Posts the specified command to be executed on the main thread,
1381 * waits for the request to complete, and returns the result.
1382 * @see #sendRequestAsync
1383 */
1384 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1385 return sendRequest(
1386 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1387 }
1388
1389 /**
1390 * Posts the specified command to be executed on the main thread,
1391 * waits for the request to complete, and returns the result.
1392 * @see #sendRequestAsync
1393 */
1394 private Object sendRequest(
1395 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1397 throw new RuntimeException("This method will deadlock if called from the main thread.");
1398 }
1399
Nathan Harold92bed182018-10-12 18:16:49 -07001400 MainThreadRequest request = null;
1401 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1402 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1403 } else if (phone != null) {
1404 request = new MainThreadRequest(argument, phone, workSource);
1405 } else {
1406 request = new MainThreadRequest(argument, subId, workSource);
1407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 Message msg = mMainThreadHandler.obtainMessage(command, request);
1410 msg.sendToTarget();
1411
1412 // Wait for the request to complete
1413 synchronized (request) {
1414 while (request.result == null) {
1415 try {
1416 request.wait();
1417 } catch (InterruptedException e) {
1418 // Do nothing, go back and wait until the request is complete
1419 }
1420 }
1421 }
1422 return request.result;
1423 }
1424
1425 /**
1426 * Asynchronous ("fire and forget") version of sendRequest():
1427 * Posts the specified command to be executed on the main thread, and
1428 * returns immediately.
1429 * @see #sendRequest
1430 */
1431 private void sendRequestAsync(int command) {
1432 mMainThreadHandler.sendEmptyMessage(command);
1433 }
1434
1435 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001436 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001437 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001438 */
1439 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001440 sendRequestAsync(command, argument, null, null);
1441 }
1442
1443 /**
1444 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1445 * @see {@link #sendRequest(int,Object)}
1446 */
1447 private void sendRequestAsync(
1448 int command, Object argument, Phone phone, WorkSource workSource) {
1449 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001450 Message msg = mMainThreadHandler.obtainMessage(command, request);
1451 msg.sendToTarget();
1452 }
1453
1454 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 * Initialize the singleton PhoneInterfaceManager instance.
1456 * This is only done once, at startup, from PhoneApp.onCreate().
1457 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001458 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 synchronized (PhoneInterfaceManager.class) {
1460 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001461 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 } else {
1463 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1464 }
1465 return sInstance;
1466 }
1467 }
1468
1469 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001470 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001473 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001474 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1476 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001477 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001478 mTelephonySharedPreferences =
1479 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001480 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001481 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001482
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 publish();
1484 }
1485
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001486 private Phone getDefaultPhone() {
1487 Phone thePhone = getPhone(getDefaultSubscription());
1488 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1489 }
1490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 private void publish() {
1492 if (DBG) log("publish: " + this);
1493
Peter Wangc035ce42020-01-08 21:00:22 -08001494 TelephonyFrameworkInitializer
1495 .getTelephonyServiceManager()
1496 .getTelephonyServiceRegisterer()
1497 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499
Stuart Scott584921c2015-01-15 17:10:34 -08001500 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001501 if (request.phone != null) {
1502 return request.phone;
1503 } else {
1504 return getPhoneFromSubId(request.subId);
1505 }
1506 }
1507
1508 private Phone getPhoneFromSubId(int subId) {
1509 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1510 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001511 }
1512
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001513 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1514 Phone phone = getPhoneFromRequest(request);
1515 return phone == null ? null :
1516 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1517 }
1518
Wink Saville36469e72014-06-11 15:17:00 -07001519 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001521 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523
Naina Nallurid63128d2019-09-17 14:10:30 -07001524 private void sendEraseModemConfig(Phone phone) {
1525 if (phone != null) {
1526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1527 mApp, phone.getSubId(), "eraseModemConfig");
1528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1531 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1532 } finally {
1533 Binder.restoreCallingIdentity(identity);
1534 }
1535 }
1536 }
1537
Peter Wang44b186e2020-01-13 23:33:09 -08001538 private boolean isImsAvailableOnDevice() {
1539 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1540 if (pm == null) {
1541 // For some reason package manger is not available.. This will fail internally anyway,
1542 // so do not throw error and allow.
1543 return true;
1544 }
1545 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1546 }
1547
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 if (DBG) log("dial: " + number);
1554 // No permission check needed here: This is just a wrapper around the
1555 // ACTION_DIAL intent, which is available to any app since it puts up
1556 // the UI before it does anything.
1557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 String url = createTelUrl(number);
1561 if (url == null) {
1562 return;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001565 // PENDING: should we just silently fail if phone is offhook or ringing?
1566 PhoneConstants.State state = mCM.getState(subId);
1567 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1568 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1569 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1570 mApp.startActivity(intent);
1571 }
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 }
1575 }
1576
1577 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001578 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001579 }
1580
Wink Savilleb564aae2014-10-23 10:18:09 -07001581 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 if (DBG) log("call: " + number);
1583
1584 // This is just a wrapper around the ACTION_CALL intent, but we still
1585 // need to do a permission check since we're calling startActivity()
1586 // from the context of the phone app.
1587 enforceCallPermission();
1588
Jordan Liu1617b712019-07-10 15:06:26 -07001589 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 != AppOpsManager.MODE_ALLOWED) {
1591 return;
1592 }
1593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001594 final long identity = Binder.clearCallingIdentity();
1595 try {
1596 String url = createTelUrl(number);
1597 if (url == null) {
1598 return;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001601 boolean isValid = false;
1602 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1603 if (slist != null) {
1604 for (SubscriptionInfo subInfoRecord : slist) {
1605 if (subInfoRecord.getSubscriptionId() == subId) {
1606 isValid = true;
1607 break;
1608 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001609 }
Wink Saville08874612014-08-31 19:19:58 -07001610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001611 if (!isValid) {
1612 return;
1613 }
Wink Saville08874612014-08-31 19:19:58 -07001614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001615 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1616 intent.putExtra(SUBSCRIPTION_KEY, subId);
1617 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1618 mApp.startActivity(intent);
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
1621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
Wink Savilleb564aae2014-10-23 10:18:09 -07001624 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001625 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001626 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1627 }
1628
Wink Savilleb564aae2014-10-23 10:18:09 -07001629 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001630 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001631 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1632 }
1633
Wink Savilleb564aae2014-10-23 10:18:09 -07001634 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001636
1637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1640 checkSimPin.start();
1641 return checkSimPin.unlockSim(null, pin);
1642 } finally {
1643 Binder.restoreCallingIdentity(identity);
1644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 }
1646
Wink Savilleb564aae2014-10-23 10:18:09 -07001647 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001649
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1653 checkSimPuk.start();
1654 return checkSimPuk.unlockSim(puk, pin);
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
1657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001661 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 * a synchronous one.
1663 */
1664 private static class UnlockSim extends Thread {
1665
1666 private final IccCard mSimCard;
1667
1668 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001669 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1670 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671
1672 // For replies from SimCard interface
1673 private Handler mHandler;
1674
1675 // For async handler to identify request type
1676 private static final int SUPPLY_PIN_COMPLETE = 100;
1677
1678 public UnlockSim(IccCard simCard) {
1679 mSimCard = simCard;
1680 }
1681
1682 @Override
1683 public void run() {
1684 Looper.prepare();
1685 synchronized (UnlockSim.this) {
1686 mHandler = new Handler() {
1687 @Override
1688 public void handleMessage(Message msg) {
1689 AsyncResult ar = (AsyncResult) msg.obj;
1690 switch (msg.what) {
1691 case SUPPLY_PIN_COMPLETE:
1692 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1693 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001694 mRetryCount = msg.arg1;
1695 if (ar.exception != null) {
1696 if (ar.exception instanceof CommandException &&
1697 ((CommandException)(ar.exception)).getCommandError()
1698 == CommandException.Error.PASSWORD_INCORRECT) {
1699 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1700 } else {
1701 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1702 }
1703 } else {
1704 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 mDone = true;
1707 UnlockSim.this.notifyAll();
1708 }
1709 break;
1710 }
1711 }
1712 };
1713 UnlockSim.this.notifyAll();
1714 }
1715 Looper.loop();
1716 }
1717
1718 /*
1719 * Use PIN or PUK to unlock SIM card
1720 *
1721 * If PUK is null, unlock SIM card with PIN
1722 *
1723 * If PUK is not null, unlock SIM card with PUK and set PIN code
1724 */
Wink Saville9de0f752013-10-22 19:04:03 -07001725 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726
1727 while (mHandler == null) {
1728 try {
1729 wait();
1730 } catch (InterruptedException e) {
1731 Thread.currentThread().interrupt();
1732 }
1733 }
1734 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1735
1736 if (puk == null) {
1737 mSimCard.supplyPin(pin, callback);
1738 } else {
1739 mSimCard.supplyPuk(puk, pin, callback);
1740 }
1741
1742 while (!mDone) {
1743 try {
1744 Log.d(LOG_TAG, "wait for done");
1745 wait();
1746 } catch (InterruptedException e) {
1747 // Restore the interrupted status
1748 Thread.currentThread().interrupt();
1749 }
1750 }
1751 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001752 int[] resultArray = new int[2];
1753 resultArray[0] = mResult;
1754 resultArray[1] = mRetryCount;
1755 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757 }
1758
1759 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001760 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001761
1762 }
1763
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 // No permission check needed here: this call is harmless, and it's
1766 // needed for the ServiceState.requestStateUpdate() call (which is
1767 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 final Phone phone = getPhone(subId);
1771 if (phone != null) {
1772 phone.updateServiceLocation();
1773 }
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001779 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001780 @Override
1781 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001782 return isRadioOnWithFeature(callingPackage, null);
1783 }
1784
1785
1786 @Override
1787 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1788 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1789 callingFeatureId);
1790 }
1791
1792 @Deprecated
1793 @Override
1794 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1795 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001796 }
1797
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001799 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1800 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001802 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001803 return false;
1804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 return isRadioOnForSubscriber(subId);
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
1811 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001812 }
1813
1814 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 final Phone phone = getPhone(subId);
1818 if (phone != null) {
1819 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1820 } else {
1821 return false;
1822 }
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
1828 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001829 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
Wink Saville36469e72014-06-11 15:17:00 -07001831
Wink Savilleb564aae2014-10-23 10:18:09 -07001832 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone phone = getPhone(subId);
1838 if (phone != null) {
1839 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1840 }
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001843 }
Wink Saville36469e72014-06-11 15:17:00 -07001844 }
1845
1846 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001847 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone == null) {
1857 return false;
1858 }
1859 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1860 toggleRadioOnOffForSubscriber(subId);
1861 }
1862 return true;
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 }
Wink Saville36469e72014-06-11 15:17:00 -07001867
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001868 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001869 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001870 /*
1871 * If any of the Radios are available, it will need to be
1872 * shutdown. So return true if any Radio is available.
1873 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1877 Phone phone = PhoneFactory.getPhone(i);
1878 if (phone != null && phone.isRadioAvailable()) return true;
1879 }
1880 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1881 return false;
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001884 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001885 }
1886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001888 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001889 enforceModifyPermission();
1890
1891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1894 logv("Shutting down Phone " + i);
1895 shutdownRadioUsingPhoneId(i);
1896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001899 }
1900 }
1901
1902 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001903 Phone phone = PhoneFactory.getPhone(phoneId);
1904 if (phone != null && phone.isRadioAvailable()) {
1905 phone.shutdownRadio();
1906 }
1907 }
1908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911
1912 final long identity = Binder.clearCallingIdentity();
1913 try {
1914 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1915 if (defaultPhone != null) {
1916 defaultPhone.setRadioPower(turnOn);
1917 return true;
1918 } else {
1919 loge("There's no default phone.");
1920 return false;
1921 }
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001924 }
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
Wink Savilleb564aae2014-10-23 10:18:09 -07001927 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 final Phone phone = getPhone(subId);
1933 if (phone != null) {
1934 phone.setRadioPower(turnOn);
1935 return true;
1936 } else {
1937 return false;
1938 }
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Wink Saville36469e72014-06-11 15:17:00 -07001944 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 public boolean enableDataConnectivity() {
1947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948
1949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 int subId = mSubscriptionController.getDefaultDataSubId();
1952 final Phone phone = getPhone(subId);
1953 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001954 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 return true;
1956 } else {
1957 return false;
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Wink Saville36469e72014-06-11 15:17:00 -07001964 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 public boolean disableDataConnectivity() {
1967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968
1969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 int subId = mSubscriptionController.getDefaultDataSubId();
1972 final Phone phone = getPhone(subId);
1973 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001974 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 return true;
1976 } else {
1977 return false;
1978 }
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
Sanket Padawe356d7632015-06-22 14:03:32 -07001984 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001985 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 final Phone phone = getPhone(subId);
1989 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001990 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001991 } else {
1992 return false;
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 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002000 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002001 }
2002
pkanwarae03a6b2016-11-06 20:37:09 -08002003 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002004 enforceCallPermission();
2005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2009 return;
2010 }
2011 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2012 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2013 } finally {
2014 Binder.restoreCallingIdentity(identity);
2015 }
pkanwar32d516d2016-10-14 19:37:38 -07002016 };
2017
Wink Savilleb564aae2014-10-23 10:18:09 -07002018 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2024 return false;
2025 }
2026 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002033 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002034 }
2035
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002036 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2041 PhoneConstantConversions.convertCallState(phone.getState());
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 }
2046
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002048 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002049 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2050 }
2051
2052 @Override
2053 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 final long identity = Binder.clearCallingIdentity();
2055 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002056 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 if (phone != null) {
2058 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2059 } else {
2060 return PhoneConstantConversions.convertDataState(
2061 PhoneConstants.DataState.DISCONNECTED);
2062 }
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067
Sanket Padawe356d7632015-06-22 14:03:32 -07002068 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002069 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002070 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2071 }
2072
2073 @Override
2074 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 final long identity = Binder.clearCallingIdentity();
2076 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002077 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 if (phone != null) {
2079 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2080 } else {
2081 return TelephonyManager.DATA_ACTIVITY_NONE;
2082 }
2083 } finally {
2084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 }
2087
2088 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002089 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002090 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002091 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002092
2093 LocationAccessPolicy.LocationPermissionResult locationResult =
2094 LocationAccessPolicy.checkLocationPermission(mApp,
2095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2096 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002098 .setCallingPid(Binder.getCallingPid())
2099 .setCallingUid(Binder.getCallingUid())
2100 .setMethod("getCellLocation")
2101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2102 .build());
2103 switch (locationResult) {
2104 case DENIED_HARD:
2105 throw new SecurityException("Not allowed to access cell location");
2106 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002107 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2108 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002115 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002116 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Svetoslav64fad262015-04-14 14:35:21 -07002120 }
2121
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002123 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2124 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002125 if (!TextUtils.isEmpty(callingPackage)) {
2126 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2128 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002129 return "";
2130 }
2131 }
2132
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002133 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2134 // registered cell info, so return a NULL country instead.
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002137 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2138 // Get default phone in this case.
2139 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2140 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002141 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002142 // Todo: fix this when we can get the actual cellular network info when the device
2143 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002144 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002145 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2146 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002147 return "";
2148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002149 Phone phone = PhoneFactory.getPhone(phoneId);
2150 if (phone != null) {
2151 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002152 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153 if (sst != null) {
2154 LocaleTracker lt = sst.getLocaleTracker();
2155 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002156 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2157 return lt.getCurrentCountry();
2158 } else if (emergencyNumberTracker != null) {
2159 return emergencyNumberTracker.getEmergencyCountryIso();
2160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161 }
2162 }
2163 }
2164 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002168 }
2169
2170 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002172 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002173 }
2174
Sanket Padawe356d7632015-06-22 14:03:32 -07002175 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002176 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 mApp.enforceCallingOrSelfPermission(
2178 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002179
2180 final long identity = Binder.clearCallingIdentity();
2181 try {
2182 final Phone phone = getPhone(subId);
2183 if (phone != null) {
2184 phone.enableLocationUpdates();
2185 }
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190
2191 @Override
2192 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002193 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002197 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 mApp.enforceCallingOrSelfPermission(
2199 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200
2201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
2205 phone.disableLocationUpdates();
2206 }
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
Nathan Harold31d7ff32018-10-15 20:20:30 -07002212 /**
2213 * Returns the target SDK version number for a given package name.
2214 *
Nathan Haroldec184742019-07-10 17:04:16 -07002215 * This call MUST be invoked before clearing the calling UID.
2216 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002217 * @return target SDK if the package is found or INT_MAX.
2218 */
2219 private int getTargetSdk(String packageName) {
2220 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002221 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002222 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002223 if (ai != null) return ai.targetSdkVersion;
2224 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002225 loge("Failed to get package info for pkg="
2226 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002227 }
2228 return Integer.MAX_VALUE;
2229 }
2230
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 @Override
2232 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002233 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2234 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002235 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002236 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2237 throw new SecurityException(
2238 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2239 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002240
Jordan Liu1617b712019-07-10 15:06:26 -07002241 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2243 return null;
2244 }
Svetoslav64fad262015-04-14 14:35:21 -07002245
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002246 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002249 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250
Nathan Haroldf180aac2018-06-01 18:43:55 -07002251 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2252 for (CellInfo ci : info) {
2253 if (ci instanceof CellInfoGsm) {
2254 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2255 } else if (ci instanceof CellInfoWcdma) {
2256 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002259 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002262 private List<CellInfo> getCachedCellInfo() {
2263 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2264 for (Phone phone : PhoneFactory.getPhones()) {
2265 List<CellInfo> info = phone.getAllCellInfo();
2266 if (info != null) cellInfos.addAll(info);
2267 }
2268 return cellInfos;
2269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270
2271 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002272 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002273 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002274 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002275
2276 LocationAccessPolicy.LocationPermissionResult locationResult =
2277 LocationAccessPolicy.checkLocationPermission(mApp,
2278 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2279 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002280 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002281 .setCallingPid(Binder.getCallingPid())
2282 .setCallingUid(Binder.getCallingUid())
2283 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002284 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002285 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2286 .build());
2287 switch (locationResult) {
2288 case DENIED_HARD:
2289 throw new SecurityException("Not allowed to access cell info");
2290 case DENIED_SOFT:
2291 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002294 final int targetSdk = getTargetSdk(callingPackage);
2295 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2296 return getCachedCellInfo();
2297 }
2298
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002299 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2304 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002305 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002306 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 if (info != null) cellInfos.addAll(info);
2308 }
2309 return cellInfos;
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313 }
2314
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002315 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002316 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2317 String callingFeatureId) {
2318 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2319 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002320 }
2321
2322 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002323 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2324 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002325 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002326 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002327 }
2328
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002329 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2330 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002332 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002333
2334 LocationAccessPolicy.LocationPermissionResult locationResult =
2335 LocationAccessPolicy.checkLocationPermission(mApp,
2336 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2337 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002338 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002339 .setCallingPid(Binder.getCallingPid())
2340 .setCallingUid(Binder.getCallingUid())
2341 .setMethod("requestCellInfoUpdate")
2342 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2343 .build());
2344 switch (locationResult) {
2345 case DENIED_HARD:
2346 throw new SecurityException("Not allowed to access cell info");
2347 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002348 try {
2349 cb.onCellInfo(new ArrayList<CellInfo>());
2350 } catch (RemoteException re) {
2351 // Drop without consequences
2352 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002353 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002354 }
2355
Nathan Harolda939a962019-05-09 10:13:47 -07002356
2357 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002358 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2359
2360 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2361 }
2362
2363 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002365 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002366 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367
2368 final long identity = Binder.clearCallingIdentity();
2369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002370 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 } finally {
2372 Binder.restoreCallingIdentity(identity);
2373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 }
2375
Shishir Agrawala9f32182016-04-12 12:00:16 -07002376 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002377 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002378 Phone phone = PhoneFactory.getPhone(slotIndex);
2379 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002380 return null;
2381 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002382 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002383 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002384 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002385 return null;
2386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 return phone.getImei();
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002394 }
2395
2396 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002397 public String getTypeAllocationCodeForSlot(int slotIndex) {
2398 Phone phone = PhoneFactory.getPhone(slotIndex);
2399 String tac = null;
2400 if (phone != null) {
2401 String imei = phone.getImei();
2402 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2403 }
2404 return tac;
2405 }
2406
2407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002408 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002409 Phone phone = PhoneFactory.getPhone(slotIndex);
2410 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002411 return null;
2412 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002413
Jeff Davidson913390f2018-02-23 17:11:49 -08002414 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002415 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002416 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002417 return null;
2418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 return phone.getMeid();
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Jack Yu2af8d712017-03-15 17:14:14 -07002426 }
2427
2428 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002429 public String getManufacturerCodeForSlot(int slotIndex) {
2430 Phone phone = PhoneFactory.getPhone(slotIndex);
2431 String manufacturerCode = null;
2432 if (phone != null) {
2433 String meid = phone.getMeid();
2434 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2435 }
2436 return manufacturerCode;
2437 }
2438
2439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002440 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2441 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002442 Phone phone = PhoneFactory.getPhone(slotIndex);
2443 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002444 return null;
2445 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002446 int subId = phone.getSubId();
2447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002448 mApp, subId, callingPackage, callingFeatureId,
2449 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002450 return null;
2451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 return phone.getDeviceSvn();
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
2458 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002459 }
2460
fionaxu43304da2017-11-27 22:51:16 -08002461 @Override
2462 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 final Phone phone = getPhone(subId);
2466 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
2469 }
fionaxu43304da2017-11-27 22:51:16 -08002470 }
2471
2472 @Override
2473 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 return phone == null ? null : phone.getCarrierName();
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
2480 }
fionaxu43304da2017-11-27 22:51:16 -08002481 }
2482
calvinpanffe225e2018-11-01 19:43:06 +08002483 @Override
chen xu0026ca62019-03-06 15:28:50 -08002484 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 final Phone phone = getPhone(subId);
2488 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002489 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
2493 }
2494
2495 @Override
chen xu0026ca62019-03-06 15:28:50 -08002496 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002500 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002501 } finally {
2502 Binder.restoreCallingIdentity(identity);
2503 }
2504 }
2505
chen xu651eec72018-11-11 19:03:44 -08002506 @Override
chen xu864e11c2018-12-06 22:10:03 -08002507 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2508 if (!isSubscriptionMccMnc) {
2509 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2510 }
chen xu651eec72018-11-11 19:03:44 -08002511 final Phone phone = PhoneFactory.getPhone(slotIndex);
2512 if (phone == null) {
2513 return TelephonyManager.UNKNOWN_CARRIER_ID;
2514 }
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2518 } finally {
2519 Binder.restoreCallingIdentity(identity);
2520 }
2521 }
2522
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 //
2524 // Internal helper methods.
2525 //
2526
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002527 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2529 *
2530 * @throws SecurityException if the caller does not have the required permission
2531 */
2532 private void enforceModifyPermission() {
2533 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2534 }
2535
Shuo Qiancd19c462020-01-16 20:51:11 -08002536 /**
2537 * Make sure the caller is system.
2538 *
2539 * @throws SecurityException if the caller is not system.
2540 */
2541 private void enforceSystemCaller() {
2542 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2543 throw new SecurityException("Caller must be system");
2544 }
2545 }
2546
Shuo Qian3b6ee772019-11-13 17:43:31 -08002547 private void enforceActiveEmergencySessionPermission() {
2548 mApp.enforceCallingOrSelfPermission(
2549 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2550 }
2551
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 /**
2553 * Make sure the caller has the CALL_PHONE permission.
2554 *
2555 * @throws SecurityException if the caller does not have the required permission
2556 */
2557 private void enforceCallPermission() {
2558 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2559 }
2560
paulhu5a773602019-08-23 19:17:33 +08002561 private void enforceSettingsPermission() {
2562 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002563 }
2564
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 private String createTelUrl(String number) {
2566 if (TextUtils.isEmpty(number)) {
2567 return null;
2568 }
2569
Jake Hambye994d462014-02-03 13:10:13 -08002570 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 }
2572
Ihab Awadf9e92732013-12-05 18:02:52 -08002573 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2575 }
2576
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002577 private static void logv(String msg) {
2578 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2579 }
2580
Ihab Awadf9e92732013-12-05 18:02:52 -08002581 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2583 }
2584
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002585 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002587 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002591 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = PhoneFactory.getPhone(slotIndex);
2595 if (phone == null) {
2596 return PhoneConstants.PHONE_TYPE_NONE;
2597 } else {
2598 return phone.getPhoneType();
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
2605 /**
2606 * Returns the CDMA ERI icon index to display
2607 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002609 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2610 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2611 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002612 }
2613
Sanket Padawe356d7632015-06-22 14:03:32 -07002614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002615 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2616 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002618 mApp, subId, callingPackage, callingFeatureId,
2619 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002620 return -1;
2621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 final Phone phone = getPhone(subId);
2626 if (phone != null) {
2627 return phone.getCdmaEriIconIndex();
2628 } else {
2629 return -1;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
2636 /**
2637 * Returns the CDMA ERI icon mode,
2638 * 0 - ON
2639 * 1 - FLASHING
2640 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002642 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2643 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2644 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002645 }
2646
Sanket Padawe356d7632015-06-22 14:03:32 -07002647 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002648 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2649 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002651 mApp, subId, callingPackage, callingFeatureId,
2652 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 return -1;
2654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(subId);
2659 if (phone != null) {
2660 return phone.getCdmaEriIconMode();
2661 } else {
2662 return -1;
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 }
2668
2669 /**
2670 * Returns the CDMA ERI text,
2671 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002673 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2674 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2675 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002676 }
2677
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002679 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2680 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002682 mApp, subId, callingPackage, callingFeatureId,
2683 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002684 return null;
2685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 final Phone phone = getPhone(subId);
2690 if (phone != null) {
2691 return phone.getCdmaEriText();
2692 } else {
2693 return null;
2694 }
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
2700 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002701 * Returns the CDMA MDN.
2702 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002703 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002704 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2706 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
2708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002711 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 return phone.getLine1Number();
2713 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002714 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 return null;
2716 }
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002719 }
2720 }
2721
2722 /**
2723 * Returns the CDMA MIN.
2724 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002726 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2728 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729
2730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 final Phone phone = getPhone(subId);
2733 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2734 return phone.getCdmaMin();
2735 } else {
2736 return null;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002740 }
2741 }
2742
Hall Liud892bec2018-11-30 14:51:45 -08002743 @Override
2744 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2745 INumberVerificationCallback callback, String callingPackage) {
2746 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2747 != PERMISSION_GRANTED) {
2748 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2749 }
2750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2751
2752 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2753 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2754 throw new SecurityException("Calling package must be configured in the device config");
2755 }
2756
2757 if (range == null) {
2758 throw new NullPointerException("Range must be non-null");
2759 }
2760
2761 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002762 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002763
2764 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2765 }
2766
Junda Liuca05d5d2014-08-14 22:36:34 -07002767 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 * Returns true if CDMA provisioning needs to run.
2769 */
2770 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002773 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 } finally {
2775 Binder.restoreCallingIdentity(identity);
2776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
2779 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002780 * Sets the voice mail number of a given subId.
2781 */
2782 @Override
2783 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002784 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2785 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786
2787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2790 new Pair<String, String>(alphaTag, number), new Integer(subId));
2791 return success;
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002795 }
2796
Ta-wei Yen87c49842016-05-13 21:19:52 -07002797 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002798 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002800 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2801 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002802 if (!TextUtils.equals(callingPackage, systemDialer)) {
2803 throw new SecurityException("caller must be system dialer");
2804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2809 if (phoneAccountHandle == null) {
2810 return null;
2811 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002812 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 } finally {
2814 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002815 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002816 }
2817
2818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002819 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2820 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002821 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002823 mApp, subId, callingPackage, callingFeatureId,
2824 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002825 return null;
2826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002828 final long identity = Binder.clearCallingIdentity();
2829 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002830 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002831 } finally {
2832 Binder.restoreCallingIdentity(identity);
2833 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002834 }
2835
2836 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002837 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2838 VisualVoicemailSmsFilterSettings settings) {
2839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002844 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002848 }
2849
2850 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002851 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 } finally {
2859 Binder.restoreCallingIdentity(identity);
2860 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002861 }
2862
2863 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002864 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2865 String callingPackage, int subId) {
2866 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867
2868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002871 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 } finally {
2873 Binder.restoreCallingIdentity(identity);
2874 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002875 }
2876
2877 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002878 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002879 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002884 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002888 }
2889
2890 @Override
2891 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2892 String number, int port, String text, PendingIntent sentIntent) {
2893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002894 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002895 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002896 SmsController smsController = PhoneFactory.getSmsController();
2897 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2898 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002899 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002900
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002901 /**
fionaxu0152e512016-11-14 13:36:14 -08002902 * Sets the voice activation state of a given subId.
2903 */
2904 @Override
2905 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2907 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908
2909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 if (phone != null) {
2913 phone.setVoiceActivationState(activationState);
2914 } else {
2915 loge("setVoiceActivationState fails with invalid subId: " + subId);
2916 }
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002919 }
2920 }
2921
2922 /**
2923 * Sets the data activation state of a given subId.
2924 */
2925 @Override
2926 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2928 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 final Phone phone = getPhone(subId);
2933 if (phone != null) {
2934 phone.setDataActivationState(activationState);
2935 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002936 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 }
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002940 }
2941 }
2942
2943 /**
2944 * Returns the voice activation state of a given subId.
2945 */
2946 @Override
2947 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002948 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949
fionaxu0152e512016-11-14 13:36:14 -08002950 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 if (phone != null) {
2954 return phone.getVoiceActivationState();
2955 } else {
2956 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2957 }
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002960 }
2961 }
2962
2963 /**
2964 * Returns the data activation state of a given subId.
2965 */
2966 @Override
2967 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969
fionaxu0152e512016-11-14 13:36:14 -08002970 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 if (phone != null) {
2974 return phone.getDataActivationState();
2975 } else {
2976 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002980 }
2981 }
2982
2983 /**
Wink Saville36469e72014-06-11 15:17:00 -07002984 * Returns the unread count of voicemails for a subId
2985 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002987 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2988 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002990 mApp, subId, callingPackage, callingFeatureId,
2991 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002992 return 0;
2993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 final Phone phone = getPhone(subId);
2997 if (phone != null) {
2998 return phone.getVoiceMessageCount();
2999 } else {
3000 return 0;
3001 }
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 }
3006
3007 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003008 * returns true, if the device is in a state where both voice and data
3009 * are supported simultaneously. This can change based on location or network condition.
3010 */
3011 @Override
3012 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 final Phone phone = getPhone(subId);
3016 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003020 }
3021
3022 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003023 * Send the dialer code if called from the current default dialer or the caller has
3024 * carrier privilege.
3025 * @param inputCode The dialer code to send
3026 */
3027 @Override
3028 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003029 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003031 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3032 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003033 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003034 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003035 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003040 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
fionaxu235cc5e2017-03-06 22:25:57 -08003044 }
3045
Pengquan Menga1bb6272018-09-06 09:59:22 -07003046 @Override
3047 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003048 TelephonyPermissions
3049 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3050 mApp, subId, "getNetworkSelectionMode");
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 if (!isActiveSubscription(subId)) {
3054 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3055 }
3056 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003059 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003060 }
3061
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08003063 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3064 String callingFeatureId) {
3065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3066 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3067 return null;
3068 }
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 return mPhoneConfigurationManager.getStaticPhoneCapability();
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003078 public boolean isInEmergencySmsMode() {
3079 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 for (Phone phone : PhoneFactory.getPhones()) {
3083 if (phone.isInEmergencySmsMode()) {
3084 return true;
3085 }
3086 }
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 return false;
3091 }
3092
shilu366312e2019-12-17 09:28:10 -08003093 /**
3094 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3095 * @param subId The subscription to use to check the configuration.
3096 * @param c The callback that will be used to send the result.
3097 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003098 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003099 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3100 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003101 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003102 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003103
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003104 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3105 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3106 "IMS not available on device.");
3107 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 final long token = Binder.clearCallingIdentity();
3109 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003110 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003111 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003113 } catch (ImsException e) {
3114 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 } finally {
3116 Binder.restoreCallingIdentity(token);
3117 }
3118 }
3119
shilu366312e2019-12-17 09:28:10 -08003120 /**
3121 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3122 * @param subId The subscription to use to check the configuration.
3123 * @param c The callback that will be used to send the result.
3124 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003126 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003127 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003128 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003129 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3130 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3131 }
Meng Wangafbc5852019-09-19 17:37:13 -07003132 final long token = Binder.clearCallingIdentity();
3133 try {
3134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3135 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3136 .removeRegistrationCallbackForSubscription(c, subId);
3137 } catch (ImsException e) {
3138 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3139 + "is inactive, ignoring unregister.");
3140 // If the subscription is no longer active, just return, since the callback
3141 // will already have been removed internally.
3142 } finally {
3143 Binder.restoreCallingIdentity(token);
3144 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 }
3146
Brad Ebingera34a6c22019-10-22 17:36:18 -07003147 /**
3148 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3149 */
3150 @Override
3151 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3152 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3153 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3154 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3155 "IMS not available on device.");
3156 }
3157 final long token = Binder.clearCallingIdentity();
3158 try {
3159 Phone phone = getPhone(subId);
3160 if (phone == null) {
3161 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3162 + subId + "'");
3163 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3164 }
3165 phone.getImsRegistrationState(regState -> {
3166 try {
3167 consumer.accept((regState == null)
3168 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3169 } catch (RemoteException e) {
3170 // Ignore if the remote process is no longer available to call back.
3171 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3172 }
3173 });
3174 } finally {
3175 Binder.restoreCallingIdentity(token);
3176 }
3177 }
3178
3179 /**
3180 * Get the transport type for the IMS service registration state.
3181 */
3182 @Override
3183 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003184 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebingera34a6c22019-10-22 17:36:18 -07003185 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3186 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3187 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3188 "IMS not available on device.");
3189 }
3190 final long token = Binder.clearCallingIdentity();
3191 try {
3192 Phone phone = getPhone(subId);
3193 if (phone == null) {
3194 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3195 + subId + "'");
3196 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3197 }
3198 phone.getImsRegistrationTech(regTech -> {
3199 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3200 int regTechConverted = (regTech == null)
3201 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3202 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3203 regTechConverted);
3204 try {
3205 consumer.accept(regTechConverted);
3206 } catch (RemoteException e) {
3207 // Ignore if the remote process is no longer available to call back.
3208 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3209 }
3210 });
3211 } finally {
3212 Binder.restoreCallingIdentity(token);
3213 }
3214 }
3215
shilu366312e2019-12-17 09:28:10 -08003216 /**
3217 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3218 * @param subId The subscription to use to check the configuration.
3219 * @param c The callback that will be used to send the result.
3220 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003222 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3223 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003224 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003225 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003226 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3227 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3228 "IMS not available on device.");
3229 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3231 final long token = Binder.clearCallingIdentity();
3232 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003233 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003235 } catch (ImsException e) {
3236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 } finally {
3238 Binder.restoreCallingIdentity(token);
3239 }
3240 }
3241
shilu366312e2019-12-17 09:28:10 -08003242 /**
3243 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3244 * @param subId The subscription to use to check the configuration.
3245 * @param c The callback that will be used to send the result.
3246 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003248 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003249 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003250 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003251 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3252 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3253 }
Meng Wangafbc5852019-09-19 17:37:13 -07003254
3255 final long token = Binder.clearCallingIdentity();
3256 try {
3257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3258 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003259 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003260 } catch (ImsException e) {
3261 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3262 + "is inactive, ignoring unregister.");
3263 // If the subscription is no longer active, just return, since the callback
3264 // will already have been removed internally.
3265 } finally {
3266 Binder.restoreCallingIdentity(token);
3267 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 }
3269
3270 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003271 public boolean isCapable(int subId, int capability, int regTech) {
3272 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3274 final long token = Binder.clearCallingIdentity();
3275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003276 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003278 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3280 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003281 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003282 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3283 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 } finally {
3285 Binder.restoreCallingIdentity(token);
3286 }
3287 }
3288
3289 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003290 public boolean isAvailable(int subId, int capability, int regTech) {
3291 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 final long token = Binder.clearCallingIdentity();
3293 try {
3294 Phone phone = getPhone(subId);
3295 if (phone == null) return false;
3296 return phone.isImsCapabilityAvailable(capability, regTech);
3297 } finally {
3298 Binder.restoreCallingIdentity(token);
3299 }
3300 }
3301
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003302 /**
3303 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3304 * subscription.
3305 * @param subId The subscription to use to check the configuration.
3306 * @param callback The callback that will be used to send the result.
3307 * @param capability The MmTelFeature capability that will be used to send the result.
3308 * @param transportType The transport type of the MmTelFeature capability.
3309 */
3310 @Override
3311 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3312 int transportType) {
3313 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3316 "IMS not available on device.");
3317 }
3318 final long token = Binder.clearCallingIdentity();
3319 try {
3320 int slotId = getSlotIndex(subId);
3321 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3322 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3323 + subId + "'");
3324 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3325 }
3326 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3327 transportType, aBoolean -> {
3328 try {
3329 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3330 } catch (RemoteException e) {
3331 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3332 + "running. Ignore");
3333 }
3334 });
3335 } finally {
3336 Binder.restoreCallingIdentity(token);
3337 }
3338 }
3339
shilu366312e2019-12-17 09:28:10 -08003340 /**
3341 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3342 * @param subId The subscription to use to check the configuration.
3343 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 @Override
3345 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003346 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3347 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3348
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3350 final long token = Binder.clearCallingIdentity();
3351 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003354 } catch (ImsException e) {
3355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 } finally {
3357 Binder.restoreCallingIdentity(token);
3358 }
3359 }
3360
3361 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003362 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003364 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003368 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003370 } catch (ImsException e) {
3371 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003372 } finally {
3373 Binder.restoreCallingIdentity(identity);
3374 }
3375 }
3376
shilu366312e2019-12-17 09:28:10 -08003377 /**
3378 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3379 * @param subId The subscription to use to check the configuration.
3380 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003382 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003383 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003384 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003388 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3389 } catch (ImsException e) {
3390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
3396 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003397 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003399 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003403 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003404 } catch (ImsException e) {
3405 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 } finally {
3407 Binder.restoreCallingIdentity(identity);
3408 }
3409 }
3410
shilu366312e2019-12-17 09:28:10 -08003411 /**
3412 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3413 * @param subId The subscription to use to check the configuration.
3414 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 @Override
3416 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003417 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003418 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003422 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003423 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003424 } catch (ImsException e) {
3425 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
3429 }
3430
3431 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003432 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003434 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003439 } catch (ImsException e) {
3440 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
3444 }
3445
shilu366312e2019-12-17 09:28:10 -08003446 /**
3447 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3448 * @param subId The subscription to use to check the configuration.
3449 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003450 @Override
3451 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003452 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003453 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003457 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003459 } catch (ImsException e) {
3460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
3464 }
3465
3466 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003467 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003469 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003473 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003474 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003475 } catch (ImsException e) {
3476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
3480 }
3481
3482 @Override
3483 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3485 "setVoWiFiNonPersistent");
3486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003489 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003490 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003491 } catch (ImsException e) {
3492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
shilu366312e2019-12-17 09:28:10 -08003498 /**
3499 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3500 * @param subId The subscription to use to check the configuration.
3501 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 @Override
3503 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003504 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003511 } catch (ImsException e) {
3512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 } finally {
3514 Binder.restoreCallingIdentity(identity);
3515 }
3516 }
3517
3518 @Override
3519 public void setVoWiFiModeSetting(int subId, int mode) {
3520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3521 "setVoWiFiModeSetting");
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003525 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003527 } catch (ImsException e) {
3528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
3532 }
3533
3534 @Override
3535 public int getVoWiFiRoamingModeSetting(int subId) {
3536 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003540 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003542 } catch (ImsException e) {
3543 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
3547 }
3548
3549 @Override
3550 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3552 "setVoWiFiRoamingModeSetting");
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003556 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003558 } catch (ImsException e) {
3559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
3563 }
3564
3565 @Override
3566 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3568 "setRttCapabilityEnabled");
3569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003572 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3573 } catch (ImsException e) {
3574 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
shilu366312e2019-12-17 09:28:10 -08003580 /**
3581 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3582 * @param subId The subscription to use to check the configuration.
3583 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 @Override
3585 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003586 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003593 } catch (ImsException e) {
3594 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003600 @Override
3601 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3602 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003605 if (!isImsAvailableOnDevice()) {
3606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3607 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003608 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003610 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003611 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003612 } catch (ImsException e) {
3613 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
3619 @Override
3620 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3621 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3622 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3624 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3625 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003626 try {
3627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003628 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003629 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003630 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003631 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3632 + "is inactive, ignoring unregister.");
3633 // If the subscription is no longer active, just return, since the callback will already
3634 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
3638 }
3639
allenwtsu99c623b2020-01-03 18:24:23 +08003640
3641 private void checkModifyPhoneStatePermission(int subId, String message) {
3642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3643 message);
3644 }
3645
3646 private boolean isImsProvisioningRequired(int subId, int capability,
3647 boolean isMmtelCapability) {
3648 Phone phone = getPhone(subId);
3649 if (phone == null) {
3650 loge("phone instance null for subid " + subId);
3651 return false;
3652 }
3653 if (isMmtelCapability) {
3654 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3655 return false;
3656 }
3657 } else {
3658 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3659 return false;
3660 }
3661 }
3662 return true;
3663 }
3664
3665 @Override
3666 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3667 boolean isProvisioned) {
3668 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3673 if (!isImsProvisioningRequired(subId, capability, false)) {
3674 return;
3675 }
3676
3677 // this capability requires provisioning, route to the correct API.
3678 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3679 switch (capability) {
3680 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3681 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3682 ims.setEabProvisioned(isProvisioned);
3683 break;
3684 default: {
3685 throw new IllegalArgumentException("Tried to set provisioning for "
3686 + "rcs capability '" + capability + "', which does not require "
3687 + "provisioning.");
3688 }
3689 }
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
3693
3694 }
3695
3696
3697 @Override
3698 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3699 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3703 if (!isImsProvisioningRequired(subId, capability, false)) {
3704 return true;
3705 }
3706
3707 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3708 switch (capability) {
3709 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3710 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3711 return ims.isEabProvisionedOnDevice();
3712
3713 default: {
3714 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3715 + "capability '" + capability + "', which does not require "
3716 + "provisioning.");
3717 }
3718 }
3719
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003725 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3727 boolean isProvisioned) {
3728 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3729 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3730 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3731 }
allenwtsu99c623b2020-01-03 18:24:23 +08003732 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003736 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003737 return;
3738 }
3739
3740 // this capability requires provisioning, route to the correct API.
3741 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3742 switch (capability) {
3743 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3744 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3745 ims.setVolteProvisioned(isProvisioned);
3746 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3747 ims.setWfcProvisioned(isProvisioned);
3748 }
3749 break;
3750 }
3751 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3752 // There is currently no difference in VT provisioning type.
3753 ims.setVtProvisioned(isProvisioned);
3754 break;
3755 }
3756 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3757 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3758 // change the capability of the feature instead if needed.
3759 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3760 == isProvisioned) {
3761 // No change in provisioning.
3762 return;
3763 }
3764 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3765 try {
3766 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003767 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003768 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3769 + ", Exception" + e.getMessage());
3770 }
3771 break;
3772 }
3773 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003774 throw new IllegalArgumentException("Tried to set provisioning for "
3775 + "MmTel capability '" + capability + "', which does not require "
3776 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003777 }
3778 }
3779
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
3783 }
3784
3785 @Override
3786 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3787 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3788 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3789 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3790 }
3791 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003795 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003796 return true;
3797 }
3798
3799 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3800 switch (capability) {
3801 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3802 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3803 return ims.isVolteProvisionedOnDevice();
3804 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3805 return ims.isWfcProvisionedOnDevice();
3806 }
3807 // This should never happen, since we are checking tech above to make sure it
3808 // is either LTE or IWLAN.
3809 throw new IllegalArgumentException("Invalid radio technology for voice "
3810 + "capability.");
3811 }
3812 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3813 // There is currently no difference in VT provisioning type.
3814 return ims.isVtProvisionedOnDevice();
3815 }
3816 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3817 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3818 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3819 }
3820 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003821 throw new IllegalArgumentException(
3822 "Tried to get provisioning for MmTel capability '" + capability
3823 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003824 }
3825 }
3826
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
3830 }
3831
3832 @Override
3833 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3834 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3835 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3836 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3837 }
3838 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3839 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3840 return (provisionedBits & capability) > 0;
3841 }
3842
3843 @Override
3844 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3845 boolean isProvisioned) {
3846 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3847 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3848 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3849 }
3850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3851 "setProvisioningStatusForCapability");
3852 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3853 // If the current provisioning status for capability already matches isProvisioned,
3854 // do nothing.
3855 if (((provisionedBits & capability) > 0) == isProvisioned) {
3856 return;
3857 }
3858 if (isProvisioned) {
3859 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3860 } else {
3861 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3862 }
3863 }
3864
3865 /**
3866 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3867 * technology. The bitfield should mirror the bitfield defined by
3868 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3869 */
3870 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3871 String key = getMmTelProvisioningKey(subId, tech);
3872 // Default is no capabilities are provisioned.
3873 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3874 }
3875
3876 /**
3877 * Sets the MmTel capability provisioning bitfield (defined by
3878 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3879 * technology specified.
3880 *
3881 * Note: This is a synchronous command and should not be called on UI thread.
3882 */
3883 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3884 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3885 String key = getMmTelProvisioningKey(subId, tech);
3886 editor.putInt(key, newField);
3887 editor.commit();
3888 }
3889
3890 private static String getMmTelProvisioningKey(int subId, int tech) {
3891 // resulting key is provision_ims_mmtel_{subId}_{tech}
3892 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3893 }
3894
3895 /**
3896 * Query CarrierConfig to see if the specified capability requires provisioning for the
3897 * carrier associated with the subscription id.
3898 */
3899 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3900 int capability) {
3901 CarrierConfigManager configManager = new CarrierConfigManager(context);
3902 PersistableBundle c = configManager.getConfigForSubId(subId);
3903 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003904 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003905 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3906 false);
3907 boolean requireVoiceVtProvisioning = c.getBoolean(
3908 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3909
3910 // First check to make sure that the capability requires provisioning.
3911 switch (capability) {
3912 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3913 // intentional fallthrough
3914 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3915 if (requireVoiceVtProvisioning) {
3916 // Voice and Video requires provisioning
3917 return true;
3918 }
3919 break;
3920 }
3921 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3922 if (requireUtProvisioning) {
3923 // UT requires provisioning
3924 return true;
3925 }
3926 break;
3927 }
3928 }
3929 return false;
3930 }
3931
allenwtsu99c623b2020-01-03 18:24:23 +08003932 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3933 int capability) {
3934 CarrierConfigManager configManager = new CarrierConfigManager(context);
3935 PersistableBundle c = configManager.getConfigForSubId(subId);
3936
3937 boolean requireRcsProvisioning = c.getBoolean(
3938 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3939
3940 // First check to make sure that the capability requires provisioning.
3941 switch (capability) {
3942 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3943 // intentional fallthrough
3944 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3945 if (requireRcsProvisioning) {
3946 // OPTION or PRESENCE requires provisioning
3947 return true;
3948 }
3949 break;
3950 }
3951 }
3952 return false;
3953 }
3954
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003955 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003956 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003957 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3958 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3959 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003960 enforceReadPrivilegedPermission("getImsProvisioningInt");
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003964 int slotId = getSlotIndex(subId);
3965 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3966 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3967 + subId + "' for key:" + key);
3968 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3969 }
3970 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003971 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003972 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3973 + subId + "' for key:" + key);
3974 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
3978 }
3979
3980 @Override
3981 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003982 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3983 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3984 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003985 enforceReadPrivilegedPermission("getImsProvisioningString");
3986 final long identity = Binder.clearCallingIdentity();
3987 try {
3988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003989 int slotId = getSlotIndex(subId);
3990 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3991 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3992 + subId + "' for key:" + key);
3993 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3994 }
3995 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003997 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3998 + subId + "' for key:" + key);
3999 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
4003 }
4004
4005 @Override
4006 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4008 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4009 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4011 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004012 final long identity = Binder.clearCallingIdentity();
4013 try {
4014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004015 int slotId = getSlotIndex(subId);
4016 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4017 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4018 + subId + "' for key:" + key);
4019 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4020 }
4021 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004022 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004023 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4024 + "' for key:" + key);
4025 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
4029 }
4030
4031 @Override
4032 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004033 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4034 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4035 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4037 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004041 int slotId = getSlotIndex(subId);
4042 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4043 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4044 + subId + "' for key:" + key);
4045 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4046 }
4047 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004048 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004049 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4050 + "' for key:" + key);
4051 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
4055 }
4056
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004057 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 int slotId = SubscriptionManager.getSlotIndex(subId);
4059 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004060 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4061 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 }
4063 return slotId;
4064 }
4065
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004066 private int getSlotIndex(int subId) {
4067 int slotId = SubscriptionManager.getSlotIndex(subId);
4068 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4069 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4070 }
4071 return slotId;
4072 }
4073
Wink Saville36469e72014-06-11 15:17:00 -07004074 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004075 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004076 */
4077 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004078 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4079 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004080 final int targetSdk = getTargetSdk(callingPackage);
4081 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004082 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004083 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004084 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004085 mApp, subId, callingPackage, callingFeatureId,
4086 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4088 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 final Phone phone = getPhone(subId);
4093 if (phone != null) {
4094 return phone.getServiceState().getDataNetworkType();
4095 } else {
4096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4097 }
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004101 }
4102
4103 /**
4104 * Returns the data network type
4105 */
4106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004107 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4108 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4109 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004110 }
4111
4112 /**
4113 * Returns the data network type for a subId
4114 */
4115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004116 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4117 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004119 mApp, subId, callingPackage, callingFeatureId,
4120 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004121 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4122 }
4123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 final Phone phone = getPhone(subId);
4127 if (phone != null) {
4128 return phone.getServiceState().getDataNetworkType();
4129 } else {
4130 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4131 }
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004135 }
4136
4137 /**
Wink Saville36469e72014-06-11 15:17:00 -07004138 * Returns the Voice network type for a subId
4139 */
4140 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004141 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4142 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004144 mApp, subId, callingPackage, callingFeatureId,
4145 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4147 }
4148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 final Phone phone = getPhone(subId);
4152 if (phone != null) {
4153 return phone.getServiceState().getVoiceNetworkType();
4154 } else {
4155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4156 }
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004160 }
4161
4162 /**
4163 * @return true if a ICC card is present
4164 */
4165 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004166 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004167 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4168 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004169 }
4170
4171 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004172 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004173 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004174 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004175 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 final Phone phone = PhoneFactory.getPhone(slotIndex);
4179 if (phone != null) {
4180 return phone.getIccCard().hasIccCard();
4181 } else {
4182 return false;
4183 }
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004187 }
4188
4189 /**
4190 * Return if the current radio is LTE on CDMA. This
4191 * is a tri-state return value as for a period of time
4192 * the mode may be unknown.
4193 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004194 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004195 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004196 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004197 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004199 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4200 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4201 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004202 }
4203
Sanket Padawe356d7632015-06-22 14:03:32 -07004204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004205 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4206 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004207 try {
4208 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4209 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004210 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4211 }
4212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 final Phone phone = getPhone(subId);
4216 if (phone == null) {
4217 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4218 } else {
4219 return phone.getLteOnCdmaMode();
4220 }
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004223 }
Wink Saville36469e72014-06-11 15:17:00 -07004224 }
4225
Wink Saville36469e72014-06-11 15:17:00 -07004226 /**
4227 * {@hide}
4228 * Returns Default subId, 0 in the case of single standby.
4229 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004230 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004231 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004232 }
4233
Shishir Agrawala9f32182016-04-12 12:00:16 -07004234 private int getSlotForDefaultSubscription() {
4235 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4236 }
4237
Wink Savilleb564aae2014-10-23 10:18:09 -07004238 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004239 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004240 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004241
Pengquan Menge92a50d2018-09-21 15:54:48 -07004242 private boolean isActiveSubscription(int subId) {
4243 return mSubscriptionController.isActiveSubId(subId);
4244 }
4245
Ihab Awadf2177b72013-11-25 13:33:23 -08004246 /**
4247 * @see android.telephony.TelephonyManager.WifiCallingChoices
4248 */
4249 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 final long identity = Binder.clearCallingIdentity();
4251 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4254 getWhenToMakeWifiCallsDefaultPreference());
4255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004258 }
4259
4260 /**
4261 * @see android.telephony.TelephonyManager.WifiCallingChoices
4262 */
4263 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004267 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004272 }
4273
Sailesh Nepald1e68152013-12-12 19:08:02 -08004274 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004275 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004276 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004277 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004278
Jordan Liu4c733742019-02-28 12:03:40 -08004279 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4280 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4281 if (phoneId == -1) {
4282 throw new IllegalArgumentException("Given slot index: " + slotIndex
4283 + " does not correspond to an active phone");
4284 }
4285 return PhoneFactory.getPhone(phoneId);
4286 }
4287
Shishir Agrawal566b7612013-10-28 14:41:00 -07004288 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004289 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4290 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4292 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004294 if (DBG) {
4295 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4296 }
4297 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4298 p2);
4299 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004300
Jordan Liu4c733742019-02-28 12:03:40 -08004301
4302 @Override
4303 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4304 int slotIndex, String callingPackage, String aid, int p2) {
4305 enforceModifyPermission();
4306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4307 if (DBG) {
4308 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4309 }
4310 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4311 callingPackage, aid, p2);
4312 }
4313
4314 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4315 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 if (TextUtils.equals(ISDR_AID, aid)) {
4319 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004320 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4321 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 if (bestComponent == null
4323 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4324 loge("The calling package is not allowed to access ISD-R.");
4325 throw new SecurityException(
4326 "The calling package is not allowed to access ISD-R.");
4327 }
Derek Tan740e1672017-06-27 14:56:27 -07004328 }
Derek Tan740e1672017-06-27 14:56:27 -07004329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004331 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4332 null /* workSource */);
4333 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 return response;
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004338 }
4339
4340 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004341 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4343 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004344 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4345 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4346 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004347
Jordan Liu4c733742019-02-28 12:03:40 -08004348 @Override
4349 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4350 enforceModifyPermission();
4351 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4352 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4353 channel);
4354 }
4355
4356 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 if (channel < 0) {
4360 return false;
4361 }
Jordan Liu4c733742019-02-28 12:03:40 -08004362 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4363 null /* workSource */);
4364 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 return success;
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004369 }
4370
4371 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004372 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004373 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4375 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004376 if (DBG) {
4377 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4378 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4379 + p3 + " data=" + data);
4380 }
4381 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4382 command, p1, p2, p3, data);
4383 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004384
Jordan Liu4c733742019-02-28 12:03:40 -08004385 @Override
4386 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4387 int command, int p1, int p2, int p3, String data) {
4388 enforceModifyPermission();
4389 if (DBG) {
4390 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4391 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4392 + p3 + " data=" + data);
4393 }
4394 return iccTransmitApduLogicalChannelWithPermission(
4395 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4396 data);
4397 }
4398
4399 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4400 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004403 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 return "";
4405 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004408 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4409 null /* workSource */);
4410 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 // Append the returned status code to the end of the response payload.
4413 String s = Integer.toHexString(
4414 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4415 if (response.payload != null) {
4416 s = IccUtils.bytesToHexString(response.payload) + s;
4417 }
4418 return s;
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004421 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004422 }
Jake Hambye994d462014-02-03 13:10:13 -08004423
Evan Charltonc66da362014-05-16 14:06:40 -07004424 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004425 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4426 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4428 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004430 if (DBG) {
4431 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4432 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4433 }
4434 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4435 cla, command, p1, p2, p3, data);
4436 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004437
Jordan Liu4c733742019-02-28 12:03:40 -08004438 @Override
4439 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4440 int command, int p1, int p2, int p3, String data) {
4441 enforceModifyPermission();
4442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4443 if (DBG) {
4444 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4445 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4446 + " data=" + data);
4447 }
4448
4449 return iccTransmitApduBasicChannelWithPermission(
4450 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4451 p2, p3, data);
4452 }
4453
4454 // open APDU basic channel assuming the caller has sufficient permissions
4455 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4456 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4460 && TextUtils.equals(ISDR_AID, data)) {
4461 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004462 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4463 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 if (bestComponent == null
4465 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4466 loge("The calling package is not allowed to select ISD-R.");
4467 throw new SecurityException(
4468 "The calling package is not allowed to select ISD-R.");
4469 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004470 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004473 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4474 null /* workSource */);
4475 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 // Append the returned status code to the end of the response payload.
4478 String s = Integer.toHexString(
4479 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4480 if (response.payload != null) {
4481 s = IccUtils.bytesToHexString(response.payload) + s;
4482 }
4483 return s;
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004486 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004487 }
4488
4489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004490 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004491 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4493 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 if (DBG) {
4498 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4499 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4500 }
4501
4502 IccIoResult response =
4503 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4504 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4505 subId);
4506
4507 if (DBG) {
4508 log("Exchange SIM_IO [R]" + response);
4509 }
4510
4511 byte[] result = null;
4512 int length = 2;
4513 if (response.payload != null) {
4514 length = 2 + response.payload.length;
4515 result = new byte[length];
4516 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4517 } else {
4518 result = new byte[length];
4519 }
4520
4521 result[length - 1] = (byte) response.sw2;
4522 result[length - 2] = (byte) response.sw1;
4523 return result;
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004526 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004527 }
4528
Nathan Haroldb3014052017-01-25 15:57:32 -08004529 /**
4530 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4531 * on a particular subscription
4532 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004533 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4534 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004536 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004537 return null;
4538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539
4540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 if (appType != TelephonyManager.APPTYPE_USIM
4543 && appType != TelephonyManager.APPTYPE_SIM) {
4544 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4545 return null;
4546 }
4547 Object response = sendRequest(
4548 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4549 if (response instanceof String[]) {
4550 return (String[]) response;
4551 }
yincheng zhao2737e882019-09-06 17:06:54 -07004552 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004554 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004557 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004558 }
4559
yincheng zhao2737e882019-09-06 17:06:54 -07004560 /**
4561 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4562 * subscription.
4563 *
4564 * @param subId the id of the subscription.
4565 * @param appType the uicc app type, must be USIM or SIM.
4566 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4567 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004568 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004569 * @return number of fplmns that is successfully written to the SIM.
4570 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004571 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4572 String callingFeatureId) {
4573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4574 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004575 if (DBG) logv("no permissions for setForbiddenplmns");
4576 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4577 }
4578 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4579 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4580 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4581 }
4582 if (fplmns == null) {
4583 throw new IllegalArgumentException("Fplmn List provided is null");
4584 }
4585 for (String fplmn : fplmns) {
4586 if (!CellIdentity.isValidPlmn(fplmn)) {
4587 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4588 }
4589 }
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 Object response = sendRequest(
4593 CMD_SET_FORBIDDEN_PLMNS,
4594 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4595 subId);
4596 return (int) response;
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
4600 }
4601
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004602 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004603 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4605 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4610 if (response.payload == null) {
4611 return "";
4612 }
Evan Charltonc66da362014-05-16 14:06:40 -07004613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 // Append the returned status code to the end of the response payload.
4615 String s = Integer.toHexString(
4616 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4617 s = IccUtils.bytesToHexString(response.payload) + s;
4618 return s;
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
Evan Charltonc66da362014-05-16 14:06:40 -07004622 }
4623
Jake Hambye994d462014-02-03 13:10:13 -08004624 /**
4625 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4626 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4627 *
4628 * @param itemID the ID of the item to read
4629 * @return the NV item as a String, or null on error.
4630 */
4631 @Override
4632 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004633 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4635 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636
4637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004640 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4642 return value;
4643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
Jake Hambye994d462014-02-03 13:10:13 -08004646 }
4647
4648 /**
4649 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4650 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4651 *
4652 * @param itemID the ID of the item to read
4653 * @param itemValue the value to write, as a String
4654 * @return true on success; false on any failure
4655 */
4656 @Override
4657 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4660 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661
4662 final long identity = Binder.clearCallingIdentity();
4663 try {
4664 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4665 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004666 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4668 return success;
4669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Jake Hambye994d462014-02-03 13:10:13 -08004672 }
4673
4674 /**
4675 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4676 * Used for device configuration by some CDMA operators.
4677 *
4678 * @param preferredRoamingList byte array containing the new PRL
4679 * @return true on success; false on any failure
4680 */
4681 @Override
4682 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4684 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
4688 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4689 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4690 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4691 return success;
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Jake Hambye994d462014-02-03 13:10:13 -08004695 }
4696
4697 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004698 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004699 * Used for device configuration by some CDMA operators.
4700 *
chen xu6dac5ab2018-10-26 17:39:23 -07004701 * @param slotIndex - device slot.
4702 *
Jake Hambye994d462014-02-03 13:10:13 -08004703 * @return true on success; false on any failure
4704 */
4705 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004706 public boolean resetModemConfig(int slotIndex) {
4707 Phone phone = PhoneFactory.getPhone(slotIndex);
4708 if (phone != null) {
4709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4710 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711
chen xu6dac5ab2018-10-26 17:39:23 -07004712 final long identity = Binder.clearCallingIdentity();
4713 try {
4714 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4715 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4716 return success;
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 }
chen xu6dac5ab2018-10-26 17:39:23 -07004721 return false;
4722 }
4723
4724 /**
4725 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4726 *
4727 * @param slotIndex - device slot.
4728 *
4729 * @return true on success; false on any failure
4730 */
4731 @Override
4732 public boolean rebootModem(int slotIndex) {
4733 Phone phone = PhoneFactory.getPhone(slotIndex);
4734 if (phone != null) {
4735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4736 mApp, phone.getSubId(), "rebootModem");
4737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4741 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4742 return success;
4743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
4746 }
4747 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004748 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004749
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004750 public String[] getPcscfAddress(String apnType, String callingPackage,
4751 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004752 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4754 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004755 return new String[0];
4756 }
4757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758 final long identity = Binder.clearCallingIdentity();
4759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004760 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 } finally {
4762 Binder.restoreCallingIdentity(identity);
4763 }
Wink Saville36469e72014-06-11 15:17:00 -07004764 }
4765
Brad Ebinger51f743a2017-01-23 13:50:20 -08004766 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004767 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4768 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004769 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004770 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004771 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004772
4773 final long identity = Binder.clearCallingIdentity();
4774 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004775 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004776 // may happen if the device does not support IMS.
4777 return;
4778 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004779 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004783 }
4784
4785 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004786 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4787 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004788 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004789 public void disableIms(int slotId) {
4790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791
4792 final long identity = Binder.clearCallingIdentity();
4793 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004794 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004795 // may happen if the device does not support IMS.
4796 return;
4797 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004798 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004802 }
4803
4804 /**
4805 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4806 * feature or {@link null} if the service is not available. If the feature is available, the
4807 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4808 */
4809 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004810 IImsServiceFeatureCallback callback) {
4811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812
4813 final long identity = Binder.clearCallingIdentity();
4814 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004815 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004816 // may happen if the device does not support IMS.
4817 return null;
4818 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004819 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004823 }
4824
4825 /**
4826 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4827 * feature during emergency calling or {@link null} if the service is not available. If the
4828 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4829 * listener for feature updates.
4830 */
4831 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833
4834 final long identity = Binder.clearCallingIdentity();
4835 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004836 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004837 // may happen if the device does not support IMS.
4838 return null;
4839 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004840 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 } finally {
4842 Binder.restoreCallingIdentity(identity);
4843 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004844 }
4845
Brad Ebinger5f64b052017-12-14 14:26:15 -08004846 /**
4847 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004848 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004849 */
4850 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852
4853 final long identity = Binder.clearCallingIdentity();
4854 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004855 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004856 // may happen if the device does not support IMS.
4857 return null;
4858 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004859 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004863 }
4864
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004865 /**
4866 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004867 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004868 */
4869 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871
4872 final long identity = Binder.clearCallingIdentity();
4873 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004874 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004875 // may happen if the device does not support IMS.
4876 return null;
4877 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004878 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004882 }
4883
Brad Ebinger884c07b2018-02-15 16:17:40 -08004884 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004885 * Sets the ImsService Package Name that Telephony will bind to.
4886 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004887 * @param slotIndex the slot ID that the ImsService should bind for.
4888 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004889 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004890 * @param featureTypes An integer array of feature types associated with a packageName.
4891 * @param packageName The name of the package that the current configuration will be replaced
4892 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004893 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004894 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004895 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4896 int[] featureTypes, String packageName) {
4897 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4900 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004901 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 final long identity = Binder.clearCallingIdentity();
4904 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004905 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004906 // may happen if the device does not support IMS.
4907 return false;
4908 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004909 Map<Integer, String> featureConfig = new HashMap<>();
4910 for (int featureType : featureTypes) {
4911 featureConfig.put(featureType, packageName);
4912 }
4913 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4914 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915 } finally {
4916 Binder.restoreCallingIdentity(identity);
4917 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004918 }
4919
4920 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004921 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004922 *
4923 * @param slotId The slot that the ImsService is associated with.
4924 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4925 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004926 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004927 * @return the package name of the ImsService configuration.
4928 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004929 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4930 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004931 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004932 TelephonyPermissions
4933 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4934 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4935 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 final long identity = Binder.clearCallingIdentity();
4938 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004939 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004940 // may happen if the device does not support IMS.
4941 return "";
4942 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004943 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004944 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4945 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004949 }
4950
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004951 /**
4952 * Get the MmTelFeature state associated with the requested subscription id.
4953 * @param subId The subscription that the MmTelFeature is associated with.
4954 * @param callback A callback with an integer containing the
4955 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4956 */
4957 @Override
4958 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4959 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4960 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4961 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4962 "IMS not available on device.");
4963 }
4964 final long token = Binder.clearCallingIdentity();
4965 try {
4966 int slotId = getSlotIndex(subId);
4967 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4968 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4969 + subId + "'");
4970 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4971 }
4972 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4973 try {
4974 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4975 } catch (RemoteException e) {
4976 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4977 + "Ignore");
4978 }
4979 });
4980 } finally {
4981 Binder.restoreCallingIdentity(token);
4982 }
4983 }
4984
Wink Saville36469e72014-06-11 15:17:00 -07004985 public void setImsRegistrationState(boolean registered) {
4986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004990 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Wink Saville36469e72014-06-11 15:17:00 -07004994 }
4995
4996 /**
Stuart Scott54788802015-03-30 13:18:01 -07004997 * Set the network selection mode to automatic.
4998 *
4999 */
5000 @Override
5001 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5003 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
5005 final long identity = Binder.clearCallingIdentity();
5006 try {
shilufc958392020-01-20 11:36:01 -08005007 if (!isActiveSubscription(subId)) {
5008 return;
5009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5011 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Stuart Scott54788802015-03-30 13:18:01 -07005015 }
5016
Pengquan Mengea84e042018-09-20 14:57:26 -07005017 /**
5018 * Ask the radio to connect to the input network and change selection mode to manual.
5019 *
5020 * @param subId the id of the subscription.
5021 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5022 * the operator to attach to.
5023 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5024 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5025 * normal network selection next time.
5026 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005027 */
5028 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005029 public boolean setNetworkSelectionModeManual(
5030 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5032 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005033
5034 if (!isActiveSubscription(subId)) {
5035 return false;
5036 }
5037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005040 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005042 if (DBG) {
5043 log("setNetworkSelectionModeManual: subId: " + subId
5044 + " operator: " + operatorInfo);
5045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005050 }
5051
5052 /**
5053 * Scans for available networks.
5054 */
5055 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005056 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5057 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5059 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005060 LocationAccessPolicy.LocationPermissionResult locationResult =
5061 LocationAccessPolicy.checkLocationPermission(mApp,
5062 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5063 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005064 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005065 .setCallingPid(Binder.getCallingPid())
5066 .setCallingUid(Binder.getCallingUid())
5067 .setMethod("getCellNetworkScanResults")
5068 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5069 .build());
5070 switch (locationResult) {
5071 case DENIED_HARD:
5072 throw new SecurityException("Not allowed to access scan results -- location");
5073 case DENIED_SOFT:
5074 return null;
5075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076
Pengquan Menga1bb6272018-09-06 09:59:22 -07005077 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 try {
5079 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005080 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082 } finally {
5083 Binder.restoreCallingIdentity(identity);
5084 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005085 }
5086
5087 /**
yinxub1bed742017-04-17 11:45:04 -07005088 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005089 *
yinxub1bed742017-04-17 11:45:04 -07005090 * @param subId id of the subscription
5091 * @param request contains the radio access networks with bands/channels to scan
5092 * @param messenger callback messenger for scan results or errors
5093 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005094 * @return the id of the requested scan which can be used to stop the scan.
5095 */
5096 @Override
5097 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005098 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5100 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005101 LocationAccessPolicy.LocationPermissionResult locationResult =
5102 LocationAccessPolicy.checkLocationPermission(mApp,
5103 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5104 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005105 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005106 .setCallingPid(Binder.getCallingPid())
5107 .setCallingUid(Binder.getCallingUid())
5108 .setMethod("requestNetworkScan")
5109 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5110 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005111 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005112 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005113 if (e != null) {
5114 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5115 throw e;
5116 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005117 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005118 return TelephonyScanManager.INVALID_SCAN_ID;
5119 }
5120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 }
Hall Liu912dfd32019-04-25 14:02:26 -07005122 int callingUid = Binder.getCallingUid();
5123 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005124 final long identity = Binder.clearCallingIdentity();
5125 try {
5126 return mNetworkScanRequestTracker.startNetworkScan(
5127 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005128 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
yinxu504e1392017-04-12 16:03:22 -07005132 }
5133
Hall Liub2ac8ef2019-02-28 15:56:23 -08005134 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005135 NetworkScanRequest request, int subId) {
5136 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5137 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5138 boolean hasNetworkScanPermission =
5139 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5140 == PERMISSION_GRANTED;
5141
5142 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5143 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5144 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005145 }
5146
5147 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5148 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005149 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5150 return new SecurityException("Specific channels must not be"
5151 + " scanned without location access.");
5152 }
5153 }
5154 }
5155
Hall Liub2ac8ef2019-02-28 15:56:23 -08005156 return null;
5157 }
5158
yinxu504e1392017-04-12 16:03:22 -07005159 /**
5160 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005161 *
5162 * @param subId id of the subscription
5163 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005164 */
5165 @Override
5166 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5168 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169
Hall Liu912dfd32019-04-25 14:02:26 -07005170 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005173 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
yinxu504e1392017-04-12 16:03:22 -07005177 }
5178
5179 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005180 * Get the calculated preferred network type.
5181 * Used for debugging incorrect network type.
5182 *
5183 * @return the preferred network type, defined in RILConstants.java.
5184 */
5185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005186 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005187 final Phone defaultPhone = getDefaultPhone();
5188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005189 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005190 return RILConstants.PREFERRED_NETWORK_MODE;
5191 }
5192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 final long identity = Binder.clearCallingIdentity();
5194 try {
5195 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005196 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
Junda Liu84d15a22014-07-02 11:21:04 -07005200 }
5201
5202 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005203 * Get the preferred network type.
5204 * Used for device configuration by some CDMA operators.
5205 *
5206 * @return the preferred network type, defined in RILConstants.java.
5207 */
5208 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005209 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005210 TelephonyPermissions
5211 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5212 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213
5214 final long identity = Binder.clearCallingIdentity();
5215 try {
5216 if (DBG) log("getPreferredNetworkType");
5217 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5218 int networkType = (result != null ? result[0] : -1);
5219 if (DBG) log("getPreferredNetworkType: " + networkType);
5220 return networkType;
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005224 }
5225
5226 /**
5227 * Set the preferred network type.
5228 * Used for device configuration by some CDMA operators.
5229 *
5230 * @param networkType the preferred network type, defined in RILConstants.java.
5231 * @return true on success; false on any failure.
5232 */
5233 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005234 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5236 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237
5238 final long identity = Binder.clearCallingIdentity();
5239 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005240 Settings.Global.putInt(mApp.getContentResolver(),
5241 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5242 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 } finally {
5244 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005245 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005246 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005247
5248 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005249 * Get the allowed network types that store in the telephony provider.
5250 *
5251 * @param subId the id of the subscription.
5252 * @return allowedNetworkTypes the allowed network types.
5253 */
5254 @Override
5255 public long getAllowedNetworkTypes(int subId) {
5256 TelephonyPermissions
5257 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5258 mApp, subId, "getAllowedNetworkTypes");
5259
5260 final long identity = Binder.clearCallingIdentity();
5261 try {
5262 return SubscriptionManager.getLongSubscriptionProperty(
5263 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
5267 }
5268
5269 /**
5270 * Set the allowed network types.
5271 *
5272 * @param subId the id of the subscription.
5273 * @param allowedNetworkTypes the allowed network types.
5274 * @return true on success; false on any failure.
5275 */
5276 @Override
5277 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5279 mApp, subId, "setAllowedNetworkTypes");
5280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 SubscriptionManager.setSubscriptionProperty(subId,
5283 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5284 String.valueOf(allowedNetworkTypes));
5285 return setPreferredNetworkTypesInternal(subId);
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
5289 }
5290
5291 private boolean setPreferredNetworkTypesInternal(int subId) {
5292 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5293 Settings.Global.getInt(mApp.getContentResolver(),
5294 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5295 RILConstants.PREFERRED_NETWORK_MODE));
5296 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5297 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5298 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5299 (int) (networkTypeBitMask & allowedNetworkTypes));
5300
5301 if (DBG) {
5302 log("setPreferredNetworkTypesInternal: subId " + subId
5303 + " networkTypes " + networkTypeBitMask
5304 + " allowedNetworkTypes " + allowedNetworkTypes
5305 + " networkMode " + networkMode);
5306 }
5307
5308 Boolean success = (Boolean) sendRequest(
5309 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5310 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5311 return success;
5312 }
5313
5314 /**
Miaoa84611c2019-03-15 09:21:10 +08005315 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005316 *
Miaoa84611c2019-03-15 09:21:10 +08005317 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005318 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005319 * @hide
5320 */
5321 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005322 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005323 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005325 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 try {
Miaoa84611c2019-03-15 09:21:10 +08005327 if (phone != null) {
5328 return phone.hasMatchedTetherApnSetting();
5329 } else {
5330 return false;
5331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 } finally {
5333 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005334 }
Junda Liu475951f2014-11-07 16:45:03 -08005335 }
5336
5337 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005338 * Set mobile data enabled
5339 * Used by the user through settings etc to turn on/off mobile data
5340 *
5341 * @param enable {@code true} turn turn data on, else {@code false}
5342 */
5343 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005344 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5346 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347
5348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 int phoneId = mSubscriptionController.getPhoneId(subId);
5351 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5352 Phone phone = PhoneFactory.getPhone(phoneId);
5353 if (phone != null) {
5354 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005355 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005357 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 }
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005361 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005362 }
5363
5364 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005365 * Enable or disable always reporting signal strength changes from radio.
5366 *
5367 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5368 */
5369 @Override
5370 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5371 enforceModifyPermission();
5372 enforceSystemCaller();
5373
5374 final long identity = Binder.clearCallingIdentity();
5375 final Phone phone = getPhone(subId);
5376 try {
5377 if (phone != null) {
5378 if (DBG) {
5379 log("setAlwaysReportSignalStrength: subId=" + subId
5380 + " isEnable=" + isEnable);
5381 }
5382 phone.setAlwaysReportSignalStrength(isEnable);
5383 } else {
5384 loge("setAlwaysReportSignalStrength: no phone found for subId="
5385 + subId);
5386 }
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
5390 }
5391
5392 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005393 * Get the user enabled state of Mobile Data.
5394 *
5395 * TODO: remove and use isUserDataEnabled.
5396 * This can't be removed now because some vendor codes
5397 * calls through ITelephony directly while they should
5398 * use TelephonyManager.
5399 *
5400 * @return true on enabled
5401 */
5402 @Override
5403 public boolean getDataEnabled(int subId) {
5404 return isUserDataEnabled(subId);
5405 }
5406
5407 /**
5408 * Get whether mobile data is enabled per user setting.
5409 *
5410 * There are other factors deciding whether mobile data is actually enabled, but they are
5411 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005412 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005413 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005414 *
5415 * @return {@code true} if data is enabled else {@code false}
5416 */
5417 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005418 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005419 try {
5420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5421 null);
5422 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5424 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426
5427 final long identity = Binder.clearCallingIdentity();
5428 try {
5429 int phoneId = mSubscriptionController.getPhoneId(subId);
5430 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5431 Phone phone = PhoneFactory.getPhone(phoneId);
5432 if (phone != null) {
5433 boolean retVal = phone.isUserDataEnabled();
5434 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5435 return retVal;
5436 } else {
5437 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5438 return false;
5439 }
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005442 }
5443 }
5444
5445 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005446 * Checks if the device is capable of mobile data by considering whether whether the
5447 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5448 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005449 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005450 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005451 */
5452 @Override
5453 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005454 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 int phoneId = mSubscriptionController.getPhoneId(subId);
5459 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5460 Phone phone = PhoneFactory.getPhone(phoneId);
5461 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005462 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5464 return retVal;
5465 } else {
5466 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5467 return false;
5468 }
5469 } finally {
5470 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005471 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005472 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005473
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005474 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5475 Phone phone) {
5476 //load access rules from carrier configs, and check those as well: b/139133814
5477 SubscriptionController subController = SubscriptionController.getInstance();
5478 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5479 || subController == null) return privilegeFromSim;
5480
5481 int uid = Binder.getCallingUid();
5482 PackageManager pkgMgr = phone.getContext().getPackageManager();
5483 String[] packages = pkgMgr.getPackagesForUid(uid);
5484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5488 SubscriptionManager subManager = (SubscriptionManager)
5489 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5490 for (String pkg : packages) {
5491 if (subManager.canManageSubscription(subInfo, pkg)) {
5492 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5493 }
5494 }
5495 return privilegeFromSim;
5496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
5499 }
5500
5501 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5502 String pkgName) {
5503 //load access rules from carrier configs, and check those as well: b/139133814
5504 SubscriptionController subController = SubscriptionController.getInstance();
5505 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5506 || subController == null) return privilegeFromSim;
5507
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5511 SubscriptionManager subManager = (SubscriptionManager)
5512 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5513 return subManager.canManageSubscription(subInfo, pkgName)
5514 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
5518 }
5519
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005520 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005521 public int getCarrierPrivilegeStatus(int subId) {
5522 final Phone phone = getPhone(subId);
5523 if (phone == null) {
5524 loge("getCarrierPrivilegeStatus: Invalid subId");
5525 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5526 }
5527 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005528 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005529 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005530 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5531 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005532
5533 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5534 card.getCarrierPrivilegeStatusForCurrentTransaction(
5535 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005536 }
Junda Liu29340342014-07-10 15:23:27 -07005537
5538 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005539 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005540 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005541 final Phone phone = getPhone(subId);
5542 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005543 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005544 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5545 }
5546 UiccProfile profile =
5547 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5548 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005549 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005550 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5551 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005552 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005553 profile.getCarrierPrivilegeStatusForUid(
5554 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005555 }
5556
5557 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005558 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5559 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005560 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005561 }
5562
5563 int phoneId = SubscriptionManager.getPhoneId(subId);
5564 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005565 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005566 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005567 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5568 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005569 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5570 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5571 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005572 }
5573
5574 @Override
5575 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005576 if (TextUtils.isEmpty(pkgName))
5577 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005578 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5579 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5580 UiccCard card = UiccController.getInstance().getUiccCard(i);
5581 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005582 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005583 continue;
5584 }
5585
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005586 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5587 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5588 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005589 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5590 break;
5591 }
5592 }
5593
5594 return result;
Junda Liu29340342014-07-10 15:23:27 -07005595 }
Derek Tan89e89d42014-07-08 17:00:10 -07005596
5597 @Override
Junda Liue64de782015-04-16 17:19:16 -07005598 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5599 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5600 loge("phoneId " + phoneId + " is not valid.");
5601 return null;
5602 }
5603 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005604 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005605 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005606 return null ;
5607 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005608 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005609 }
5610
Amith Yamasani6e118872016-02-19 12:53:51 -08005611 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005612 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005613 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005614 List<String> privilegedPackages = new ArrayList<>();
5615 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005616 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5617 // has UICC in that slot.
5618 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005619 if (card.hasCarrierPrivilegeRules()) {
5620 if (packages == null) {
5621 // Only check packages in user 0 for now
5622 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005623 PackageManager.MATCH_DISABLED_COMPONENTS
5624 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005625 | PackageManager.GET_SIGNING_CERTIFICATES,
5626 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005627 }
5628 for (int p = packages.size() - 1; p >= 0; p--) {
5629 PackageInfo pkgInfo = packages.get(p);
5630 if (pkgInfo != null && pkgInfo.packageName != null
5631 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005632 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005633 privilegedPackages.add(pkgInfo.packageName);
5634 }
5635 }
5636 }
5637 }
5638 return privilegedPackages;
5639 }
5640
chen xuf7e9fe82019-05-09 19:31:02 -07005641 @Override
5642 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005643 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5644
5645 final long identity = Binder.clearCallingIdentity();
5646
chen xuf7e9fe82019-05-09 19:31:02 -07005647 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005648 try {
5649 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5650 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5651 }
5652 } finally {
5653 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005654 }
5655 return privilegedPackages;
5656 }
5657
Wink Savilleb564aae2014-10-23 10:18:09 -07005658 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005659 final Phone phone = getPhone(subId);
5660 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005661 if (card == null) {
5662 loge("getIccId: No UICC");
5663 return null;
5664 }
5665 String iccId = card.getIccId();
5666 if (TextUtils.isEmpty(iccId)) {
5667 loge("getIccId: ICC ID is null or empty.");
5668 return null;
5669 }
5670 return iccId;
5671 }
5672
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005673 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005674 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5675 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005676 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005677 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 final String iccId = getIccId(subId);
5682 final Phone phone = getPhone(subId);
5683 if (phone == null) {
5684 return false;
5685 }
5686 final String subscriberId = phone.getSubscriberId();
5687
5688 if (DBG_MERGE) {
5689 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5690 + subscriberId + " to " + number);
5691 }
5692
5693 if (TextUtils.isEmpty(iccId)) {
5694 return false;
5695 }
5696
5697 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5698
5699 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5700 if (alphaTag == null) {
5701 editor.remove(alphaTagPrefKey);
5702 } else {
5703 editor.putString(alphaTagPrefKey, alphaTag);
5704 }
5705
5706 // Record both the line number and IMSI for this ICCID, since we need to
5707 // track all merged IMSIs based on line number
5708 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5709 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5710 if (number == null) {
5711 editor.remove(numberPrefKey);
5712 editor.remove(subscriberPrefKey);
5713 } else {
5714 editor.putString(numberPrefKey, number);
5715 editor.putString(subscriberPrefKey, subscriberId);
5716 }
5717
5718 editor.commit();
5719 return true;
5720 } finally {
5721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005722 }
Derek Tan7226c842014-07-02 17:42:23 -07005723 }
5724
5725 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005726 public String getLine1NumberForDisplay(int subId, String callingPackage,
5727 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005728 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005730 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005731 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005732 return null;
5733 }
Derek Tan97ebb422014-09-05 16:55:38 -07005734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 String iccId = getIccId(subId);
5738 if (iccId != null) {
5739 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5740 if (DBG_MERGE) {
5741 log("getLine1NumberForDisplay returning "
5742 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5743 }
5744 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5747 return null;
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005750 }
Derek Tan7226c842014-07-02 17:42:23 -07005751 }
5752
5753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005754 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5755 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005757 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005758 return null;
5759 }
Derek Tan97ebb422014-09-05 16:55:38 -07005760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 final long identity = Binder.clearCallingIdentity();
5762 try {
5763 String iccId = getIccId(subId);
5764 if (iccId != null) {
5765 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5766 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5767 }
5768 return null;
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005771 }
Derek Tan7226c842014-07-02 17:42:23 -07005772 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005773
5774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005775 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5776 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005777 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5778 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005780 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005781 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005782 return null;
5783 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005784
Jordan Liub49b04b2019-05-06 14:45:15 -07005785 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5786 // the process, where TelephonyManager was instantiated.
5787 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005788 final long identity = Binder.clearCallingIdentity();
5789 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005790 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 final TelephonyManager tele = TelephonyManager.from(context);
5792 final SubscriptionManager sub = SubscriptionManager.from(context);
5793
5794 // Figure out what subscribers are currently active
5795 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796
Jordan Liub49b04b2019-05-06 14:45:15 -07005797 // Only consider subs which match the current subId
5798 // This logic can be simplified. See b/131189269 for progress.
5799 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005800 activeSubscriberIds.add(tele.getSubscriberId(subId));
5801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802
5803 // First pass, find a number override for an active subscriber
5804 String mergeNumber = null;
5805 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5806 for (String key : prefs.keySet()) {
5807 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5808 final String subscriberId = (String) prefs.get(key);
5809 if (activeSubscriberIds.contains(subscriberId)) {
5810 final String iccId = key.substring(
5811 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5812 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5813 mergeNumber = (String) prefs.get(numberKey);
5814 if (DBG_MERGE) {
5815 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5816 + " for active subscriber " + subscriberId);
5817 }
5818 if (!TextUtils.isEmpty(mergeNumber)) {
5819 break;
5820 }
5821 }
5822 }
5823 }
5824
5825 // Shortcut when no active merged subscribers
5826 if (TextUtils.isEmpty(mergeNumber)) {
5827 return null;
5828 }
5829
5830 // Second pass, find all subscribers under that line override
5831 final ArraySet<String> result = new ArraySet<>();
5832 for (String key : prefs.keySet()) {
5833 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5834 final String number = (String) prefs.get(key);
5835 if (mergeNumber.equals(number)) {
5836 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5837 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5838 final String subscriberId = (String) prefs.get(subscriberKey);
5839 if (!TextUtils.isEmpty(subscriberId)) {
5840 result.add(subscriberId);
5841 }
5842 }
5843 }
5844 }
5845
5846 final String[] resultArray = result.toArray(new String[result.size()]);
5847 Arrays.sort(resultArray);
5848 if (DBG_MERGE) {
5849 Slog.d(LOG_TAG,
5850 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5851 }
5852 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005853 } finally {
5854 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005855 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005856 }
5857
5858 @Override
zoey chen38003472019-12-13 17:16:31 +08005859 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5860 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005861
5862 final long identity = Binder.clearCallingIdentity();
5863 try {
5864 final TelephonyManager telephonyManager = mApp.getSystemService(
5865 TelephonyManager.class);
5866 String subscriberId = telephonyManager.getSubscriberId(subId);
5867 if (subscriberId == null) {
5868 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005869 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005870 + subId);
5871 }
5872 return null;
5873 }
5874
5875 final SubscriptionInfo info = SubscriptionController.getInstance()
5876 .getSubscriptionInfo(subId);
5877 final ParcelUuid groupUuid = info.getGroupUuid();
5878 // If it doesn't belong to any group, return just subscriberId of itself.
5879 if (groupUuid == null) {
5880 return new String[]{subscriberId};
5881 }
5882
5883 // Get all subscriberIds from the group.
5884 final List<String> mergedSubscriberIds = new ArrayList<>();
5885 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005886 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5887 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005888 for (SubscriptionInfo subInfo : groupInfos) {
5889 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5890 if (subscriberId != null) {
5891 mergedSubscriberIds.add(subscriberId);
5892 }
5893 }
5894
5895 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898
5899 }
5900 }
5901
5902 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005903 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005904 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005905 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906
5907 final long identity = Binder.clearCallingIdentity();
5908 try {
5909 final Phone phone = getPhone(subId);
5910 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005914 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005915
5916 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005917 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005918 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5919 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005920 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5921 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922
5923 final long identity = Binder.clearCallingIdentity();
5924 try {
5925 final Phone phone = getPhone(subId);
5926 if (phone == null) {
5927 return false;
5928 }
5929 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5930 cdmaNonRoamingList);
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005933 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005934 }
5935
5936 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005937 @Deprecated
5938 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5939 enforceModifyPermission();
5940
5941 int returnValue = 0;
5942 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005943 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005944 if(result.exception == null) {
5945 if (result.result != null) {
5946 byte[] responseData = (byte[])(result.result);
5947 if(responseData.length > oemResp.length) {
5948 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5949 responseData.length + "bytes. Buffer Size is " +
5950 oemResp.length + "bytes.");
5951 }
5952 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5953 returnValue = responseData.length;
5954 }
5955 } else {
5956 CommandException ex = (CommandException) result.exception;
5957 returnValue = ex.getCommandError().ordinal();
5958 if(returnValue > 0) returnValue *= -1;
5959 }
5960 } catch (RuntimeException e) {
5961 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5962 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5963 if(returnValue > 0) returnValue *= -1;
5964 }
5965
5966 return returnValue;
5967 }
5968
5969 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005970 public void setRadioCapability(RadioAccessFamily[] rafs) {
5971 try {
5972 ProxyController.getInstance().setRadioCapability(rafs);
5973 } catch (RuntimeException e) {
5974 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5975 }
5976 }
5977
5978 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005979 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005980 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005981 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005982 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005983 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 final long identity = Binder.clearCallingIdentity();
5986 try {
chen xub97461a2018-10-26 14:17:57 -07005987 TelephonyPermissions
5988 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5989 mApp, phone.getSubId(), "getRadioAccessFamily");
5990 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 } finally {
5992 Binder.restoreCallingIdentity(identity);
5993 }
chen xub97461a2018-10-26 14:17:57 -07005994 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005995 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005996
5997 @Override
5998 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005999 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006004 ImsManager.getInstance(defaultPhone.getContext(),
6005 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 } finally {
6007 Binder.restoreCallingIdentity(identity);
6008 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006009 }
6010
6011 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006012 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006013 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6015 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006016 return false;
6017 }
Svet Ganovb320e182015-04-16 12:30:10 -07006018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 final long identity = Binder.clearCallingIdentity();
6020 try {
6021 // Check the user preference and the system-level IMS setting. Even if the user has
6022 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6023 // In the long run, we may instead need to check if there exists a connection service
6024 // which can support video calling.
6025 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006026 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 return imsManager.isVtEnabledByPlatform()
6028 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6029 && imsManager.isVtEnabledByUser();
6030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006033 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006034
Andrew Leea1239f22015-03-02 17:44:07 -08006035 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006036 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6037 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006039 mApp, subId, callingPackage, callingFeatureId,
6040 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 return false;
6042 }
6043
6044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 CarrierConfigManager configManager =
6047 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006048 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
Andrew Leea1239f22015-03-02 17:44:07 -08006053 }
6054
6055 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006056 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006058 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 return false;
6060 }
6061
6062 final long identity = Binder.clearCallingIdentity();
6063 try {
6064 CarrierConfigManager configManager =
6065 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006066 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
Andrew Leea1239f22015-03-02 17:44:07 -08006071 }
6072
Andrew Lee9431b832015-03-09 18:46:45 -07006073 @Override
6074 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006075 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006076 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006077 }
6078
6079 @Override
6080 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 final long identity = Binder.clearCallingIdentity();
6082 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006083 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
Andrew Lee9431b832015-03-09 18:46:45 -07006087 }
6088
Hall Liuf6668912018-10-31 17:05:23 -07006089 /**
6090 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6091 * support for the feature and device firmware support.
6092 *
6093 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6094 */
6095 @Override
6096 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006098 final Phone phone = getPhone(subscriptionId);
6099 if (phone == null) {
6100 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6101 return false;
6102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006104 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6106 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006107 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 return isCarrierSupported && isDeviceSupported;
6109 } finally {
6110 Binder.restoreCallingIdentity(identity);
6111 }
Hall Liu98187582018-01-22 19:15:32 -08006112 }
6113
Hall Liuf6668912018-10-31 17:05:23 -07006114 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006115 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6116 * RTT setting, will return true if the device and carrier both support RTT.
6117 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006118 */
6119 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 final long identity = Binder.clearCallingIdentity();
6121 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006122 boolean isRttSupported = isRttSupported(subscriptionId);
6123 boolean isUserRttSettingOn = Settings.Secure.getInt(
6124 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6125 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6126 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6127 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 } finally {
6129 Binder.restoreCallingIdentity(identity);
6130 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006131 }
6132
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006133 @Deprecated
6134 @Override
6135 public String getDeviceId(String callingPackage) {
6136 return getDeviceIdWithFeature(callingPackage, null);
6137 }
6138
Sanket Padawe7310cc72015-01-14 09:53:20 -08006139 /**
6140 * Returns the unique device ID of phone, for example, the IMEI for
6141 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6142 *
6143 * <p>Requires Permission:
6144 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6145 */
6146 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006147 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006148 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006149 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006150 return null;
6151 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006152 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006153 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006154 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006155 return null;
6156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157
6158 final long identity = Binder.clearCallingIdentity();
6159 try {
6160 return phone.getDeviceId();
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006164 }
6165
Ping Sunc67b7c22016-03-02 19:16:45 +08006166 /**
6167 * {@hide}
6168 * Returns the IMS Registration Status on a particular subid
6169 *
6170 * @param subId
6171 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006172 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006173 Phone phone = getPhone(subId);
6174 if (phone != null) {
6175 return phone.isImsRegistered();
6176 } else {
6177 return false;
6178 }
6179 }
6180
Santos Cordon7a1885b2015-02-03 11:15:19 -08006181 @Override
6182 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006189 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006190
Tyler Gunnf70ed162019-04-03 15:28:53 -07006191 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006192 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006193 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006195 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006196 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6197 }
6198 final long identity = Binder.clearCallingIdentity();
6199 try {
6200 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
6203 }
6204 }
6205
6206 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006207 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6208 final long identity = Binder.clearCallingIdentity();
6209 try {
6210 Phone phone = getPhone(subscriptionId);
6211 if (phone == null) {
6212 return null;
6213 }
6214 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6215 } finally {
6216 Binder.restoreCallingIdentity(identity);
6217 }
6218 }
6219
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006220 /**
6221 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006222 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006223 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 final long identity = Binder.clearCallingIdentity();
6225 try {
6226 Phone phone = getPhone(subId);
6227 if (phone != null) {
6228 return phone.isWifiCallingEnabled();
6229 } else {
6230 return false;
6231 }
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006234 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006235 }
6236
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006237 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006238 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006239 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006240 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 Phone phone = getPhone(subId);
6244 if (phone != null) {
6245 return phone.isVideoEnabled();
6246 } else {
6247 return false;
6248 }
6249 } finally {
6250 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006251 }
6252 }
6253
6254 /**
6255 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6256 * defined in {@link ImsRegistrationImplBase}.
6257 */
6258 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 Phone phone = getPhone(subId);
6262 if (phone != null) {
6263 return phone.getImsRegistrationTech();
6264 } else {
6265 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6266 }
6267 } finally {
6268 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006269 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006270 }
6271
Stuart Scott8eef64f2015-04-08 15:13:54 -07006272 @Override
6273 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006274 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006275 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6276 return;
6277 }
6278
Svet Ganovcc087f82015-05-12 20:35:54 -07006279 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006280
Svet Ganovcc087f82015-05-12 20:35:54 -07006281 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006282 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6283 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006284 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006285 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006286 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006287 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6288 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006289 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006290 // There has been issues when Sms raw table somehow stores orphan
6291 // fragments. They lead to garbled message when new fragments come
6292 // in and combined with those stale ones. In case this happens again,
6293 // user can reset all network settings which will clean up this table.
6294 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006295 // Clean up IMS settings as well here.
6296 int slotId = getSlotIndex(subId);
6297 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6298 ImsManager.getInstance(mApp, slotId).factoryReset();
6299 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006300
6301 // Erase modem config if erase modem on network setting is enabled.
6302 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6303 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6304 if (configValue != null && Boolean.parseBoolean(configValue)) {
6305 sendEraseModemConfig(getDefaultPhone());
6306 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006307 } finally {
6308 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006309 }
6310 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006311
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006312 private void cleanUpSmsRawTable(Context context) {
6313 ContentResolver resolver = context.getContentResolver();
6314 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6315 resolver.delete(uri, null, null);
6316 }
6317
Narayan Kamath1c496c22015-04-16 14:40:19 +01006318 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006319 public String getSimLocaleForSubscriber(int subId) {
6320 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6321 final Phone phone = getPhone(subId);
6322 if (phone == null) {
6323 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006324 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 final long identity = Binder.clearCallingIdentity();
6327 try {
chen xu5d3637b2019-01-21 23:31:38 -08006328 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006329 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006330 if (info == null) {
6331 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6332 return null;
6333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 // Try and fetch the locale from the carrier properties or from the SIM language
6335 // preferences (EF-PL and EF-LI)...
6336 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006338 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6339 if (localeFromDefaultSim != null) {
6340 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6341 if (DBG) log("Using locale from subId: " + subId + " locale: "
6342 + localeFromDefaultSim);
6343 return localeFromDefaultSim.toLanguageTag();
6344 } else {
6345 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 }
6347 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349 // The SIM language preferences only store a language (e.g. fr = French), not an
6350 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6351 // the SIM and carrier preferences does not include a country we add the country
6352 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006353 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006355 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 return mccLocale.toLanguageTag();
6357 }
6358
6359 if (DBG) log("No locale found - returning null");
6360 return null;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006364 }
6365
6366 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006367 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6368 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006369 }
6370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 /**
6372 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6373 */
6374 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006375 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6376 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006377 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006378
Chenjie Yu1ba97252018-01-11 18:16:20 -08006379 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006380 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006381
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006382 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006383 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6384 * representing the state of the modem.
6385 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006386 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6387 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006388 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006389 */
6390 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006391 public void requestModemActivityInfo(ResultReceiver result) {
6392 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006393 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394
6395 final long identity = Binder.clearCallingIdentity();
6396 try {
6397 ModemActivityInfo ret = null;
6398 synchronized (mLastModemActivityInfo) {
6399 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6400 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006401 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006402 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006404 int[] txTimeMs = info.getTransmitTimeMillis();
6405 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006407 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 }
6409 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006410 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6411 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 mLastModemActivityInfo.setIdleTimeMillis(
6413 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006414 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6415 mLastModemActivityInfo.setReceiveTimeMillis(
6416 info.getReceiveTimeMillis() + mLastModemActivityInfo
6417 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006418 }
Chen Xud78231e2019-09-10 18:49:52 -07006419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6421 mLastModemActivityInfo.getSleepTimeMillis(),
6422 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006423 mLastModemActivityInfo.getTransmitTimeMillis(),
6424 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426 Bundle bundle = new Bundle();
6427 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6428 result.send(0, bundle);
6429 } finally {
6430 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006431 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006432 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006433
Siddharth Rayb8114062018-06-17 15:02:38 -07006434 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6435 // less than total activity duration.
6436 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6437 if (info == null) {
6438 return false;
6439 }
6440 int activityDurationMs =
6441 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6442 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006443 int[] txTimeMs = info.getTransmitTimeMillis();
6444 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6445 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006446 }
6447 return (info.isValid()
6448 && (info.getSleepTimeMillis() <= activityDurationMs)
6449 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006450 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006451 && (totalTxTimeMs <= activityDurationMs));
6452 }
6453
Jack Yu85bd38a2015-11-09 11:34:32 -08006454 /**
6455 * {@hide}
6456 * Returns the service state information on specified subscription.
6457 */
6458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006459 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6460 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006462 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006463 return null;
6464 }
6465
Hall Liuf19c44f2018-11-27 14:38:17 -08006466 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6467 LocationAccessPolicy.checkLocationPermission(mApp,
6468 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6469 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006470 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006471 .setCallingPid(Binder.getCallingPid())
6472 .setCallingUid(Binder.getCallingUid())
6473 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006474 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006475 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6476 .build());
6477
6478 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6479 LocationAccessPolicy.checkLocationPermission(mApp,
6480 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6481 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006482 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006483 .setCallingPid(Binder.getCallingPid())
6484 .setCallingUid(Binder.getCallingUid())
6485 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006486 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006487 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6488 .build());
6489 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6490 boolean hasFinePermission =
6491 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6492 boolean hasCoarsePermission =
6493 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 final long identity = Binder.clearCallingIdentity();
6496 try {
6497 final Phone phone = getPhone(subId);
6498 if (phone == null) {
6499 return null;
6500 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006501
Hall Liuf19c44f2018-11-27 14:38:17 -08006502 ServiceState ss = phone.getServiceState();
6503
6504 // Scrub out the location info in ServiceState depending on what level of access
6505 // the caller has.
6506 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006507 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6508 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006512 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006513
6514 /**
6515 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6516 *
6517 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6518 * voicemail ringtone.
6519 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6520 * PhoneAccount.
6521 */
6522 @Override
6523 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6527 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006528 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006535 }
6536
6537 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006538 * Sets the per-account voicemail ringtone.
6539 *
6540 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6541 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6542 *
6543 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6544 * voicemail ringtone.
6545 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6546 * PhoneAccount.
6547 */
6548 @Override
6549 public void setVoicemailRingtoneUri(String callingPackage,
6550 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006551 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006552 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006553 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6554 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6556 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6557 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559
6560 final long identity = Binder.clearCallingIdentity();
6561 try {
6562 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6563 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006564 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 }
6566 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006569 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006570 }
6571
6572 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006573 * Returns whether vibration is set for voicemail notification in Phone settings.
6574 *
6575 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6576 * voicemail vibration setting.
6577 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6578 */
6579 @Override
6580 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6584 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006585 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006592 }
6593
Youhan Wange64578a2016-05-02 15:32:42 -07006594 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006595 * Sets the per-account voicemail vibration.
6596 *
6597 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6598 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6599 *
6600 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6601 * voicemail vibration setting.
6602 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6603 * specific PhoneAccount.
6604 */
6605 @Override
6606 public void setVoicemailVibrationEnabled(String callingPackage,
6607 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006608 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006610 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6611 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6613 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6614 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006615 }
6616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6620 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006621 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 }
6623 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6624 } finally {
6625 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006626 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006627 }
6628
6629 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006630 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6631 *
6632 * @throws SecurityException if the caller does not have the required permission
6633 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006634 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006635 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006636 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006637 }
6638
6639 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006640 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6641 * permission.
6642 *
6643 * @throws SecurityException if the caller does not have the required permission
6644 */
6645 private void enforceSendSmsPermission() {
6646 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6647 }
6648
6649 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006650 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006651 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006652 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006653 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006654 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006658 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 if (componentName == null) {
6660 throw new SecurityException(
6661 "Caller not current active visual voicemail package[null]");
6662 }
6663 String vvmPackage = componentName.getPackageName();
6664 if (!callingPackage.equals(vvmPackage)) {
6665 throw new SecurityException("Caller not current active visual voicemail package["
6666 + vvmPackage + "]");
6667 }
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006670 }
6671 }
6672
6673 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006674 * Return the application ID for the app type.
6675 *
6676 * @param subId the subscription ID that this request applies to.
6677 * @param appType the uicc app type.
6678 * @return Application ID for specificied app type, or null if no uicc.
6679 */
6680 @Override
6681 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006682 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006683 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684
6685 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006686 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006687 if (phone == null) {
6688 return null;
6689 }
6690 String aid = null;
6691 try {
6692 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6693 .getApplicationByType(appType).getAid();
6694 } catch (Exception e) {
6695 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6696 }
6697 return aid;
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006700 }
Youhan Wange64578a2016-05-02 15:32:42 -07006701 }
6702
Youhan Wang4001d252016-05-11 10:29:41 -07006703 /**
6704 * Return the Electronic Serial Number.
6705 *
6706 * @param subId the subscription ID that this request applies to.
6707 * @return ESN or null if error.
6708 */
6709 @Override
6710 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006711 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006712 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713
6714 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006715 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 if (phone == null) {
6717 return null;
6718 }
6719 String esn = null;
6720 try {
6721 esn = phone.getEsn();
6722 } catch (Exception e) {
6723 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6724 }
6725 return esn;
6726 } finally {
6727 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006728 }
Youhan Wang4001d252016-05-11 10:29:41 -07006729 }
6730
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006731 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006732 * Return the Preferred Roaming List Version.
6733 *
6734 * @param subId the subscription ID that this request applies to.
6735 * @return PRLVersion or null if error.
6736 */
6737 @Override
6738 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006739 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006740 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741
6742 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006743 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744 if (phone == null) {
6745 return null;
6746 }
6747 String cdmaPrlVersion = null;
6748 try {
6749 cdmaPrlVersion = phone.getCdmaPrlVersion();
6750 } catch (Exception e) {
6751 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6752 }
6753 return cdmaPrlVersion;
6754 } finally {
6755 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006756 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006757 }
6758
6759 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006760 * Get snapshot of Telephony histograms
6761 * @return List of Telephony histograms
6762 * @hide
6763 */
6764 @Override
6765 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6767 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
6771 return RIL.getTelephonyRILTimingHistograms();
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006775 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006776
6777 /**
6778 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006779 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6780 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006781 * Require system privileges. In the future we may add this to carrier APIs.
6782 *
Michele Berionne482f8202018-11-27 18:57:59 -08006783 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006784 */
6785 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006786 @TelephonyManager.SetCarrierRestrictionResult
6787 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006788 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006789 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006790
Michele Berionne482f8202018-11-27 18:57:59 -08006791 if (carrierRestrictionRules == null) {
6792 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006793 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 final long identity = Binder.clearCallingIdentity();
6796 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006797 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006798 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006802 }
6803
6804 /**
6805 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006806 * Get the allowed carrier list and the excluded carrier list, including the priority between
6807 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006808 * Require system privileges. In the future we may add this to carrier APIs.
6809 *
Michele Berionne482f8202018-11-27 18:57:59 -08006810 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006811 */
6812 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006813 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006814 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816
6817 final long identity = Binder.clearCallingIdentity();
6818 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006819 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6820 if (response instanceof CarrierRestrictionRules) {
6821 return (CarrierRestrictionRules) response;
6822 }
6823 // Response is an Exception of some kind,
6824 // which is signalled to the user as a NULL retval
6825 return null;
6826 } catch (Exception e) {
6827 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6828 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 } finally {
6830 Binder.restoreCallingIdentity(identity);
6831 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006832 }
6833
fionaxu59545b42016-05-25 15:53:37 -07006834 /**
6835 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6836 * @param subId the subscription ID that this action applies to.
6837 * @param enabled control enable or disable metered apns.
6838 * {@hide}
6839 */
6840 @Override
6841 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6842 enforceModifyPermission();
6843 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844
6845 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006846 if (phone == null) {
6847 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6848 return;
6849 }
6850 try {
6851 phone.carrierActionSetMeteredApnsEnabled(enabled);
6852 } catch (Exception e) {
6853 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 } finally {
6855 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006856 }
6857 }
6858
6859 /**
6860 * Action set from carrier signalling broadcast receivers to enable/disable radio
6861 * @param subId the subscription ID that this action applies to.
6862 * @param enabled control enable or disable radio.
6863 * {@hide}
6864 */
6865 @Override
6866 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6867 enforceModifyPermission();
6868 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869
6870 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006871 if (phone == null) {
6872 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6873 return;
6874 }
6875 try {
6876 phone.carrierActionSetRadioEnabled(enabled);
6877 } catch (Exception e) {
6878 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 } finally {
6880 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006881 }
6882 }
6883
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006884 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006885 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6886 * network status based on which carrier apps could apply actions accordingly,
6887 * enable/disable default url handler for example.
6888 *
6889 * @param subId the subscription ID that this action applies to.
6890 * @param report control start/stop reporting the default network status.
6891 * {@hide}
6892 */
6893 @Override
6894 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6895 enforceModifyPermission();
6896 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897
6898 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006899 if (phone == null) {
6900 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6901 return;
6902 }
6903 try {
6904 phone.carrierActionReportDefaultNetworkStatus(report);
6905 } catch (Exception e) {
6906 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 } finally {
6908 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006909 }
6910 }
6911
6912 /**
fionaxud9622282017-07-17 17:51:30 -07006913 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6914 * @param subId the subscription ID that this action applies to.
6915 * {@hide}
6916 */
6917 @Override
6918 public void carrierActionResetAll(int subId) {
6919 enforceModifyPermission();
6920 final Phone phone = getPhone(subId);
6921 if (phone == null) {
6922 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6923 return;
6924 }
6925 try {
6926 phone.carrierActionResetAll();
6927 } catch (Exception e) {
6928 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6929 }
6930 }
6931
6932 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006933 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6934 * bug report is being generated.
6935 */
6936 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006937 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006938 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6939 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006940 writer.println("Permission Denial: can't dump Phone from pid="
6941 + Binder.getCallingPid()
6942 + ", uid=" + Binder.getCallingUid()
6943 + "without permission "
6944 + android.Manifest.permission.DUMP);
6945 return;
6946 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006947 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006948 }
Jack Yueb89b242016-06-22 13:27:47 -07006949
Brad Ebingerdac2f002018-04-03 15:17:52 -07006950 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006951 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6952 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6953 @NonNull String[] args) {
6954 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6955 this, in.getFileDescriptor(), out.getFileDescriptor(),
6956 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006957 }
6958
Jack Yueb89b242016-06-22 13:27:47 -07006959 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006960 * Get aggregated video call data usage since boot.
6961 *
6962 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6963 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006964 * {@hide}
6965 */
6966 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006967 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006968 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6969 null);
6970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006971 final long identity = Binder.clearCallingIdentity();
6972 try {
6973 // NetworkStatsService keeps tracking the active network interface and identity. It
6974 // records the delta with the corresponding network identity.
6975 // We just return the total video call data usage snapshot since boot.
6976 Phone phone = getPhone(subId);
6977 if (phone != null) {
6978 return phone.getVtDataUsage(perUidStats);
6979 }
6980 return null;
6981 } finally {
6982 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006983 }
Jack Yueb89b242016-06-22 13:27:47 -07006984 }
Jack Yu75ab2952016-07-08 14:29:33 -07006985
6986 /**
6987 * Policy control of data connection. Usually used when data limit is passed.
6988 * @param enabled True if enabling the data, otherwise disabling.
6989 * @param subId Subscription index
6990 * {@hide}
6991 */
6992 @Override
6993 public void setPolicyDataEnabled(boolean enabled, int subId) {
6994 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995
6996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 Phone phone = getPhone(subId);
6999 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007000 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 }
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007004 }
7005 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007006
7007 /**
7008 * Get Client request stats
7009 * @return List of Client Request Stats
7010 * @hide
7011 */
7012 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007013 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7014 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007016 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007017 return null;
7018 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007019 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 final long identity = Binder.clearCallingIdentity();
7022 try {
7023 if (phone != null) {
7024 return phone.getClientRequestStats();
7025 }
7026
7027 return null;
7028 } finally {
7029 Binder.restoreCallingIdentity(identity);
7030 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007031 }
7032
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007033 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007034 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007035 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007036 }
Jack Yueb4124c2017-02-16 15:32:43 -08007037
7038 /**
Grace Chen70990072017-03-24 17:21:30 -07007039 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007040 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007041 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007042 * @param state State of SIM (power down, power up, pass through)
7043 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7044 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7045 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007046 *
7047 **/
7048 @Override
Grace Chen70990072017-03-24 17:21:30 -07007049 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007050 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007051 Phone phone = PhoneFactory.getPhone(slotIndex);
7052
vagdeviaf9a5b92018-08-15 16:01:53 -07007053 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 final long identity = Binder.clearCallingIdentity();
7056 try {
7057 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007058 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 }
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007062 }
7063 }
Shuo Qiandd210312017-04-12 22:11:33 +00007064
Tyler Gunn65d45c22017-06-05 11:22:26 -07007065 private boolean isUssdApiAllowed(int subId) {
7066 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007067 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007068 if (configManager == null) {
7069 return false;
7070 }
7071 PersistableBundle pb = configManager.getConfigForSubId(subId);
7072 if (pb == null) {
7073 return false;
7074 }
7075 return pb.getBoolean(
7076 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7077 }
7078
Shuo Qiandd210312017-04-12 22:11:33 +00007079 /**
7080 * Check if phone is in emergency callback mode
7081 * @return true if phone is in emergency callback mode
7082 * @param subId sub id
7083 */
goneil9c5f4872017-12-05 14:07:56 -08007084 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007085 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007086 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007087 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088
7089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 if (phone != null) {
7092 return phone.isInEcm();
7093 } else {
7094 return false;
7095 }
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007098 }
7099 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007100
7101 /**
7102 * Get the current signal strength information for the given subscription.
7103 * Because this information is not updated when the device is in a low power state
7104 * it should not be relied-upon to be current.
7105 * @param subId Subscription index
7106 * @return the most recent cached signal strength info from the modem
7107 */
7108 @Override
7109 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 Phone p = getPhone(subId);
7113 if (p == null) {
7114 return null;
7115 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117 return p.getSignalStrength();
7118 } finally {
7119 Binder.restoreCallingIdentity(identity);
7120 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007121 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007122
Pengquan Meng77b7f132018-08-22 14:49:57 -07007123 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007124 * Get the current modem radio state for the given slot.
7125 * @param slotIndex slot index.
7126 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007127 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007128 * @return the current radio power state from the modem
7129 */
7130 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007131 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007132 Phone phone = PhoneFactory.getPhone(slotIndex);
7133 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7135 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007136 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7137 }
7138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 return phone.getRadioPowerState();
7142 } finally {
7143 Binder.restoreCallingIdentity(identity);
7144 }
7145 }
7146 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7147 }
7148
7149 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007150 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7151 *
7152 * <p>Requires one of the following permissions:
7153 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7154 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7155 * privileges.
7156 *
7157 * @param subId subscription id
7158 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7159 * {@code false}.
7160 */
7161 @Override
7162 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007163 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7164 null /* message */);
7165
Pengquan Menga1bb6272018-09-06 09:59:22 -07007166 boolean isEnabled = false;
7167 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007168 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007169 Phone phone = getPhone(subId);
7170 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007171 } catch (Exception e) {
7172 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7173 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007174 } finally {
7175 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007176 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007177 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007178 }
7179
7180
7181 /**
7182 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7183 *
7184 * <p> Requires permission:
7185 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7186 * privileges.
7187 *
7188 * @param subId subscription id
7189 * @param isEnabled {@code true} means enable, {@code false} means disable.
7190 */
7191 @Override
7192 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7194 mApp, subId, "setDataRoamingEnabled");
7195
Pengquan Menga1bb6272018-09-06 09:59:22 -07007196 final long identity = Binder.clearCallingIdentity();
7197 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007198 Phone phone = getPhone(subId);
7199 if (phone != null) {
7200 phone.setDataRoamingEnabled(isEnabled);
7201 }
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007204 }
7205 }
7206
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007207 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007208 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007209 TelephonyPermissions
7210 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007211 mApp, subId, "isManualNetworkSelectionAllowed");
7212
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007213 boolean isAllowed = true;
7214 final long identity = Binder.clearCallingIdentity();
7215 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007216 Phone phone = getPhone(subId);
7217 if (phone != null) {
7218 isAllowed = phone.isCspPlmnEnabled();
7219 }
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
7222 }
7223 return isAllowed;
7224 }
7225
7226 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007227 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007228 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007229 try {
7230 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007231 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007232 } catch (SecurityException e) {
7233 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7234 // has carrier privileges on an active UICC
7235 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7236 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007237 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007238 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007239 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007240
7241 final long identity = Binder.clearCallingIdentity();
7242 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007243 UiccController uiccController = UiccController.getInstance();
7244 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007245 if (hasReadPermission) {
7246 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007247 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007248
7249 // Remove private info if the caller doesn't have access
7250 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7251 for (UiccCardInfo cardInfo : cardInfos) {
7252 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7253 // is available
7254 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7255 if (card == null || card.getUiccProfile() == null) {
7256 // assume no access if the card or profile is unavailable
7257 filteredInfos.add(cardInfo.getUnprivileged());
7258 continue;
7259 }
7260 UiccProfile profile = card.getUiccProfile();
7261 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7262 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7263 filteredInfos.add(cardInfo);
7264 } else {
7265 filteredInfos.add(cardInfo.getUnprivileged());
7266 }
7267 }
7268 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
7272 }
7273
7274 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007275 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007276 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7281 if (slots == null) {
7282 Rlog.i(LOG_TAG, "slots is null.");
7283 return null;
7284 }
7285
7286 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7287 for (int i = 0; i < slots.length; i++) {
7288 UiccSlot slot = slots[i];
7289 if (slot == null) {
7290 continue;
7291 }
7292
Jordan Liu7be7e652019-05-06 18:55:02 +00007293 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294 UiccCard card = slot.getUiccCard();
7295 if (card != null) {
7296 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007297 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007298 cardId = slot.getEid();
7299 if (TextUtils.isEmpty(cardId)) {
7300 cardId = slot.getIccId();
7301 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 }
7303
Jordan Liu857451f2019-05-09 16:35:35 -07007304 if (cardId != null) {
7305 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7306 // if cardId is an EID, it's all digits so this is fine
7307 cardId = IccUtils.stripTrailingFs(cardId);
7308 }
7309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 int cardState = 0;
7311 switch (slot.getCardState()) {
7312 case CARDSTATE_ABSENT:
7313 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7314 break;
7315 case CARDSTATE_PRESENT:
7316 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7317 break;
7318 case CARDSTATE_ERROR:
7319 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7320 break;
7321 case CARDSTATE_RESTRICTED:
7322 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7323 break;
7324 default:
7325 break;
7326
7327 }
7328
7329 infos[i] = new UiccSlotInfo(
7330 slot.isActive(),
7331 slot.isEuicc(),
7332 cardId,
7333 cardState,
7334 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007335 slot.isExtendedApduSupported(),
7336 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 }
7338 return infos;
7339 } finally {
7340 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007341 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007342 }
7343
7344 @Override
7345 public boolean switchSlots(int[] physicalSlots) {
7346 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347
7348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007354 }
Jack Yu4c988042018-02-27 15:30:01 -08007355
7356 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007357 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007358 final long identity = Binder.clearCallingIdentity();
7359 try {
7360 return UiccController.getInstance().getCardIdForDefaultEuicc();
7361 } finally {
7362 Binder.restoreCallingIdentity(identity);
7363 }
7364 }
7365
7366 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007367 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7368 enforceModifyPermission();
7369 final Phone phone = getPhone(subId);
7370 if (phone == null) {
7371 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7372 return;
7373 }
7374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 final long identity = Binder.clearCallingIdentity();
7376 try {
7377 phone.setRadioIndicationUpdateMode(filters, mode);
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
Jack Yu4c988042018-02-27 15:30:01 -08007381 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007382
7383 /**
goneil47ffb6e2018-04-06 15:40:58 -07007384 * A test API to reload the UICC profile.
7385 *
7386 * <p>Requires that the calling app has permission
7387 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7388 * @hide
7389 */
7390 @Override
7391 public void refreshUiccProfile(int subId) {
7392 enforceModifyPermission();
7393
7394 final long identity = Binder.clearCallingIdentity();
7395 try {
7396 Phone phone = getPhone(subId);
7397 if (phone == null) {
7398 return;
7399 }
7400 UiccCard uiccCard = phone.getUiccCard();
7401 if (uiccCard == null) {
7402 return;
7403 }
7404 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7405 if (uiccProfile == null) {
7406 return;
7407 }
7408 uiccProfile.refresh();
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
7411 }
7412 }
7413
7414 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007415 * Returns false if the mobile data is disabled by default, otherwise return true.
7416 */
7417 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007418 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007419 }
7420
7421 /**
7422 * Returns true if the data roaming is enabled by default, i.e the system property
7423 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7424 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7425 */
7426 private boolean getDefaultDataRoamingEnabled(int subId) {
7427 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007428 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007429 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007430 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7431 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7432 return isDataRoamingEnabled;
7433 }
7434
7435 /**
7436 * Returns the default network type for the given {@code subId}, if the default network type is
7437 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7438 */
7439 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007440 List<Integer> list = TelephonyProperties.default_network();
7441 int phoneId = mSubscriptionController.getPhoneId(subId);
7442 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7443 return list.get(phoneId);
7444 }
7445 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007446 }
fionaxua13278b2018-03-21 00:08:13 -07007447
7448 @Override
7449 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007450 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 final Phone phone = getPhone(subId);
7456 if (phone == null) {
7457 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7458 return;
7459 }
chen xueaba88a2019-03-15 13:15:10 -07007460 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7461 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 } finally {
7463 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007464 }
fionaxua13278b2018-03-21 00:08:13 -07007465 }
7466
7467 @Override
7468 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007469 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470
7471 final long identity = Binder.clearCallingIdentity();
7472 try {
7473 final Phone phone = getPhone(subId);
7474 if (phone == null) {
7475 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7476 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7477 }
7478 return phone.getCarrierIdListVersion();
7479 } finally {
7480 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007481 }
fionaxua13278b2018-03-21 00:08:13 -07007482 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007483
7484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7486 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007488 mApp, subId, callingPackage, callingFeatureId,
7489 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007490 return -1;
7491 }
7492
7493 final long identity = Binder.clearCallingIdentity();
7494 try {
7495 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7496 } finally {
7497 Binder.restoreCallingIdentity(identity);
7498 }
7499 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007500
7501 @Override
7502 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007503 TelephonyPermissions
7504 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007505 mApp, subId, "getCdmaRoamingMode");
7506
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
7513 }
7514
7515 @Override
7516 public boolean setCdmaRoamingMode(int subId, int mode) {
7517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7518 mApp, subId, "setCdmaRoamingMode");
7519
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
7526 }
7527
7528 @Override
7529 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7531 mApp, subId, "setCdmaSubscriptionMode");
7532
7533 final long identity = Binder.clearCallingIdentity();
7534 try {
7535 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7536 } finally {
7537 Binder.restoreCallingIdentity(identity);
7538 }
7539 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007540
sqianc5eccab2018-10-19 18:46:41 -07007541 @Override
sqian8c685422019-02-22 15:55:18 -08007542 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007543 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007545 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7546 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007547 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7548 }
7549 final long identity = Binder.clearCallingIdentity();
7550 try {
sqian854d44b2018-12-12 16:48:18 -08007551 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7552 for (Phone phone: PhoneFactory.getPhones()) {
7553 if (phone.getEmergencyNumberTracker() != null
7554 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7555 emergencyNumberListInternal.put(
7556 phone.getSubId(),
7557 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7558 }
sqian11b7a0e2018-12-05 18:48:28 -08007559 }
sqian854d44b2018-12-12 16:48:18 -08007560 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007561 } finally {
7562 Binder.restoreCallingIdentity(identity);
7563 }
sqianc5eccab2018-10-19 18:46:41 -07007564 }
7565
7566 @Override
sqian8c685422019-02-22 15:55:18 -08007567 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007568 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007569 if (!exactMatch) {
7570 TelephonyPermissions
7571 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007572 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007573 }
7574 final long identity = Binder.clearCallingIdentity();
7575 try {
sqian854d44b2018-12-12 16:48:18 -08007576 for (Phone phone: PhoneFactory.getPhones()) {
7577 if (phone.getEmergencyNumberTracker() != null
7578 && phone.getEmergencyNumberTracker() != null) {
7579 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7580 number, exactMatch)) {
7581 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007582 }
7583 }
sqian11b7a0e2018-12-05 18:48:28 -08007584 }
7585 return false;
7586 } finally {
7587 Binder.restoreCallingIdentity(identity);
7588 }
7589 }
7590
sqianf4ca7ed2019-01-15 18:32:07 -08007591 /**
7592 * Update emergency number list for test mode.
7593 */
7594 @Override
7595 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7596 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7597 "updateEmergencyNumberListTestMode");
7598
7599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 for (Phone phone: PhoneFactory.getPhones()) {
7602 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7603 if (tracker != null) {
7604 tracker.executeEmergencyNumberTestModeCommand(action, num);
7605 }
7606 }
7607 } finally {
7608 Binder.restoreCallingIdentity(identity);
7609 }
7610 }
7611
7612 /**
7613 * Get the full emergency number list for test mode.
7614 */
7615 @Override
7616 public List<String> getEmergencyNumberListTestMode() {
7617 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7618 "getEmergencyNumberListTestMode");
7619
7620 final long identity = Binder.clearCallingIdentity();
7621 try {
7622 Set<String> emergencyNumbers = new HashSet<>();
7623 for (Phone phone: PhoneFactory.getPhones()) {
7624 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7625 if (tracker != null) {
7626 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7627 emergencyNumbers.add(num.getNumber());
7628 }
7629 }
7630 }
7631 return new ArrayList<>(emergencyNumbers);
7632 } finally {
7633 Binder.restoreCallingIdentity(identity);
7634 }
7635 }
7636
chen xud6b45bd2018-10-30 22:27:10 -07007637 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007638 public int getEmergencyNumberDbVersion(int subId) {
7639 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7640
7641 final long identity = Binder.clearCallingIdentity();
7642 try {
7643 final Phone phone = getPhone(subId);
7644 if (phone == null) {
7645 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7646 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7647 }
7648 return phone.getEmergencyNumberDbVersion();
7649 } finally {
7650 Binder.restoreCallingIdentity(identity);
7651 }
7652 }
7653
7654 @Override
7655 public void notifyOtaEmergencyNumberDbInstalled() {
7656 enforceModifyPermission();
7657
7658 final long identity = Binder.clearCallingIdentity();
7659 try {
7660 for (Phone phone: PhoneFactory.getPhones()) {
7661 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7662 if (tracker != null) {
7663 tracker.updateOtaEmergencyNumberDatabase();
7664 }
7665 }
7666 } finally {
7667 Binder.restoreCallingIdentity(identity);
7668 }
7669 }
7670
7671 @Override
7672 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7673 enforceActiveEmergencySessionPermission();
7674
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 for (Phone phone: PhoneFactory.getPhones()) {
7678 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7679 if (tracker != null) {
7680 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7681 }
7682 }
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
7686 }
7687
7688 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007689 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7690 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7691 Phone phone = getPhone(subId);
7692 if (phone == null) {
7693 return null;
7694 }
7695 final long identity = Binder.clearCallingIdentity();
7696 try {
7697 UiccProfile profile = UiccController.getInstance()
7698 .getUiccProfileForPhone(phone.getPhoneId());
7699 if (profile != null) {
7700 return profile.getCertsFromCarrierPrivilegeAccessRules();
7701 }
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
7705 return null;
7706 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007707
7708 /**
7709 * Enable or disable a modem stack.
7710 */
7711 @Override
7712 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7713 enforceModifyPermission();
7714
7715 final long identity = Binder.clearCallingIdentity();
7716 try {
7717 Phone phone = PhoneFactory.getPhone(slotIndex);
7718 if (phone == null) {
7719 return false;
7720 } else {
7721 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7722 }
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
7726 }
Michelecea4cf22018-12-21 15:00:11 -08007727
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007728 /**
7729 * Whether a modem stack is enabled or not.
7730 */
7731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007732 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7733 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007734 Phone phone = PhoneFactory.getPhone(slotIndex);
7735 if (phone == null) return false;
7736
7737 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007738 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7739 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007740 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7741 }
7742
7743 final long identity = Binder.clearCallingIdentity();
7744 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007745 try {
7746 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7747 } catch (NoSuchElementException ex) {
7748 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7749 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007750 } finally {
7751 Binder.restoreCallingIdentity(identity);
7752 }
7753 }
7754
Michelecea4cf22018-12-21 15:00:11 -08007755 @Override
Michele0ea7d782019-03-19 14:58:42 -07007756 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007757 enforceModifyPermission();
7758
7759 final long identity = Binder.clearCallingIdentity();
7760 try {
7761 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007762 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007763 .commit();
7764 } finally {
7765 Binder.restoreCallingIdentity(identity);
7766 }
7767 }
7768
7769 @Override
Michele0ea7d782019-03-19 14:58:42 -07007770 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007771 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007773 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7774 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007775 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007776 }
Michelecea4cf22018-12-21 15:00:11 -08007777
7778 final long identity = Binder.clearCallingIdentity();
7779 try {
Michele0ea7d782019-03-19 14:58:42 -07007780 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
7784 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007785
Michele0ea7d782019-03-19 14:58:42 -07007786 @TelephonyManager.IsMultiSimSupportedResult
7787 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007788 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7789 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7790 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007791 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7792 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007793 }
7794 // Check if the hardware supports multisim functionality. If usage of multisim is not
7795 // supported by the modem, indicate that it is restricted.
7796 PhoneCapability staticCapability =
7797 mPhoneConfigurationManager.getStaticPhoneCapability();
7798 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007799 loge("isMultiSimSupportedInternal: no static configuration available");
7800 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007801 }
Sarah Chin0605abf2019-12-06 10:24:18 -08007802 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007803 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7804 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007805 }
7806 // Check if support of multiple SIMs is restricted by carrier
7807 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007808 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007809 }
7810
Michele0ea7d782019-03-19 14:58:42 -07007811 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007812 }
7813
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007814 /**
7815 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007816 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7817 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7818 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007819 * @param numOfSims number of active sims we want to switch to
7820 */
7821 @Override
7822 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007823 if (numOfSims == 1) {
7824 enforceModifyPermission();
7825 } else {
7826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7827 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7828 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007829 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007830
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007831 try {
Michele30b57b22019-03-01 12:01:14 -08007832 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007833 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007834 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7835 return;
7836 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007837 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7838 } finally {
7839 Binder.restoreCallingIdentity(identity);
7840 }
7841 }
7842
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007843 @Override
7844 public boolean isApplicationOnUicc(int subId, int appType) {
7845 enforceReadPrivilegedPermission("isApplicationOnUicc");
7846 Phone phone = getPhone(subId);
7847 if (phone == null) {
7848 return false;
7849 }
7850 final long identity = Binder.clearCallingIdentity();
7851 try {
7852 UiccCard uiccCard = phone.getUiccCard();
7853 if (uiccCard == null) {
7854 return false;
7855 }
7856 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7857 if (uiccProfile == null) {
7858 return false;
7859 }
7860 if (TelephonyManager.APPTYPE_SIM <= appType
7861 && appType <= TelephonyManager.APPTYPE_ISIM) {
7862 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7863 }
7864 return false;
7865 } finally {
7866 Binder.restoreCallingIdentity(identity);
7867 }
7868 }
7869
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007870 /**
chen xub4baa772019-04-03 10:23:41 -07007871 * Get whether making changes to modem configurations will trigger reboot.
7872 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007873 */
7874 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007875 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7876 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007878 mApp, subId, callingPackage, callingFeatureId,
7879 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007880 return false;
7881 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7885 } finally {
7886 Binder.restoreCallingIdentity(identity);
7887 }
7888 }
7889
Nathan Harold29f5f052019-02-15 13:41:57 -08007890 private void updateModemStateMetrics() {
7891 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7892 // TODO: check the state for each modem if the api is ready.
7893 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7894 }
7895
Pengquan Meng3889a572019-01-23 11:16:29 -08007896 @Override
7897 public int[] getSlotsMapping() {
7898 enforceReadPrivilegedPermission("getSlotsMapping");
7899
7900 final long identity = Binder.clearCallingIdentity();
7901 try {
7902 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7903 // All logical slots should have a mapping to a physical slot.
7904 int[] logicalSlotsMapping = new int[phoneCount];
7905 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7906 for (int i = 0; i < slotInfos.length; i++) {
7907 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7908 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7909 }
7910 }
7911 return logicalSlotsMapping;
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
7914 }
7915 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007916
7917 /**
7918 * Get the IRadio HAL Version
7919 */
7920 @Override
7921 public int getRadioHalVersion() {
7922 Phone phone = getDefaultPhone();
7923 if (phone == null) return -1;
7924 HalVersion hv = phone.getHalVersion();
7925 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7926 return hv.major * 100 + hv.minor;
7927 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007928
7929 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007930 * Get the current calling package name.
7931 * @return the current calling package name
7932 */
7933 @Override
7934 public String getCurrentPackageName() {
7935 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7936 }
7937
7938 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007939 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7940 * corresponding network requests on a subId.
7941 *
7942 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007943 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007944 * 2) APN is un-metered for this subscription, or
7945 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007946 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007947 *
7948 * @return whether data is allowed for a apn type.
7949 *
7950 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007951 */
7952 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007953 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007954 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7955 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007956
7957 // Now that all security checks passes, perform the operation as ourselves.
7958 final long identity = Binder.clearCallingIdentity();
7959 try {
7960 Phone phone = getPhone(subId);
7961 if (phone == null) return false;
7962
Jack Yu41407ee2019-05-13 16:54:09 -07007963 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007964 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
7967 }
7968 }
7969
7970 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007971 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007972 enforceReadPrivilegedPermission("isApnMetered");
7973
7974 // Now that all security checks passes, perform the operation as ourselves.
7975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 Phone phone = getPhone(subId);
7978 if (phone == null) return true; // By default return true.
7979
Jack Yu41407ee2019-05-13 16:54:09 -07007980 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
7984 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007985
7986 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08007987 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
7988 int subscriptionId, IBooleanConsumer resultCallback) {
7989 enforceModifyPermission();
7990 long token = Binder.clearCallingIdentity();
7991 try {
7992 Phone phone = getPhone(subscriptionId);
7993 if (phone == null) {
7994 try {
7995 if (resultCallback != null) {
7996 resultCallback.accept(false);
7997 }
7998 } catch (RemoteException e) {
7999 // ignore
8000 }
8001 return;
8002 }
8003 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8004 Pair.create(specifiers, (x) -> {
8005 try {
8006 if (resultCallback != null) {
8007 resultCallback.accept(x);
8008 }
8009 } catch (RemoteException e) {
8010 // ignore
8011 }
8012 });
8013 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8014 } finally {
8015 Binder.restoreCallingIdentity(token);
8016 }
8017 }
8018
8019 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008020 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8021 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8022 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8023 if (iccRecords == null) {
8024 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8025 return false;
8026 }
8027 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8028 }
8029
8030 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008031 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008032 if (callingPackage == null) {
8033 callingPackage = getCurrentPackageName();
8034 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008035 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8036 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8037 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8038 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8039 }
8040 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8041 Intent intent = new Intent();
8042 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8043 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8044 // Bring up choose default SMS subscription dialog right now
8045 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8046 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8047 mApp.startActivity(intent);
8048 }
chen xud5ca2d52019-05-28 15:20:57 -07008049
8050 @Override
8051 public String getMmsUAProfUrl(int subId) {
8052 //TODO investigate if this API should require proper permission check in R b/133791609
8053 final long identity = Binder.clearCallingIdentity();
8054 try {
8055 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8056 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
8060 }
8061
8062 @Override
8063 public String getMmsUserAgent(int subId) {
8064 //TODO investigate if this API should require proper permission check in R b/133791609
8065 final long identity = Binder.clearCallingIdentity();
8066 try {
8067 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8068 .getString(com.android.internal.R.string.config_mms_user_agent);
8069 } finally {
8070 Binder.restoreCallingIdentity(identity);
8071 }
8072 }
Jack Yub07d4972019-05-28 16:12:25 -07008073
8074 @Override
8075 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8076 enforceModifyPermission();
8077
8078 // Now that all security checks passes, perform the operation as ourselves.
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 Phone phone = getPhone(subId);
8082 if (phone == null) return false;
8083
8084 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8085 } finally {
8086 Binder.restoreCallingIdentity(identity);
8087 }
8088 }
8089
8090 @Override
8091 public boolean isDataAllowedInVoiceCall(int subId) {
8092 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8093
8094 // Now that all security checks passes, perform the operation as ourselves.
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 Phone phone = getPhone(subId);
8098 if (phone == null) return false;
8099
8100 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
8104 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008105
changbettyd5c246e2019-12-24 15:40:37 +08008106 @Override
8107 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8108 enforceModifyPermission();
8109
8110 // Now that all security checks passes, perform the operation as ourselves.
8111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 Phone phone = getPhone(subId);
8114 if (phone == null) return false;
8115
8116 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
8119 }
8120 }
8121
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008122 /**
8123 * Updates whether conference event pacakge handling is enabled.
8124 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8125 * otherwise.
8126 */
8127 @Override
8128 public void setCepEnabled(boolean isCepEnabled) {
8129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8130
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8134 for (Phone phone : PhoneFactory.getPhones()) {
8135 Phone defaultPhone = phone.getImsPhone();
8136 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8137 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8138 ImsPhoneCallTracker imsPhoneCallTracker =
8139 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8140 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8141 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8142 + imsPhone.getMsisdn());
8143 }
8144 }
8145 } finally {
8146 Binder.restoreCallingIdentity(identity);
8147 }
8148 }
allenwtsu46dcc572020-01-08 18:24:03 +08008149
8150 /**
8151 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8152 *
8153 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8154 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8155 * before being read.
8156 */
8157 @Override
8158 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8159 isCompressed) {
8160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8161 mApp, subId, "notifyRcsAutoConfigurationReceived");
8162 try {
8163 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8164 if (configBinder == null) {
8165 Rlog.e(LOG_TAG, "null result for getImsConfig");
8166 } else {
8167 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8168 }
8169 } catch (RemoteException e) {
8170 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8171 }
8172 }
zoey chene02881a2019-12-30 16:11:23 +08008173
8174 @Override
8175 public boolean isIccLockEnabled(int subId) {
8176 enforceReadPrivilegedPermission("isIccLockEnabled");
8177
8178 // Now that all security checks passes, perform the operation as ourselves.
8179 final long identity = Binder.clearCallingIdentity();
8180 try {
8181 Phone phone = getPhone(subId);
8182 if (phone != null && phone.getIccCard() != null) {
8183 return phone.getIccCard().getIccLockEnabled();
8184 } else {
8185 return false;
8186 }
8187 } finally {
8188 Binder.restoreCallingIdentity(identity);
8189 }
8190 }
8191
8192 /**
8193 * Set the ICC pin lock enabled or disabled.
8194 *
8195 * @return an integer representing the status of IccLock enabled or disabled in the following
8196 * three cases:
8197 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8198 * successfully.
8199 * - Positive number and zero for remaining password attempts.
8200 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8201 *
8202 */
8203 @Override
8204 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8205 enforceModifyPermission();
8206
8207 Phone phone = getPhone(subId);
8208 if (phone == null) {
8209 return 0;
8210 }
8211 // Now that all security checks passes, perform the operation as ourselves.
8212 final long identity = Binder.clearCallingIdentity();
8213 try {
8214 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8215 new Pair<Boolean, String>(enabled, password), phone, null);
8216 return attemptsRemaining;
8217
8218 } catch (Exception e) {
8219 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
8223 return 0;
8224 }
8225
8226 /**
8227 * Change the ICC password used in ICC pin lock.
8228 *
8229 * @return an integer representing the status of IccLock changed in the following three cases:
8230 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8231 * - Positive number and zero for remaining password attempts.
8232 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8233 *
8234 */
8235 @Override
8236 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8237 enforceModifyPermission();
8238
8239 Phone phone = getPhone(subId);
8240 if (phone == null) {
8241 return 0;
8242 }
8243 // Now that all security checks passes, perform the operation as ourselves.
8244 final long identity = Binder.clearCallingIdentity();
8245 try {
8246 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8247 new Pair<String, String>(oldPassword, newPassword), phone, null);
8248 return attemptsRemaining;
8249
8250 } catch (Exception e) {
8251 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8252 } finally {
8253 Binder.restoreCallingIdentity(identity);
8254 }
8255 return 0;
8256 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008257
8258 /**
8259 * Request for receiving user activity notification
8260 */
8261 @Override
8262 public void requestUserActivityNotification() {
8263 if (!mNotifyUserActivity.get()
8264 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8265 mNotifyUserActivity.set(true);
8266 }
8267 }
8268
8269 /**
8270 * Called when userActivity is signalled in the power manager.
8271 * This is safe to call from any thread, with any window manager locks held or not.
8272 */
8273 @Override
8274 public void userActivity() {
8275 // ***************************************
8276 // * Inherited from PhoneWindowManager *
8277 // ***************************************
8278 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8279 // WITH ITS LOCKS HELD.
8280 //
8281 // This code must be VERY careful about the locks
8282 // it acquires.
8283 // In fact, the current code acquires way too many,
8284 // and probably has lurking deadlocks.
8285
8286 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8287 throw new SecurityException("Only the OS may call notifyUserActivity()");
8288 }
8289
8290 if (mNotifyUserActivity.getAndSet(false)) {
8291 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8292 USER_ACTIVITY_NOTIFICATION_DELAY);
8293 }
8294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008295}