blob: 62ff07c31dc0e8f1cb30df8ba59bdd5ae5457cfd [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;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070056import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090064import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080065import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080066import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070067import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070068import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070079import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070080import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080081import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070082import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080083import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070084import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080085import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080086import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070087import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080090import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080091import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080092import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070093import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080096import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000097import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070098import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800100import android.telephony.data.ApnSetting;
101import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsMmTelFeature;
109import android.telephony.ims.aidl.IImsRcsFeature;
110import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700112import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800114import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800116import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
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;
Jordan Liua39e6c12020-03-04 13:59:23 -0800124import com.android.internal.annotations.VisibleForTesting;
sqian80370722020-01-29 15:02:51 -0800125import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700126import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700127import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700128import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800129import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800132import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800134import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800135import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700136import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800137import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800139import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700141import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700142import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700144import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800145import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700146import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700147import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700148import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700149import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700150import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700152import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800154import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Hall Liud0d1dc92020-01-20 13:42:00 -0800194import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196/**
197 * Implementation of the ITelephony interface.
198 */
Santos Cordon117fee72014-05-16 17:56:12 -0700199public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 private static final String LOG_TAG = "PhoneInterfaceManager";
201 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
202 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
205 // Message codes used with mMainThreadHandler
206 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700207 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
208 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209 private static final int CMD_OPEN_CHANNEL = 9;
210 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
211 private static final int CMD_CLOSE_CHANNEL = 11;
212 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800213 private static final int CMD_NV_READ_ITEM = 13;
214 private static final int EVENT_NV_READ_ITEM_DONE = 14;
215 private static final int CMD_NV_WRITE_ITEM = 15;
216 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
217 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
218 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700219 private static final int CMD_RESET_MODEM_CONFIG = 19;
220 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800221 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
222 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
223 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
224 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800225 private static final int CMD_SEND_ENVELOPE = 25;
226 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000227 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
228 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700229 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
230 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
231 private static final int CMD_EXCHANGE_SIM_IO = 31;
232 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800233 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
234 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700235 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700237 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
238 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700239 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
240 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
241 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
242 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700243 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
244 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
245 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
246 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700247 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800248 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
249 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000250 private static final int CMD_SWITCH_SLOTS = 50;
251 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700252 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
253 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
254 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
255 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
256 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
257 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
258 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
259 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700260 private static final int CMD_GET_ALL_CELL_INFO = 60;
261 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
262 private static final int CMD_GET_CELL_LOCATION = 62;
263 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_MODEM_REBOOT = 64;
265 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700266 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
267 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800268 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
269 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700270 private static final int CMD_GET_MODEM_STATUS = 70;
271 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700272 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
273 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700274 private static final int CMD_ERASE_MODEM_CONFIG = 74;
275 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800276 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
277 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
278 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
279 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800280 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
281 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
sqian80370722020-01-29 15:02:51 -0800282 private static final int CMD_GET_CALL_FORWARDING = 83;
283 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
284 private static final int CMD_SET_CALL_FORWARDING = 85;
285 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
286 private static final int CMD_GET_CALL_WAITING = 87;
287 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
288 private static final int CMD_SET_CALL_WAITING = 89;
289 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800291 // Parameters of select command.
292 private static final int SELECT_COMMAND = 0xA4;
293 private static final int SELECT_P1 = 0x04;
294 private static final int SELECT_P2 = 0;
295 private static final int SELECT_P3 = 0x10;
296
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 /** The singleton instance. */
298 private static PhoneInterfaceManager sInstance;
299
Wink Saville3ab207e2014-11-20 13:07:20 -0800300 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800302 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700303 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800304 private AppOpsManager mAppOps;
305 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800306 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800307 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700308 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309
Derek Tan97ebb422014-09-05 16:55:38 -0700310 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
311 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800312 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800313 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700314
Michelecea4cf22018-12-21 15:00:11 -0800315 // String to store multi SIM allowed
316 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
317
Derek Tan740e1672017-06-27 14:56:27 -0700318 // The AID of ISD-R.
319 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
320
yinxub1bed742017-04-17 11:45:04 -0700321 private NetworkScanRequestTracker mNetworkScanRequestTracker;
322
David Kelly5e06a7f2018-03-12 14:10:59 +0000323 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
324 private static final int MANUFACTURER_CODE_LENGTH = 8;
325
Derek Tan89e89d42014-07-08 17:00:10 -0700326 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700327 * Experiment flag to enable erase modem config on reset network, default value is false
328 */
329 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
330 "reset_network_erase_modem_config_enabled";
331
332 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class IccAPDUArgument {
336 public int channel, cla, command, p1, p2, p3;
337 public String data;
338
339 public IccAPDUArgument(int channel, int cla, int command,
340 int p1, int p2, int p3, String data) {
341 this.channel = channel;
342 this.cla = cla;
343 this.command = command;
344 this.p1 = p1;
345 this.p2 = p2;
346 this.p3 = p3;
347 this.data = data;
348 }
349 }
350
351 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700352 * A request object to use for transmitting data to an ICC.
353 */
354 private static final class ManualNetworkSelectionArgument {
355 public OperatorInfo operatorInfo;
356 public boolean persistSelection;
357
358 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
359 this.operatorInfo = operatorInfo;
360 this.persistSelection = persistSelection;
361 }
362 }
363
364 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
366 * request after sending. The main thread will notify the request when it is complete.
367 */
368 private static final class MainThreadRequest {
369 /** The argument to use for the request */
370 public Object argument;
371 /** The result of the request that is run on the main thread */
372 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 // The subscriber id that this request applies to. Defaults to
374 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
375 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
Nathan Harold92bed182018-10-12 18:16:49 -0700377 // In cases where subId is unavailable, the caller needs to specify the phone.
378 public Phone phone;
379
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 public WorkSource workSource;
381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 public MainThreadRequest(Object argument) {
383 this.argument = argument;
384 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800385
Nathan Harold92bed182018-10-12 18:16:49 -0700386 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
387 this.argument = argument;
388 if (phone != null) {
389 this.phone = phone;
390 }
391 this.workSource = workSource;
392 }
393
vagdeviaf9a5b92018-08-15 16:01:53 -0700394 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800395 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800396 if (subId != null) {
397 this.subId = subId;
398 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700399 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 }
402
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800403 private static final class IncomingThirdPartyCallArgs {
404 public final ComponentName component;
405 public final String callId;
406 public final String callerDisplayName;
407
408 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
409 String callerDisplayName) {
410 this.component = component;
411 this.callId = callId;
412 this.callerDisplayName = callerDisplayName;
413 }
414 }
415
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 /**
417 * A handler that processes messages on the main thread in the phone process. Since many
418 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
419 * inbound binder threads to the main thread in the phone process. The Binder thread
420 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
421 * on, which will be notified when the operation completes and will contain the result of the
422 * request.
423 *
424 * <p>If a MainThreadRequest object is provided in the msg.obj field,
425 * note that request.result must be set to something non-null for the calling thread to
426 * unblock.
427 */
428 private final class MainThreadHandler extends Handler {
429 @Override
430 public void handleMessage(Message msg) {
431 MainThreadRequest request;
432 Message onCompleted;
433 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800434 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800436 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437
438 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 case CMD_HANDLE_USSD_REQUEST: {
440 request = (MainThreadRequest) msg.obj;
441 final Phone phone = getPhoneFromRequest(request);
442 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
443 String ussdRequest = ussdObject.first;
444 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700445
Pengquan Menga1bb6272018-09-06 09:59:22 -0700446 if (!isUssdApiAllowed(request.subId)) {
447 // Carrier does not support use of this API, return failure.
448 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
449 UssdResponse response = new UssdResponse(ussdRequest, null);
450 Bundle returnData = new Bundle();
451 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
452 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 request.result = true;
455 notifyRequester(request);
456 return;
457 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700458
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 try {
460 request.result = phone != null
461 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
462 } catch (CallStateException cse) {
463 request.result = false;
464 }
465 // Wake up the requesting thread
466 notifyRequester(request);
467 break;
pkanwar32d516d2016-10-14 19:37:38 -0700468 }
469
Yorke Lee716f67e2015-06-17 15:39:16 -0700470 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700472 final Phone phone = getPhoneFromRequest(request);
473 request.result = phone != null ?
474 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
475 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700477 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700485 if (uiccCard == null) {
486 loge("iccTransmitApduLogicalChannel: No UICC");
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700489 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
491 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700492 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 iccArgument.channel, iccArgument.cla, iccArgument.command,
494 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700496 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
506 if (ar.result == null) {
507 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800508 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800510 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700511 } else {
512 loge("iccTransmitApduLogicalChannel: Unknown exception");
513 }
514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 break;
517
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
519 request = (MainThreadRequest) msg.obj;
520 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 if (uiccCard == null) {
523 loge("iccTransmitApduBasicChannel: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
528 request);
529 uiccCard.iccTransmitApduBasicChannel(
530 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
531 iccArgument.p3, iccArgument.data, onCompleted);
532 }
533 break;
534
535 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
538 if (ar.exception == null && ar.result != null) {
539 request.result = ar.result;
540 } else {
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
542 if (ar.result == null) {
543 loge("iccTransmitApduBasicChannel: Empty response");
544 } else if (ar.exception instanceof CommandException) {
545 loge("iccTransmitApduBasicChannel: CommandException: " +
546 ar.exception);
547 } else {
548 loge("iccTransmitApduBasicChannel: Unknown exception");
549 }
550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 break;
553
554 case CMD_EXCHANGE_SIM_IO:
555 request = (MainThreadRequest) msg.obj;
556 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800557 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 if (uiccCard == null) {
559 loge("iccExchangeSimIO: No UICC");
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 } else {
563 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
564 request);
565 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
566 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
567 iccArgument.data, onCompleted);
568 }
569 break;
570
571 case EVENT_EXCHANGE_SIM_IO_DONE:
572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
574 if (ar.exception == null && ar.result != null) {
575 request.result = ar.result;
576 } else {
577 request.result = new IccIoResult(0x6f, 0, (byte[])null);
578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 break;
581
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 case CMD_SEND_ENVELOPE:
583 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800584 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700585 if (uiccCard == null) {
586 loge("sendEnvelopeWithStatus: No UICC");
587 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 } else {
590 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
591 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
592 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
595 case EVENT_SEND_ENVELOPE_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700598 if (ar.exception == null && ar.result != null) {
599 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800600 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700601 request.result = new IccIoResult(0x6F, 0, (byte[])null);
602 if (ar.result == null) {
603 loge("sendEnvelopeWithStatus: Empty response");
604 } else if (ar.exception instanceof CommandException) {
605 loge("sendEnvelopeWithStatus: CommandException: " +
606 ar.exception);
607 } else {
608 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
609 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800610 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800612 break;
613
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 case CMD_OPEN_CHANNEL:
615 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800616 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800617 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800620 request.result = new IccOpenLogicalChannelResponse(-1,
621 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 } else {
624 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
626 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 break;
629
630 case EVENT_OPEN_CHANNEL_DONE:
631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 int[] result = (int[]) ar.result;
636 int channelId = result[0];
637 byte[] selectResponse = null;
638 if (result.length > 1) {
639 selectResponse = new byte[result.length - 1];
640 for (int i = 1; i < result.length; ++i) {
641 selectResponse[i - 1] = (byte) result[i];
642 }
643 }
644 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700645 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 if (ar.result == null) {
648 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 if (ar.exception != null) {
651 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
652 }
653
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700654 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700655 if (ar.exception instanceof CommandException) {
656 CommandException.Error error =
657 ((CommandException) (ar.exception)).getCommandError();
658 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700660 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700661 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 }
663 }
664 openChannelResp = new IccOpenLogicalChannelResponse(
665 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700667 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
671 case CMD_CLOSE_CHANNEL:
672 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800673 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 if (uiccCard == null) {
675 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900676 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 } else {
679 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
680 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
684 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800685 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
686 break;
687
688 case CMD_NV_READ_ITEM:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800691 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
692 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800693 break;
694
695 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 ar = (AsyncResult) msg.obj;
697 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800698 if (ar.exception == null && ar.result != null) {
699 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800701 request.result = "";
702 if (ar.result == null) {
703 loge("nvReadItem: Empty response");
704 } else if (ar.exception instanceof CommandException) {
705 loge("nvReadItem: CommandException: " +
706 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800708 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 }
710 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 break;
713
Jake Hambye994d462014-02-03 13:10:13 -0800714 case CMD_NV_WRITE_ITEM:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
717 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800718 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700719 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800720 break;
721
722 case EVENT_NV_WRITE_ITEM_DONE:
723 handleNullReturnEvent(msg, "nvWriteItem");
724 break;
725
726 case CMD_NV_WRITE_CDMA_PRL:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800729 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800730 break;
731
732 case EVENT_NV_WRITE_CDMA_PRL_DONE:
733 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
734 break;
735
chen xu6dac5ab2018-10-26 17:39:23 -0700736 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800737 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700738 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800739 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case EVENT_RESET_MODEM_CONFIG_DONE:
743 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800744 break;
745
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 case CMD_GET_PREFERRED_NETWORK_TYPE:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700749 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result; // Integer
757 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800758 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800759 if (ar.result == null) {
760 loge("getPreferredNetworkType: Empty response");
761 } else if (ar.exception instanceof CommandException) {
762 loge("getPreferredNetworkType: CommandException: " +
763 ar.exception);
764 } else {
765 loge("getPreferredNetworkType: Unknown exception");
766 }
767 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700768 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800769 break;
770
771 case CMD_SET_PREFERRED_NETWORK_TYPE:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
774 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700775 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800776 break;
777
778 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
779 handleNullReturnEvent(msg, "setPreferredNetworkType");
780 break;
781
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000782 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
783 request = (MainThreadRequest)msg.obj;
784 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000786 break;
787
788 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
789 ar = (AsyncResult)msg.obj;
790 request = (MainThreadRequest)ar.userObj;
791 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700792 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000793 break;
794
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800795 case CMD_SET_VOICEMAIL_NUMBER:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
798 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800799 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
800 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800801 break;
802
803 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
804 handleNullReturnEvent(msg, "setVoicemailNumber");
805 break;
806
Stuart Scott54788802015-03-30 13:18:01 -0700807 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
808 request = (MainThreadRequest) msg.obj;
809 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
810 request);
811 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
812 break;
813
814 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
815 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
816 break;
817
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 case CMD_PERFORM_NETWORK_SCAN:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
821 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
822 break;
823
sqian80370722020-01-29 15:02:51 -0800824 case CMD_GET_CALL_FORWARDING:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
827 int callForwardingReason = (Integer) request.argument;
828 getPhoneFromRequest(request).getCallForwardingOption(
829 callForwardingReason, onCompleted);
830 break;
831
832 case EVENT_GET_CALL_FORWARDING_DONE:
833 ar = (AsyncResult) msg.obj;
834 request = (MainThreadRequest) ar.userObj;
835 CallForwardingInfo callForwardingInfo = null;
836 if (ar.exception == null && ar.result != null) {
837 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
838 for (CallForwardInfo callForwardInfo : callForwardInfos) {
839 // Service Class is a bit mask per 3gpp 27.007. Search for
840 // any service for voice call.
841 if ((callForwardInfo.serviceClass
842 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
843 callForwardingInfo = new CallForwardingInfo(
844 callForwardInfo.serviceClass, callForwardInfo.reason,
845 callForwardInfo.number,
846 callForwardInfo.timeSeconds);
847 break;
848 }
849 }
850 // Didn't find a call forward info for voice call.
851 if (callForwardingInfo == null) {
852 callForwardingInfo = new CallForwardingInfo(
853 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
854 0 /* reason */, null /* number */, 0 /* timeout */);
855 }
856 } else {
857 if (ar.result == null) {
858 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
859 }
860 if (ar.exception != null) {
861 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
862 }
863 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
864 if (ar.exception instanceof CommandException) {
865 CommandException.Error error =
866 ((CommandException) (ar.exception)).getCommandError();
867 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
868 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
869 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
870 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
871 }
872 }
873 callForwardingInfo = new CallForwardingInfo(
874 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
875 }
876 request.result = callForwardingInfo;
877 notifyRequester(request);
878 break;
879
880 case CMD_SET_CALL_FORWARDING:
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
883 CallForwardingInfo callForwardingInfoToSet =
884 (CallForwardingInfo) request.argument;
885 getPhoneFromRequest(request).setCallForwardingOption(
886 callForwardingInfoToSet.getStatus(),
887 callForwardingInfoToSet.getReason(),
888 callForwardingInfoToSet.getNumber(),
889 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
890 break;
891
892 case EVENT_SET_CALL_FORWARDING_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null) {
896 request.result = true;
897 } else {
898 request.result = false;
899 loge("setCallForwarding exception: " + ar.exception);
900 }
901 notifyRequester(request);
902 break;
903
904 case CMD_GET_CALL_WAITING:
905 request = (MainThreadRequest) msg.obj;
906 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
907 getPhoneFromRequest(request).getCallWaiting(onCompleted);
908 break;
909
910 case EVENT_GET_CALL_WAITING_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
914 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800915 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800916 // Service Class is a bit mask per 3gpp 27.007.
917 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800918 if (callForwardResults.length > 1
919 && ((callForwardResults[1]
920 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
921 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800922 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
923 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
924 } else {
925 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
926 }
927 } else {
928 if (ar.result == null) {
929 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
930 }
931 if (ar.exception != null) {
932 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
933 }
934 if (ar.exception instanceof CommandException) {
935 CommandException.Error error =
936 ((CommandException) (ar.exception)).getCommandError();
937 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
938 callForwardingStatus =
939 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
940 }
941 }
942 }
943 request.result = callForwardingStatus;
944 notifyRequester(request);
945 break;
946
947 case CMD_SET_CALL_WAITING:
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
950 boolean isEnable = (Boolean) request.argument;
951 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
952 break;
953
954 case EVENT_SET_CALL_WAITING_DONE:
955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
957 if (ar.exception == null) {
958 request.result = true;
959 } else {
960 request.result = false;
961 loge("setCallWaiting exception: " + ar.exception);
962 }
963 notifyRequester(request);
964 break;
965
Shishir Agrawal302c8692015-06-19 13:49:39 -0700966 case EVENT_PERFORM_NETWORK_SCAN_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 CellNetworkScanResult cellScanResult;
970 if (ar.exception == null && ar.result != null) {
971 cellScanResult = new CellNetworkScanResult(
972 CellNetworkScanResult.STATUS_SUCCESS,
973 (List<OperatorInfo>) ar.result);
974 } else {
975 if (ar.result == null) {
976 loge("getCellNetworkScanResults: Empty response");
977 }
978 if (ar.exception != null) {
979 loge("getCellNetworkScanResults: Exception: " + ar.exception);
980 }
981 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
982 if (ar.exception instanceof CommandException) {
983 CommandException.Error error =
984 ((CommandException) (ar.exception)).getCommandError();
985 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
986 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
987 } else if (error == CommandException.Error.GENERIC_FAILURE) {
988 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
989 }
990 }
991 cellScanResult = new CellNetworkScanResult(errorCode, null);
992 }
993 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700994 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700995 break;
996
997 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
998 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700999 ManualNetworkSelectionArgument selArg =
1000 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001001 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1002 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001003 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1004 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001005 break;
1006
1007 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception == null) {
1011 request.result = true;
1012 } else {
1013 request.result = false;
1014 loge("setNetworkSelectionModeManual " + ar.exception);
1015 }
1016 notifyRequester(request);
1017 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001018 break;
1019
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001020 case CMD_GET_MODEM_ACTIVITY_INFO:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001023 if (defaultPhone != null) {
1024 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001025 } else {
1026 ResultReceiver result = (ResultReceiver) request.argument;
1027 Bundle bundle = new Bundle();
1028 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1029 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1030 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001031 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001032 break;
1033
1034 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001037 ResultReceiver result = (ResultReceiver) request.argument;
1038
1039 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001040 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001041 // Update the last modem activity info and the result of the request.
1042 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1043 if (isModemActivityInfoValid(info)) {
1044 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1045 int[] txTimeMs = info.getTransmitTimeMillis();
1046 int[] lastModemTxTimeMs = mLastModemActivityInfo
1047 .getTransmitTimeMillis();
1048 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1049 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1050 }
1051 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1052 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1053 + mLastModemActivityInfo.getSleepTimeMillis());
1054 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1055 + mLastModemActivityInfo.getIdleTimeMillis());
1056 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1057 mLastModemActivityInfo.setReceiveTimeMillis(
1058 info.getReceiveTimeMillis()
1059 + mLastModemActivityInfo.getReceiveTimeMillis());
1060 }
1061 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1062 mLastModemActivityInfo.getSleepTimeMillis(),
1063 mLastModemActivityInfo.getIdleTimeMillis(),
1064 mLastModemActivityInfo.getTransmitTimeMillis(),
1065 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001066 } else {
1067 if (ar.result == null) {
1068 loge("queryModemActivityInfo: Empty response");
1069 } else if (ar.exception instanceof CommandException) {
1070 loge("queryModemActivityInfo: CommandException: " +
1071 ar.exception);
1072 } else {
1073 loge("queryModemActivityInfo: Unknown exception");
1074 }
1075 }
sqian1a1be542020-03-05 11:37:28 -08001076 Bundle bundle = new Bundle();
1077 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1078 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001079 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001080 break;
1081
Meng Wang1a7c35a2016-05-05 20:56:15 -07001082 case CMD_SET_ALLOWED_CARRIERS:
1083 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001084 CarrierRestrictionRules argument =
1085 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001086 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001087 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 break;
1089
1090 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1091 ar = (AsyncResult) msg.obj;
1092 request = (MainThreadRequest) ar.userObj;
1093 if (ar.exception == null && ar.result != null) {
1094 request.result = ar.result;
1095 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001096 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1097 if (ar.exception instanceof CommandException) {
1098 loge("setAllowedCarriers: CommandException: " + ar.exception);
1099 CommandException.Error error =
1100 ((CommandException) (ar.exception)).getCommandError();
1101 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1102 request.result =
1103 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1104 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001105 } else {
1106 loge("setAllowedCarriers: Unknown exception");
1107 }
1108 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001109 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001110 break;
1111
1112 case CMD_GET_ALLOWED_CARRIERS:
1113 request = (MainThreadRequest) msg.obj;
1114 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001115 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001116 break;
1117
1118 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1119 ar = (AsyncResult) msg.obj;
1120 request = (MainThreadRequest) ar.userObj;
1121 if (ar.exception == null && ar.result != null) {
1122 request.result = ar.result;
1123 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001124 request.result = new IllegalStateException(
1125 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001126 if (ar.result == null) {
1127 loge("getAllowedCarriers: Empty response");
1128 } else if (ar.exception instanceof CommandException) {
1129 loge("getAllowedCarriers: CommandException: " +
1130 ar.exception);
1131 } else {
1132 loge("getAllowedCarriers: Unknown exception");
1133 }
1134 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001135 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001136 break;
1137
Nathan Haroldb3014052017-01-25 15:57:32 -08001138 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 if (ar.exception == null && ar.result != null) {
1142 request.result = ar.result;
1143 } else {
1144 request.result = new IllegalArgumentException(
1145 "Failed to retrieve Forbidden Plmns");
1146 if (ar.result == null) {
1147 loge("getForbiddenPlmns: Empty response");
1148 } else {
1149 loge("getForbiddenPlmns: Unknown exception");
1150 }
1151 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001152 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001153 break;
1154
1155 case CMD_GET_FORBIDDEN_PLMNS:
1156 request = (MainThreadRequest) msg.obj;
1157 uiccCard = getUiccCardFromRequest(request);
1158 if (uiccCard == null) {
1159 loge("getForbiddenPlmns() UiccCard is null");
1160 request.result = new IllegalArgumentException(
1161 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001162 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001163 break;
1164 }
1165 Integer appType = (Integer) request.argument;
1166 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1167 if (uiccApp == null) {
1168 loge("getForbiddenPlmns() no app with specified type -- "
1169 + appType);
1170 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001172 break;
1173 } else {
1174 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1175 + " specified type -- " + appType);
1176 }
1177 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1178 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1179 onCompleted);
1180 break;
1181
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001182 case CMD_SWITCH_SLOTS:
1183 request = (MainThreadRequest) msg.obj;
1184 int[] physicalSlots = (int[]) request.argument;
1185 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1186 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1187 break;
1188
1189 case EVENT_SWITCH_SLOTS_DONE:
1190 ar = (AsyncResult) msg.obj;
1191 request = (MainThreadRequest) ar.userObj;
1192 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001193 notifyRequester(request);
1194 break;
1195 case CMD_GET_NETWORK_SELECTION_MODE:
1196 request = (MainThreadRequest) msg.obj;
1197 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1198 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1199 break;
1200
1201 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1202 ar = (AsyncResult) msg.obj;
1203 request = (MainThreadRequest) ar.userObj;
1204 if (ar.exception != null) {
1205 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1206 } else {
1207 int mode = ((int[]) ar.result)[0];
1208 if (mode == 0) {
1209 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1210 } else {
1211 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1212 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001213 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001214 notifyRequester(request);
1215 break;
1216 case CMD_GET_CDMA_ROAMING_MODE:
1217 request = (MainThreadRequest) msg.obj;
1218 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1219 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1220 break;
1221 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1222 ar = (AsyncResult) msg.obj;
1223 request = (MainThreadRequest) ar.userObj;
1224 if (ar.exception != null) {
1225 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1226 } else {
1227 request.result = ((int[]) ar.result)[0];
1228 }
1229 notifyRequester(request);
1230 break;
1231 case CMD_SET_CDMA_ROAMING_MODE:
1232 request = (MainThreadRequest) msg.obj;
1233 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1234 int mode = (int) request.argument;
1235 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1236 break;
1237 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
1240 request.result = ar.exception == null;
1241 notifyRequester(request);
1242 break;
1243 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1244 request = (MainThreadRequest) msg.obj;
1245 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1246 int subscriptionMode = (int) request.argument;
1247 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1248 break;
1249 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1250 ar = (AsyncResult) msg.obj;
1251 request = (MainThreadRequest) ar.userObj;
1252 request.result = ar.exception == null;
1253 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001254 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001255 case CMD_GET_ALL_CELL_INFO:
1256 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001257 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001258 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001259 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001260 case EVENT_GET_ALL_CELL_INFO_DONE:
1261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001263 // If a timeout occurs, the response will be null
1264 request.result = (ar.exception == null && ar.result != null)
1265 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 synchronized (request) {
1267 request.notifyAll();
1268 }
1269 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001270 case CMD_REQUEST_CELL_INFO_UPDATE:
1271 request = (MainThreadRequest) msg.obj;
1272 request.phone.requestCellInfoUpdate(request.workSource,
1273 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1274 break;
1275 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1276 ar = (AsyncResult) msg.obj;
1277 request = (MainThreadRequest) ar.userObj;
1278 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1279 try {
1280 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001281 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001282 cb.onError(
1283 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1284 ar.exception.getClass().getName(),
1285 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001288 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 } else {
1290 // use the result as returned
1291 cb.onCellInfo((List<CellInfo>) ar.result);
1292 }
1293 } catch (RemoteException re) {
1294 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1295 }
1296 break;
1297 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001298 request = (MainThreadRequest) msg.obj;
1299 WorkSource ws = (WorkSource) request.argument;
1300 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001301 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001302 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001303 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 if (ar.exception == null) {
1307 request.result = ar.result;
1308 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001309 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001311 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001312 }
1313
1314 synchronized (request) {
1315 request.notifyAll();
1316 }
1317 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001318 case CMD_MODEM_REBOOT:
1319 request = (MainThreadRequest) msg.obj;
1320 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001321 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001322 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001323 case EVENT_CMD_MODEM_REBOOT_DONE:
1324 handleNullReturnEvent(msg, "rebootModem");
1325 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001326 case CMD_REQUEST_ENABLE_MODEM:
1327 request = (MainThreadRequest) msg.obj;
1328 boolean enable = (boolean) request.argument;
1329 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001330 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001331 PhoneConfigurationManager.getInstance()
1332 .enablePhone(request.phone, enable, onCompleted);
1333 break;
1334 case EVENT_ENABLE_MODEM_DONE:
1335 ar = (AsyncResult) msg.obj;
1336 request = (MainThreadRequest) ar.userObj;
1337 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001338 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001339 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001340 if ((boolean) request.result) {
1341 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1342 updateModemStateMetrics();
1343 } else {
1344 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1345 + ar.exception);
1346 }
1347 notifyRequester(request);
1348 break;
1349 case CMD_GET_MODEM_STATUS:
1350 request = (MainThreadRequest) msg.obj;
1351 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1352 PhoneConfigurationManager.getInstance()
1353 .getPhoneStatusFromModem(request.phone, onCompleted);
1354 break;
1355 case EVENT_GET_MODEM_STATUS_DONE:
1356 ar = (AsyncResult) msg.obj;
1357 request = (MainThreadRequest) ar.userObj;
1358 int id = request.phone.getPhoneId();
1359 if (ar.exception == null && ar.result != null) {
1360 request.result = ar.result;
1361 //update the cache as modem status has changed
1362 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1363 (boolean) request.result);
1364 } else {
1365 // Return true if modem status cannot be retrieved. For most cases,
1366 // modem status is on. And for older version modems, GET_MODEM_STATUS
1367 // and disable modem are not supported. Modem is always on.
1368 // TODO: this should be fixed in R to support a third
1369 // status UNKNOWN b/131631629
1370 request.result = true;
1371 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1372 + ar.exception);
1373 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001374 notifyRequester(request);
1375 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001376 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1379 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1380 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1381 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1382 break;
1383 }
1384 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1388 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1389 args.second.accept(ar.exception == null);
1390 notifyRequester(request);
1391 break;
1392 }
yincheng zhaod698b842019-09-06 17:06:54 -07001393 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 if (ar.exception == null && ar.result != null) {
1397 request.result = ar.result;
1398 } else {
1399 request.result = -1;
1400 loge("Failed to set Forbidden Plmns");
1401 if (ar.result == null) {
1402 loge("setForbidenPlmns: Empty response");
1403 } else if (ar.exception != null) {
1404 loge("setForbiddenPlmns: Exception: " + ar.exception);
1405 request.result = -1;
1406 } else {
1407 loge("setForbiddenPlmns: Unknown exception");
1408 }
1409 }
1410 notifyRequester(request);
1411 break;
1412 case CMD_SET_FORBIDDEN_PLMNS:
1413 request = (MainThreadRequest) msg.obj;
1414 uiccCard = getUiccCardFromRequest(request);
1415 if (uiccCard == null) {
1416 loge("setForbiddenPlmns: UiccCard is null");
1417 request.result = -1;
1418 notifyRequester(request);
1419 break;
1420 }
1421 Pair<Integer, List<String>> setFplmnsArgs =
1422 (Pair<Integer, List<String>>) request.argument;
1423 appType = setFplmnsArgs.first;
1424 List<String> fplmns = setFplmnsArgs.second;
1425 uiccApp = uiccCard.getApplicationByType(appType);
1426 if (uiccApp == null) {
1427 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1428 request.result = -1;
1429 loge("Failed to get UICC App");
1430 notifyRequester(request);
1431 } else {
1432 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1433 ((SIMRecords) uiccApp.getIccRecords())
1434 .setForbiddenPlmns(onCompleted, fplmns);
1435 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001436 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001437 case CMD_ERASE_MODEM_CONFIG:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1440 defaultPhone.eraseModemConfig(onCompleted);
1441 break;
1442 case EVENT_ERASE_MODEM_CONFIG_DONE:
1443 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001444 break;
zoey chenf95ca592019-12-30 16:11:23 +08001445
1446 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1447 request = (MainThreadRequest) msg.obj;
1448 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1449 Pair<String, String> changed = (Pair<String, String>) request.argument;
1450 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1451 changed.first, changed.second, onCompleted);
1452 break;
1453 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
1456 if (ar.exception == null) {
1457 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1458 } else {
1459 request.result = msg.arg1;
1460 }
1461 notifyRequester(request);
1462 break;
1463
1464 case CMD_SET_ICC_LOCK_ENABLED:
1465 request = (MainThreadRequest) msg.obj;
1466 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1467 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1468 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1469 enabled.first, enabled.second, onCompleted);
1470 break;
1471 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
1474 if (ar.exception == null) {
1475 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1476 } else {
1477 request.result = msg.arg1;
1478 }
1479 notifyRequester(request);
1480 break;
1481
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 default:
1483 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1484 break;
1485 }
1486 }
Jake Hambye994d462014-02-03 13:10:13 -08001487
Pengquan Menga1bb6272018-09-06 09:59:22 -07001488 private void notifyRequester(MainThreadRequest request) {
1489 synchronized (request) {
1490 request.notifyAll();
1491 }
1492 }
1493
Jake Hambye994d462014-02-03 13:10:13 -08001494 private void handleNullReturnEvent(Message msg, String command) {
1495 AsyncResult ar = (AsyncResult) msg.obj;
1496 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1497 if (ar.exception == null) {
1498 request.result = true;
1499 } else {
1500 request.result = false;
1501 if (ar.exception instanceof CommandException) {
1502 loge(command + ": CommandException: " + ar.exception);
1503 } else {
1504 loge(command + ": Unknown exception");
1505 }
1506 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001507 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 }
1510
1511 /**
1512 * Posts the specified command to be executed on the main thread,
1513 * waits for the request to complete, and returns the result.
1514 * @see #sendRequestAsync
1515 */
1516 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001517 return sendRequest(
1518 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001519 }
1520
1521 /**
1522 * Posts the specified command to be executed on the main thread,
1523 * waits for the request to complete, and returns the result.
1524 * @see #sendRequestAsync
1525 */
1526 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1527 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001528 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001529 }
1530
1531 /**
1532 * Posts the specified command to be executed on the main thread,
1533 * waits for the request to complete, and returns the result.
1534 * @see #sendRequestAsync
1535 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001536 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001537 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001538 }
1539
1540 /**
1541 * Posts the specified command to be executed on the main thread,
1542 * waits for the request to complete, and returns the result.
1543 * @see #sendRequestAsync
1544 */
Nathan Harold92bed182018-10-12 18:16:49 -07001545 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1546 return sendRequest(command, argument, subId, null, workSource);
1547 }
1548
1549 /**
1550 * Posts the specified command to be executed on the main thread,
1551 * waits for the request to complete, and returns the result.
1552 * @see #sendRequestAsync
1553 */
1554 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1555 return sendRequest(
1556 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1557 }
1558
1559 /**
1560 * Posts the specified command to be executed on the main thread,
1561 * waits for the request to complete, and returns the result.
1562 * @see #sendRequestAsync
1563 */
1564 private Object sendRequest(
1565 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1567 throw new RuntimeException("This method will deadlock if called from the main thread.");
1568 }
1569
Nathan Harold92bed182018-10-12 18:16:49 -07001570 MainThreadRequest request = null;
1571 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1572 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1573 } else if (phone != null) {
1574 request = new MainThreadRequest(argument, phone, workSource);
1575 } else {
1576 request = new MainThreadRequest(argument, subId, workSource);
1577 }
1578
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 Message msg = mMainThreadHandler.obtainMessage(command, request);
1580 msg.sendToTarget();
1581
1582 // Wait for the request to complete
1583 synchronized (request) {
1584 while (request.result == null) {
1585 try {
1586 request.wait();
1587 } catch (InterruptedException e) {
1588 // Do nothing, go back and wait until the request is complete
1589 }
1590 }
1591 }
1592 return request.result;
1593 }
1594
1595 /**
1596 * Asynchronous ("fire and forget") version of sendRequest():
1597 * Posts the specified command to be executed on the main thread, and
1598 * returns immediately.
1599 * @see #sendRequest
1600 */
1601 private void sendRequestAsync(int command) {
1602 mMainThreadHandler.sendEmptyMessage(command);
1603 }
1604
1605 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001606 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001607 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001608 */
1609 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 sendRequestAsync(command, argument, null, null);
1611 }
1612
1613 /**
1614 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1615 * @see {@link #sendRequest(int,Object)}
1616 */
1617 private void sendRequestAsync(
1618 int command, Object argument, Phone phone, WorkSource workSource) {
1619 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001620 Message msg = mMainThreadHandler.obtainMessage(command, request);
1621 msg.sendToTarget();
1622 }
1623
1624 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 * Initialize the singleton PhoneInterfaceManager instance.
1626 * This is only done once, at startup, from PhoneApp.onCreate().
1627 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001628 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 synchronized (PhoneInterfaceManager.class) {
1630 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001631 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 } else {
1633 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1634 }
1635 return sInstance;
1636 }
1637 }
1638
1639 /** Private constructor; @see init() */
Jordan Liua39e6c12020-03-04 13:59:23 -08001640 @VisibleForTesting
1641 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001644 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001645 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1647 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001648 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001649 mTelephonySharedPreferences =
1650 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001651 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001652 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001653
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 publish();
1655 }
1656
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001657 private Phone getDefaultPhone() {
1658 Phone thePhone = getPhone(getDefaultSubscription());
1659 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1660 }
1661
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 private void publish() {
1663 if (DBG) log("publish: " + this);
1664
1665 ServiceManager.addService("phone", this);
1666 }
1667
Stuart Scott584921c2015-01-15 17:10:34 -08001668 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001669 if (request.phone != null) {
1670 return request.phone;
1671 } else {
1672 return getPhoneFromSubId(request.subId);
1673 }
1674 }
1675
1676 private Phone getPhoneFromSubId(int subId) {
1677 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1678 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001679 }
1680
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001681 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1682 Phone phone = getPhoneFromRequest(request);
1683 return phone == null ? null :
1684 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1685 }
1686
Wink Saville36469e72014-06-11 15:17:00 -07001687 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001688 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001689 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001692 private void sendEraseModemConfig(Phone phone) {
1693 if (phone != null) {
1694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1695 mApp, phone.getSubId(), "eraseModemConfig");
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1699 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
1702 }
1703 }
1704 }
1705
Peter Wang050bb052020-01-13 23:33:09 -08001706 private boolean isImsAvailableOnDevice() {
1707 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1708 if (pm == null) {
1709 // For some reason package manger is not available.. This will fail internally anyway,
1710 // so do not throw error and allow.
1711 return true;
1712 }
1713 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1714 }
1715
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001717 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Wink Savilleb564aae2014-10-23 10:18:09 -07001720 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 if (DBG) log("dial: " + number);
1722 // No permission check needed here: This is just a wrapper around the
1723 // ACTION_DIAL intent, which is available to any app since it puts up
1724 // the UI before it does anything.
1725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 String url = createTelUrl(number);
1729 if (url == null) {
1730 return;
1731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 // PENDING: should we just silently fail if phone is offhook or ringing?
1734 PhoneConstants.State state = mCM.getState(subId);
1735 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1736 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1737 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1738 mApp.startActivity(intent);
1739 }
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
1743 }
1744
1745 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001746 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001747 }
1748
Wink Savilleb564aae2014-10-23 10:18:09 -07001749 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 if (DBG) log("call: " + number);
1751
1752 // This is just a wrapper around the ACTION_CALL intent, but we still
1753 // need to do a permission check since we're calling startActivity()
1754 // from the context of the phone app.
1755 enforceCallPermission();
1756
Jordan Liu1617b712019-07-10 15:06:26 -07001757 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 != AppOpsManager.MODE_ALLOWED) {
1759 return;
1760 }
1761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 String url = createTelUrl(number);
1765 if (url == null) {
1766 return;
1767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001769 boolean isValid = false;
1770 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1771 if (slist != null) {
1772 for (SubscriptionInfo subInfoRecord : slist) {
1773 if (subInfoRecord.getSubscriptionId() == subId) {
1774 isValid = true;
1775 break;
1776 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001777 }
Wink Saville08874612014-08-31 19:19:58 -07001778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 if (!isValid) {
1780 return;
1781 }
Wink Saville08874612014-08-31 19:19:58 -07001782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1784 intent.putExtra(SUBSCRIPTION_KEY, subId);
1785 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1786 mApp.startActivity(intent);
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
1789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Wink Savilleb564aae2014-10-23 10:18:09 -07001792 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001793 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001794 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1795 }
1796
Wink Savilleb564aae2014-10-23 10:18:09 -07001797 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001798 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001799 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1800 }
1801
Wink Savilleb564aae2014-10-23 10:18:09 -07001802 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001804
1805 final long identity = Binder.clearCallingIdentity();
1806 try {
1807 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1808 checkSimPin.start();
1809 return checkSimPin.unlockSim(null, pin);
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
1812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Wink Savilleb564aae2014-10-23 10:18:09 -07001815 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001817
1818 final long identity = Binder.clearCallingIdentity();
1819 try {
1820 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1821 checkSimPuk.start();
1822 return checkSimPuk.unlockSim(puk, pin);
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
1825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
1828 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001829 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 * a synchronous one.
1831 */
1832 private static class UnlockSim extends Thread {
1833
1834 private final IccCard mSimCard;
1835
1836 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001837 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1838 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839
1840 // For replies from SimCard interface
1841 private Handler mHandler;
1842
1843 // For async handler to identify request type
1844 private static final int SUPPLY_PIN_COMPLETE = 100;
1845
1846 public UnlockSim(IccCard simCard) {
1847 mSimCard = simCard;
1848 }
1849
1850 @Override
1851 public void run() {
1852 Looper.prepare();
1853 synchronized (UnlockSim.this) {
1854 mHandler = new Handler() {
1855 @Override
1856 public void handleMessage(Message msg) {
1857 AsyncResult ar = (AsyncResult) msg.obj;
1858 switch (msg.what) {
1859 case SUPPLY_PIN_COMPLETE:
1860 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1861 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001862 mRetryCount = msg.arg1;
1863 if (ar.exception != null) {
1864 if (ar.exception instanceof CommandException &&
1865 ((CommandException)(ar.exception)).getCommandError()
1866 == CommandException.Error.PASSWORD_INCORRECT) {
1867 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001868 } //When UiccCardApp dispose,handle message and return exception
1869 else if (ar.exception instanceof CommandException &&
1870 ((CommandException) (ar.exception)).getCommandError()
1871 == CommandException.Error.ABORTED) {
1872 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001873 } else {
1874 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1875 }
1876 } else {
1877 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 mDone = true;
1880 UnlockSim.this.notifyAll();
1881 }
1882 break;
1883 }
1884 }
1885 };
1886 UnlockSim.this.notifyAll();
1887 }
1888 Looper.loop();
1889 }
1890
1891 /*
1892 * Use PIN or PUK to unlock SIM card
1893 *
1894 * If PUK is null, unlock SIM card with PIN
1895 *
1896 * If PUK is not null, unlock SIM card with PUK and set PIN code
1897 */
Wink Saville9de0f752013-10-22 19:04:03 -07001898 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899
1900 while (mHandler == null) {
1901 try {
1902 wait();
1903 } catch (InterruptedException e) {
1904 Thread.currentThread().interrupt();
1905 }
1906 }
1907 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1908
1909 if (puk == null) {
1910 mSimCard.supplyPin(pin, callback);
1911 } else {
1912 mSimCard.supplyPuk(puk, pin, callback);
1913 }
1914
1915 while (!mDone) {
1916 try {
1917 Log.d(LOG_TAG, "wait for done");
1918 wait();
1919 } catch (InterruptedException e) {
1920 // Restore the interrupted status
1921 Thread.currentThread().interrupt();
1922 }
1923 }
1924 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001925 int[] resultArray = new int[2];
1926 resultArray[0] = mResult;
1927 resultArray[1] = mRetryCount;
1928 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930 }
1931
1932 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001933 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001934
1935 }
1936
Wink Savilleb564aae2014-10-23 10:18:09 -07001937 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 // No permission check needed here: this call is harmless, and it's
1939 // needed for the ServiceState.requestStateUpdate() call (which is
1940 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001941 final long identity = Binder.clearCallingIdentity();
1942 try {
1943 final Phone phone = getPhone(subId);
1944 if (phone != null) {
1945 phone.updateServiceLocation();
1946 }
1947 } finally {
1948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
1951
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001952 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001953 @Override
1954 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001955 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001958 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001959 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1960 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1961 callingFeatureId);
1962 }
1963
1964 @Deprecated
1965 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001966 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001967 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1968 }
1969
1970 @Override
1971 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1972 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001974 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001975 return false;
1976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001977
1978 final long identity = Binder.clearCallingIdentity();
1979 try {
1980 return isRadioOnForSubscriber(subId);
1981 } finally {
1982 Binder.restoreCallingIdentity(identity);
1983 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001984 }
1985
1986 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 final Phone phone = getPhone(subId);
1990 if (phone != null) {
1991 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1992 } else {
1993 return false;
1994 }
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999
2000 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002001 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
Wink Saville36469e72014-06-11 15:17:00 -07002003
Wink Savilleb564aae2014-10-23 10:18:09 -07002004 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002006
2007 final long identity = Binder.clearCallingIdentity();
2008 try {
2009 final Phone phone = getPhone(subId);
2010 if (phone != null) {
2011 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2012 }
2013 } finally {
2014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002015 }
Wink Saville36469e72014-06-11 15:17:00 -07002016 }
2017
2018 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002019 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002020 }
2021
Wink Savilleb564aae2014-10-23 10:18:09 -07002022 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024
2025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 final Phone phone = getPhone(subId);
2028 if (phone == null) {
2029 return false;
2030 }
2031 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2032 toggleRadioOnOffForSubscriber(subId);
2033 }
2034 return true;
2035 } finally {
2036 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 }
Wink Saville36469e72014-06-11 15:17:00 -07002039
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002040 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002041 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002042 /*
2043 * If any of the Radios are available, it will need to be
2044 * shutdown. So return true if any Radio is available.
2045 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002046 final long identity = Binder.clearCallingIdentity();
2047 try {
2048 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2049 Phone phone = PhoneFactory.getPhone(i);
2050 if (phone != null && phone.isRadioAvailable()) return true;
2051 }
2052 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2053 return false;
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002056 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002057 }
2058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002060 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 enforceModifyPermission();
2062
2063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2066 logv("Shutting down Phone " + i);
2067 shutdownRadioUsingPhoneId(i);
2068 }
2069 } finally {
2070 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002071 }
2072 }
2073
2074 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002075 Phone phone = PhoneFactory.getPhone(phoneId);
2076 if (phone != null && phone.isRadioAvailable()) {
2077 phone.shutdownRadio();
2078 }
2079 }
2080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002082 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002083
2084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2087 if (defaultPhone != null) {
2088 defaultPhone.setRadioPower(turnOn);
2089 return true;
2090 } else {
2091 loge("There's no default phone.");
2092 return false;
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002096 }
Wink Saville36469e72014-06-11 15:17:00 -07002097 }
2098
Wink Savilleb564aae2014-10-23 10:18:09 -07002099 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.setRadioPower(turnOn);
2107 return true;
2108 } else {
2109 return false;
2110 }
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
Wink Saville36469e72014-06-11 15:17:00 -07002116 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 public boolean enableDataConnectivity() {
2119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120
2121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 int subId = mSubscriptionController.getDefaultDataSubId();
2124 final Phone phone = getPhone(subId);
2125 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002126 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002127 return true;
2128 } else {
2129 return false;
2130 }
2131 } finally {
2132 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
2135
Wink Saville36469e72014-06-11 15:17:00 -07002136 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002137 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 public boolean disableDataConnectivity() {
2139 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002140
2141 final long identity = Binder.clearCallingIdentity();
2142 try {
2143 int subId = mSubscriptionController.getDefaultDataSubId();
2144 final Phone phone = getPhone(subId);
2145 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002146 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 return true;
2148 } else {
2149 return false;
2150 }
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 }
2155
Sanket Padawe356d7632015-06-22 14:03:32 -07002156 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002157 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002158 final long identity = Binder.clearCallingIdentity();
2159 try {
2160 final Phone phone = getPhone(subId);
2161 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002162 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163 } else {
2164 return false;
2165 }
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
2171 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002172 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002173 }
2174
pkanwarae03a6b2016-11-06 20:37:09 -08002175 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 enforceCallPermission();
2177
2178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2181 return;
2182 }
2183 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2184 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
2187 }
pkanwar32d516d2016-10-14 19:37:38 -07002188 };
2189
Wink Savilleb564aae2014-10-23 10:18:09 -07002190 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2196 return false;
2197 }
2198 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2199 } finally {
2200 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 }
2203
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002205 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002206 }
2207
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002208 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 Phone phone = PhoneFactory.getPhone(slotIndex);
2212 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2213 PhoneConstantConversions.convertCallState(phone.getState());
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
2216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002220 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002221 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2222 }
2223
2224 @Override
2225 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 final long identity = Binder.clearCallingIdentity();
2227 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002228 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 if (phone != null) {
2230 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2231 } else {
2232 return PhoneConstantConversions.convertDataState(
2233 PhoneConstants.DataState.DISCONNECTED);
2234 }
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239
Sanket Padawe356d7632015-06-22 14:03:32 -07002240 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002241 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002242 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2243 }
2244
2245 @Override
2246 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247 final long identity = Binder.clearCallingIdentity();
2248 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002249 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 if (phone != null) {
2251 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2252 } else {
2253 return TelephonyManager.DATA_ACTIVITY_NONE;
2254 }
2255 } finally {
2256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259
2260 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002261 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002262 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002263 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002264
2265 LocationAccessPolicy.LocationPermissionResult locationResult =
2266 LocationAccessPolicy.checkLocationPermission(mApp,
2267 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2268 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002269 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002270 .setCallingPid(Binder.getCallingPid())
2271 .setCallingUid(Binder.getCallingUid())
2272 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002273 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002274 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2275 .build());
2276 switch (locationResult) {
2277 case DENIED_HARD:
2278 throw new SecurityException("Not allowed to access cell location");
2279 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002280 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2281 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002288 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002289 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
Svetoslav64fad262015-04-14 14:35:21 -07002293 }
2294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 @Override
Jack Yu01425032020-02-22 19:38:58 -08002296 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002297 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2298 // registered cell info, so return a NULL country instead.
2299 final long identity = Binder.clearCallingIdentity();
2300 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002301 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2302 // Get default phone in this case.
2303 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2304 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002305 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002307 if (phone == null) return "";
2308 ServiceStateTracker sst = phone.getServiceStateTracker();
2309 if (sst == null) return "";
2310 LocaleTracker lt = sst.getLocaleTracker();
2311 if (lt == null) return "";
2312 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2313 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2314 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002318 }
2319
2320 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002322 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002323 }
2324
Sanket Padawe356d7632015-06-22 14:03:32 -07002325 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 mApp.enforceCallingOrSelfPermission(
2328 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002329
2330 final long identity = Binder.clearCallingIdentity();
2331 try {
2332 final Phone phone = getPhone(subId);
2333 if (phone != null) {
2334 phone.enableLocationUpdates();
2335 }
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
2341 @Override
2342 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002343 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002344 }
2345
Sanket Padawe356d7632015-06-22 14:03:32 -07002346 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002347 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 mApp.enforceCallingOrSelfPermission(
2349 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350
2351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 final Phone phone = getPhone(subId);
2354 if (phone != null) {
2355 phone.disableLocationUpdates();
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
Nathan Harold31d7ff32018-10-15 20:20:30 -07002362 /**
2363 * Returns the target SDK version number for a given package name.
2364 *
Nathan Haroldec184742019-07-10 17:04:16 -07002365 * This call MUST be invoked before clearing the calling UID.
2366 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002367 * @return target SDK if the package is found or INT_MAX.
2368 */
2369 private int getTargetSdk(String packageName) {
2370 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002371 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002372 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002373 if (ai != null) return ai.targetSdkVersion;
2374 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002375 loge("Failed to get package info for pkg="
2376 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002377 }
2378 return Integer.MAX_VALUE;
2379 }
2380
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 @Override
2382 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002383 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2384 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002385 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002386 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2387 throw new SecurityException(
2388 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2389 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002390
Jordan Liu1617b712019-07-10 15:06:26 -07002391 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2393 return null;
2394 }
Svetoslav64fad262015-04-14 14:35:21 -07002395
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002396 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002398 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002399 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400
Nathan Haroldf180aac2018-06-01 18:43:55 -07002401 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2402 for (CellInfo ci : info) {
2403 if (ci instanceof CellInfoGsm) {
2404 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2405 } else if (ci instanceof CellInfoWcdma) {
2406 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002409 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
2411
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002412 private List<CellInfo> getCachedCellInfo() {
2413 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2414 for (Phone phone : PhoneFactory.getPhones()) {
2415 List<CellInfo> info = phone.getAllCellInfo();
2416 if (info != null) cellInfos.addAll(info);
2417 }
2418 return cellInfos;
2419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420
2421 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002422 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002423 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002424 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002425
2426 LocationAccessPolicy.LocationPermissionResult locationResult =
2427 LocationAccessPolicy.checkLocationPermission(mApp,
2428 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2429 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002430 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002431 .setCallingPid(Binder.getCallingPid())
2432 .setCallingUid(Binder.getCallingUid())
2433 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002434 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002435 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2436 .build());
2437 switch (locationResult) {
2438 case DENIED_HARD:
2439 throw new SecurityException("Not allowed to access cell info");
2440 case DENIED_SOFT:
2441 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 }
2443
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002444 final int targetSdk = getTargetSdk(callingPackage);
2445 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2446 return getCachedCellInfo();
2447 }
2448
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002449 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002450 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2454 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002455 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002456 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 if (info != null) cellInfos.addAll(info);
2458 }
2459 return cellInfos;
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463 }
2464
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002465 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002466 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2467 String callingFeatureId) {
2468 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2469 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002470 }
2471
2472 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002473 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2474 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002475 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002476 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002477 }
2478
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002479 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2480 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002481 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002482 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002483
2484 LocationAccessPolicy.LocationPermissionResult locationResult =
2485 LocationAccessPolicy.checkLocationPermission(mApp,
2486 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2487 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002488 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002489 .setCallingPid(Binder.getCallingPid())
2490 .setCallingUid(Binder.getCallingUid())
2491 .setMethod("requestCellInfoUpdate")
2492 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2493 .build());
2494 switch (locationResult) {
2495 case DENIED_HARD:
2496 throw new SecurityException("Not allowed to access cell info");
2497 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002498 try {
2499 cb.onCellInfo(new ArrayList<CellInfo>());
2500 } catch (RemoteException re) {
2501 // Drop without consequences
2502 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002503 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002504 }
2505
Nathan Harolda939a962019-05-09 10:13:47 -07002506
2507 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002508 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2509
2510 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2511 }
2512
2513 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002515 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002516 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002520 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521 } finally {
2522 Binder.restoreCallingIdentity(identity);
2523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
Shishir Agrawala9f32182016-04-12 12:00:16 -07002526 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002527 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 Phone phone = PhoneFactory.getPhone(slotIndex);
2529 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002530 return null;
2531 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002532 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002533 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002534 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002535 return null;
2536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 return phone.getImei();
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002544 }
2545
2546 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002547 public String getTypeAllocationCodeForSlot(int slotIndex) {
2548 Phone phone = PhoneFactory.getPhone(slotIndex);
2549 String tac = null;
2550 if (phone != null) {
2551 String imei = phone.getImei();
2552 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2553 }
2554 return tac;
2555 }
2556
2557 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002558 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002559 Phone phone = PhoneFactory.getPhone(slotIndex);
2560 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002561 return null;
2562 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002563
Jeff Davidson913390f2018-02-23 17:11:49 -08002564 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002565 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002566 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002567 return null;
2568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 return phone.getMeid();
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
2575 }
Jack Yu2af8d712017-03-15 17:14:14 -07002576 }
2577
2578 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002579 public String getManufacturerCodeForSlot(int slotIndex) {
2580 Phone phone = PhoneFactory.getPhone(slotIndex);
2581 String manufacturerCode = null;
2582 if (phone != null) {
2583 String meid = phone.getMeid();
2584 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2585 }
2586 return manufacturerCode;
2587 }
2588
2589 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002590 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2591 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002592 Phone phone = PhoneFactory.getPhone(slotIndex);
2593 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002594 return null;
2595 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002596 int subId = phone.getSubId();
2597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002598 mApp, subId, callingPackage, callingFeatureId,
2599 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002600 return null;
2601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602
2603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 return phone.getDeviceSvn();
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
2608 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002609 }
2610
fionaxu43304da2017-11-27 22:51:16 -08002611 @Override
2612 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 final Phone phone = getPhone(subId);
2616 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
2619 }
fionaxu43304da2017-11-27 22:51:16 -08002620 }
2621
2622 @Override
2623 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 final Phone phone = getPhone(subId);
2627 return phone == null ? null : phone.getCarrierName();
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
2630 }
fionaxu43304da2017-11-27 22:51:16 -08002631 }
2632
calvinpanffe225e2018-11-01 19:43:06 +08002633 @Override
chen xu0026ca62019-03-06 15:28:50 -08002634 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 final Phone phone = getPhone(subId);
2638 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002639 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
2643 }
2644
2645 @Override
chen xu0026ca62019-03-06 15:28:50 -08002646 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002650 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002651 } finally {
2652 Binder.restoreCallingIdentity(identity);
2653 }
2654 }
2655
chen xu651eec72018-11-11 19:03:44 -08002656 @Override
chen xu864e11c2018-12-06 22:10:03 -08002657 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2658 if (!isSubscriptionMccMnc) {
2659 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2660 }
chen xu651eec72018-11-11 19:03:44 -08002661 final Phone phone = PhoneFactory.getPhone(slotIndex);
2662 if (phone == null) {
2663 return TelephonyManager.UNKNOWN_CARRIER_ID;
2664 }
2665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
2671 }
2672
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 //
2674 // Internal helper methods.
2675 //
2676
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002677 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2679 *
2680 * @throws SecurityException if the caller does not have the required permission
2681 */
2682 private void enforceModifyPermission() {
2683 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2684 }
2685
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002686 /**
2687 * Make sure the caller is system.
2688 *
2689 * @throws SecurityException if the caller is not system.
2690 */
2691 private void enforceSystemCaller() {
2692 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2693 throw new SecurityException("Caller must be system");
2694 }
2695 }
2696
Shuo Qianf2b2df42019-11-13 17:43:31 -08002697 private void enforceActiveEmergencySessionPermission() {
2698 mApp.enforceCallingOrSelfPermission(
2699 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2700 }
2701
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 /**
2703 * Make sure the caller has the CALL_PHONE permission.
2704 *
2705 * @throws SecurityException if the caller does not have the required permission
2706 */
2707 private void enforceCallPermission() {
2708 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2709 }
2710
paulhu423b5f22019-08-23 19:17:33 +08002711 private void enforceSettingsPermission() {
2712 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002713 }
2714
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 private String createTelUrl(String number) {
2716 if (TextUtils.isEmpty(number)) {
2717 return null;
2718 }
2719
Jake Hambye994d462014-02-03 13:10:13 -08002720 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 }
2722
Ihab Awadf9e92732013-12-05 18:02:52 -08002723 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2725 }
2726
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002727 private static void logv(String msg) {
2728 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2729 }
2730
Ihab Awadf9e92732013-12-05 18:02:52 -08002731 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002732 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2733 }
2734
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002735 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002737 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002738 }
2739
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002741 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 final Phone phone = PhoneFactory.getPhone(slotIndex);
2745 if (phone == null) {
2746 return PhoneConstants.PHONE_TYPE_NONE;
2747 } else {
2748 return phone.getPhoneType();
2749 }
2750 } finally {
2751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002753 }
2754
2755 /**
2756 * Returns the CDMA ERI icon index to display
2757 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002758 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002759 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2760 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2761 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002762 }
2763
Sanket Padawe356d7632015-06-22 14:03:32 -07002764 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002765 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2766 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002768 mApp, subId, callingPackage, callingFeatureId,
2769 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002770 return -1;
2771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772
2773 final long identity = Binder.clearCallingIdentity();
2774 try {
2775 final Phone phone = getPhone(subId);
2776 if (phone != null) {
2777 return phone.getCdmaEriIconIndex();
2778 } else {
2779 return -1;
2780 }
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 }
2785
2786 /**
2787 * Returns the CDMA ERI icon mode,
2788 * 0 - ON
2789 * 1 - FLASHING
2790 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002791 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002792 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2793 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2794 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002795 }
2796
Sanket Padawe356d7632015-06-22 14:03:32 -07002797 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002798 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2799 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002801 mApp, subId, callingPackage, callingFeatureId,
2802 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002803 return -1;
2804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 final Phone phone = getPhone(subId);
2809 if (phone != null) {
2810 return phone.getCdmaEriIconMode();
2811 } else {
2812 return -1;
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 }
2818
2819 /**
2820 * Returns the CDMA ERI text,
2821 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002822 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002823 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2824 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2825 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002826 }
2827
Sanket Padawe356d7632015-06-22 14:03:32 -07002828 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002829 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2830 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002832 mApp, subId, callingPackage, callingFeatureId,
2833 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002834 return null;
2835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 final Phone phone = getPhone(subId);
2840 if (phone != null) {
2841 return phone.getCdmaEriText();
2842 } else {
2843 return null;
2844 }
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 }
2849
2850 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002851 * Returns the CDMA MDN.
2852 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002853 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002854 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2856 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002861 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 return phone.getLine1Number();
2863 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 return null;
2866 }
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002869 }
2870 }
2871
2872 /**
2873 * Returns the CDMA MIN.
2874 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002876 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2878 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 final Phone phone = getPhone(subId);
2883 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2884 return phone.getCdmaMin();
2885 } else {
2886 return null;
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002890 }
2891 }
2892
Hall Liud892bec2018-11-30 14:51:45 -08002893 @Override
2894 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2895 INumberVerificationCallback callback, String callingPackage) {
2896 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2897 != PERMISSION_GRANTED) {
2898 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2899 }
2900 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2901
2902 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2903 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2904 throw new SecurityException("Calling package must be configured in the device config");
2905 }
2906
2907 if (range == null) {
2908 throw new NullPointerException("Range must be non-null");
2909 }
2910
2911 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002912 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002913
2914 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2915 }
2916
Junda Liuca05d5d2014-08-14 22:36:34 -07002917 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 * Returns true if CDMA provisioning needs to run.
2919 */
2920 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002923 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
2929 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002930 * Sets the voice mail number of a given subId.
2931 */
2932 @Override
2933 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002934 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2935 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936
2937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2940 new Pair<String, String>(alphaTag, number), new Integer(subId));
2941 return success;
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002945 }
2946
Ta-wei Yen87c49842016-05-13 21:19:52 -07002947 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002948 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2949 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002950 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2951 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002952 if (!TextUtils.equals(callingPackage, systemDialer)) {
2953 throw new SecurityException("caller must be system dialer");
2954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2959 if (phoneAccountHandle == null) {
2960 return null;
2961 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002962 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963 } finally {
2964 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002965 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002966 }
2967
2968 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002969 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2970 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002971 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002973 mApp, subId, callingPackage, callingFeatureId,
2974 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002975 return null;
2976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002978 final long identity = Binder.clearCallingIdentity();
2979 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002980 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002984 }
2985
2986 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002987 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2988 VisualVoicemailSmsFilterSettings settings) {
2989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990
2991 final long identity = Binder.clearCallingIdentity();
2992 try {
2993 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002994 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002998 }
2999
3000 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003001 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003007 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003011 }
3012
3013 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003014 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3015 String callingPackage, int subId) {
3016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003021 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003025 }
3026
3027 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003028 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003029 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003038 }
3039
3040 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003041 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3042 String callingAttributionTag, int subId, String number, int port, String text,
3043 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003044 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003045 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003046 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003047 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003048 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3049 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003050 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003051
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003052 /**
fionaxu0152e512016-11-14 13:36:14 -08003053 * Sets the voice activation state of a given subId.
3054 */
3055 @Override
3056 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3058 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 final Phone phone = getPhone(subId);
3063 if (phone != null) {
3064 phone.setVoiceActivationState(activationState);
3065 } else {
3066 loge("setVoiceActivationState fails with invalid subId: " + subId);
3067 }
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003070 }
3071 }
3072
3073 /**
3074 * Sets the data activation state of a given subId.
3075 */
3076 @Override
3077 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3079 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 final Phone phone = getPhone(subId);
3084 if (phone != null) {
3085 phone.setDataActivationState(activationState);
3086 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003087 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003088 }
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003091 }
3092 }
3093
3094 /**
3095 * Returns the voice activation state of a given subId.
3096 */
3097 @Override
3098 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003100
fionaxu0152e512016-11-14 13:36:14 -08003101 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 if (phone != null) {
3105 return phone.getVoiceActivationState();
3106 } else {
3107 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3108 }
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003111 }
3112 }
3113
3114 /**
3115 * Returns the data activation state of a given subId.
3116 */
3117 @Override
3118 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003119 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120
fionaxu0152e512016-11-14 13:36:14 -08003121 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 if (phone != null) {
3125 return phone.getDataActivationState();
3126 } else {
3127 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3128 }
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003131 }
3132 }
3133
3134 /**
Wink Saville36469e72014-06-11 15:17:00 -07003135 * Returns the unread count of voicemails for a subId
3136 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003137 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003138 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3139 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003141 mApp, subId, callingPackage, callingFeatureId,
3142 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003143 return 0;
3144 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 final Phone phone = getPhone(subId);
3148 if (phone != null) {
3149 return phone.getVoiceMessageCount();
3150 } else {
3151 return 0;
3152 }
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157
3158 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003159 * returns true, if the device is in a state where both voice and data
3160 * are supported simultaneously. This can change based on location or network condition.
3161 */
3162 @Override
3163 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 final Phone phone = getPhone(subId);
3167 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003171 }
3172
3173 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003174 * Send the dialer code if called from the current default dialer or the caller has
3175 * carrier privilege.
3176 * @param inputCode The dialer code to send
3177 */
3178 @Override
3179 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003181 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003182 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3183 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003184 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003185 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003186 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188
3189 final long identity = Binder.clearCallingIdentity();
3190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
fionaxu235cc5e2017-03-06 22:25:57 -08003195 }
3196
Pengquan Menga1bb6272018-09-06 09:59:22 -07003197 @Override
3198 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003199 TelephonyPermissions
3200 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3201 mApp, subId, "getNetworkSelectionMode");
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 if (!isActiveSubscription(subId)) {
3205 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3206 }
3207 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003210 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003211 }
3212
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003214 public boolean isInEmergencySmsMode() {
3215 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 for (Phone phone : PhoneFactory.getPhones()) {
3219 if (phone.isInEmergencySmsMode()) {
3220 return true;
3221 }
3222 }
3223 } finally {
3224 Binder.restoreCallingIdentity(identity);
3225 }
3226 return false;
3227 }
3228
shilu366312e2019-12-17 09:28:10 -08003229 /**
3230 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3231 * @param subId The subscription to use to check the configuration.
3232 * @param c The callback that will be used to send the result.
3233 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003234 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003235 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3236 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003237 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3238 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003239
Brad Ebinger77b832e2019-10-17 17:03:22 -07003240 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3241 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3242 "IMS not available on device.");
3243 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 final long token = Binder.clearCallingIdentity();
3245 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003246 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003247 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003249 } catch (ImsException e) {
3250 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003251 } finally {
3252 Binder.restoreCallingIdentity(token);
3253 }
3254 }
3255
shilu366312e2019-12-17 09:28:10 -08003256 /**
3257 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3258 * @param subId The subscription to use to check the configuration.
3259 * @param c The callback that will be used to send the result.
3260 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003262 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003263 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3264 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003265 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3266 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3267 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003268 final long token = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3271 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3272 .removeRegistrationCallbackForSubscription(c, subId);
3273 } catch (ImsException e) {
3274 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3275 + "is inactive, ignoring unregister.");
3276 // If the subscription is no longer active, just return, since the callback
3277 // will already have been removed internally.
3278 } finally {
3279 Binder.restoreCallingIdentity(token);
3280 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 }
3282
Brad Ebinger774ba362019-10-22 17:36:18 -07003283 /**
3284 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3285 */
3286 @Override
3287 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3288 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3289 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3290 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3291 "IMS not available on device.");
3292 }
3293 final long token = Binder.clearCallingIdentity();
3294 try {
3295 Phone phone = getPhone(subId);
3296 if (phone == null) {
3297 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3298 + subId + "'");
3299 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3300 }
3301 phone.getImsRegistrationState(regState -> {
3302 try {
3303 consumer.accept((regState == null)
3304 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3305 } catch (RemoteException e) {
3306 // Ignore if the remote process is no longer available to call back.
3307 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3308 }
3309 });
3310 } finally {
3311 Binder.restoreCallingIdentity(token);
3312 }
3313 }
3314
3315 /**
3316 * Get the transport type for the IMS service registration state.
3317 */
3318 @Override
3319 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003320 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3321 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003322 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3323 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3324 "IMS not available on device.");
3325 }
3326 final long token = Binder.clearCallingIdentity();
3327 try {
3328 Phone phone = getPhone(subId);
3329 if (phone == null) {
3330 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3331 + subId + "'");
3332 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3333 }
3334 phone.getImsRegistrationTech(regTech -> {
3335 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3336 int regTechConverted = (regTech == null)
3337 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3338 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3339 regTechConverted);
3340 try {
3341 consumer.accept(regTechConverted);
3342 } catch (RemoteException e) {
3343 // Ignore if the remote process is no longer available to call back.
3344 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3345 }
3346 });
3347 } finally {
3348 Binder.restoreCallingIdentity(token);
3349 }
3350 }
3351
shilu366312e2019-12-17 09:28:10 -08003352 /**
3353 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3354 * @param subId The subscription to use to check the configuration.
3355 * @param c The callback that will be used to send the result.
3356 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003357 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003358 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3359 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003360 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3361 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003362 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3363 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3364 "IMS not available on device.");
3365 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3367 final long token = Binder.clearCallingIdentity();
3368 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003369 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003371 } catch (ImsException e) {
3372 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003373 } finally {
3374 Binder.restoreCallingIdentity(token);
3375 }
3376 }
3377
shilu366312e2019-12-17 09:28:10 -08003378 /**
3379 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3380 * @param subId The subscription to use to check the configuration.
3381 * @param c The callback that will be used to send the result.
3382 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003384 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003385 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3386 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003387 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3388 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3389 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003390
3391 final long token = Binder.clearCallingIdentity();
3392 try {
3393 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3394 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003395 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003396 } catch (ImsException e) {
3397 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3398 + "is inactive, ignoring unregister.");
3399 // If the subscription is no longer active, just return, since the callback
3400 // will already have been removed internally.
3401 } finally {
3402 Binder.restoreCallingIdentity(token);
3403 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003404 }
3405
3406 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003407 public boolean isCapable(int subId, int capability, int regTech) {
3408 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3410 final long token = Binder.clearCallingIdentity();
3411 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003412 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003414 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3416 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003417 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003418 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3419 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 } finally {
3421 Binder.restoreCallingIdentity(token);
3422 }
3423 }
3424
3425 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003426 public boolean isAvailable(int subId, int capability, int regTech) {
3427 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003428 final long token = Binder.clearCallingIdentity();
3429 try {
3430 Phone phone = getPhone(subId);
3431 if (phone == null) return false;
3432 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003433 } catch (com.android.ims.ImsException e) {
3434 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3435 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 } finally {
3437 Binder.restoreCallingIdentity(token);
3438 }
3439 }
3440
Brad Ebinger77b832e2019-10-17 17:03:22 -07003441 /**
3442 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3443 * subscription.
3444 * @param subId The subscription to use to check the configuration.
3445 * @param callback The callback that will be used to send the result.
3446 * @param capability The MmTelFeature capability that will be used to send the result.
3447 * @param transportType The transport type of the MmTelFeature capability.
3448 */
3449 @Override
3450 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3451 int transportType) {
3452 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3453 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3454 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3455 "IMS not available on device.");
3456 }
3457 final long token = Binder.clearCallingIdentity();
3458 try {
3459 int slotId = getSlotIndex(subId);
3460 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3461 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3462 + subId + "'");
3463 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3464 }
3465 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3466 transportType, aBoolean -> {
3467 try {
3468 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3469 } catch (RemoteException e) {
3470 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3471 + "running. Ignore");
3472 }
3473 });
3474 } finally {
3475 Binder.restoreCallingIdentity(token);
3476 }
3477 }
3478
shilu366312e2019-12-17 09:28:10 -08003479 /**
3480 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3481 * @param subId The subscription to use to check the configuration.
3482 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003483 @Override
3484 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003485 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3486 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003487
Brad Ebinger35c841c2018-10-01 10:40:55 -07003488 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3489 final long token = Binder.clearCallingIdentity();
3490 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003491 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003492 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003493 } catch (ImsException e) {
3494 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003495 } finally {
3496 Binder.restoreCallingIdentity(token);
3497 }
3498 }
3499
3500 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003501 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003503 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003507 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003508 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003509 } catch (ImsException e) {
3510 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
3514 }
3515
shilu366312e2019-12-17 09:28:10 -08003516 /**
3517 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3518 * @param subId The subscription to use to check the configuration.
3519 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003521 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003522 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3523 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003527 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3528 } catch (ImsException e) {
3529 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
3533 }
3534
3535 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003536 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003538 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003542 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003543 } catch (ImsException e) {
3544 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
3548 }
3549
shilu366312e2019-12-17 09:28:10 -08003550 /**
3551 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3552 * @param subId The subscription to use to check the configuration.
3553 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 @Override
3555 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003556 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3557 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003561 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003562 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003563 } catch (ImsException e) {
3564 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 } finally {
3566 Binder.restoreCallingIdentity(identity);
3567 }
3568 }
3569
3570 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003571 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003573 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003577 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003578 } catch (ImsException e) {
3579 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
3583 }
3584
shilu366312e2019-12-17 09:28:10 -08003585 /**
3586 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3587 * @param subId The subscription to use to check the configuration.
3588 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 @Override
3590 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003591 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3592 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003596 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003598 } catch (ImsException e) {
3599 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
3603 }
3604
3605 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003606 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003608 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003612 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003614 } catch (ImsException e) {
3615 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 } finally {
3617 Binder.restoreCallingIdentity(identity);
3618 }
3619 }
3620
3621 @Override
3622 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3624 "setVoWiFiNonPersistent");
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003628 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003629 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003630 } catch (ImsException e) {
3631 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003632 } finally {
3633 Binder.restoreCallingIdentity(identity);
3634 }
3635 }
3636
shilu366312e2019-12-17 09:28:10 -08003637 /**
3638 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3639 * @param subId The subscription to use to check the configuration.
3640 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 @Override
3642 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003643 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3644 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003648 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003649 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003650 } catch (ImsException e) {
3651 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
3655 }
3656
3657 @Override
3658 public void setVoWiFiModeSetting(int subId, int mode) {
3659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3660 "setVoWiFiModeSetting");
3661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003664 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003666 } catch (ImsException e) {
3667 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
3671 }
3672
3673 @Override
3674 public int getVoWiFiRoamingModeSetting(int subId) {
3675 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003679 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003680 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003681 } catch (ImsException e) {
3682 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003683 } finally {
3684 Binder.restoreCallingIdentity(identity);
3685 }
3686 }
3687
3688 @Override
3689 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3691 "setVoWiFiRoamingModeSetting");
3692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003695 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003697 } catch (ImsException e) {
3698 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
3702 }
3703
3704 @Override
3705 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3707 "setRttCapabilityEnabled");
3708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003711 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3712 } catch (ImsException e) {
3713 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
3717 }
3718
shilu366312e2019-12-17 09:28:10 -08003719 /**
3720 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3721 * @param subId The subscription to use to check the configuration.
3722 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 @Override
3724 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003725 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3726 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003730 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003732 } catch (ImsException e) {
3733 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
3737 }
3738
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003739 @Override
3740 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3741 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3742 final long identity = Binder.clearCallingIdentity();
3743 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003744 if (!isImsAvailableOnDevice()) {
3745 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3746 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003747 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003748 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003749 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003750 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003751 } catch (ImsException e) {
3752 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
3756 }
3757
3758 @Override
3759 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3760 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3761 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3763 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3764 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003765 try {
3766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003767 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003768 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003769 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003770 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3771 + "is inactive, ignoring unregister.");
3772 // If the subscription is no longer active, just return, since the callback will already
3773 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003774 } finally {
3775 Binder.restoreCallingIdentity(identity);
3776 }
3777 }
3778
allenwtsu99c623b2020-01-03 18:24:23 +08003779
3780 private void checkModifyPhoneStatePermission(int subId, String message) {
3781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3782 message);
3783 }
3784
3785 private boolean isImsProvisioningRequired(int subId, int capability,
3786 boolean isMmtelCapability) {
3787 Phone phone = getPhone(subId);
3788 if (phone == null) {
3789 loge("phone instance null for subid " + subId);
3790 return false;
3791 }
3792 if (isMmtelCapability) {
3793 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3794 return false;
3795 }
3796 } else {
3797 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3798 return false;
3799 }
3800 }
3801 return true;
3802 }
3803
3804 @Override
3805 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3806 boolean isProvisioned) {
3807 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3808
3809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3812 if (!isImsProvisioningRequired(subId, capability, false)) {
3813 return;
3814 }
3815
3816 // this capability requires provisioning, route to the correct API.
3817 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3818 switch (capability) {
3819 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3820 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3821 ims.setEabProvisioned(isProvisioned);
3822 break;
3823 default: {
3824 throw new IllegalArgumentException("Tried to set provisioning for "
3825 + "rcs capability '" + capability + "', which does not require "
3826 + "provisioning.");
3827 }
3828 }
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
3832
3833 }
3834
3835
3836 @Override
3837 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3838 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3842 if (!isImsProvisioningRequired(subId, capability, false)) {
3843 return true;
3844 }
3845
3846 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3847 switch (capability) {
3848 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3849 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3850 return ims.isEabProvisionedOnDevice();
3851
3852 default: {
3853 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3854 + "capability '" + capability + "', which does not require "
3855 + "provisioning.");
3856 }
3857 }
3858
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862 }
3863
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003864 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003865 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3866 boolean isProvisioned) {
3867 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3868 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3869 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3870 }
allenwtsu99c623b2020-01-03 18:24:23 +08003871 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003875 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003876 return;
3877 }
3878
3879 // this capability requires provisioning, route to the correct API.
3880 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3881 switch (capability) {
3882 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3883 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3884 ims.setVolteProvisioned(isProvisioned);
3885 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3886 ims.setWfcProvisioned(isProvisioned);
3887 }
3888 break;
3889 }
3890 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3891 // There is currently no difference in VT provisioning type.
3892 ims.setVtProvisioned(isProvisioned);
3893 break;
3894 }
3895 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3896 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3897 // change the capability of the feature instead if needed.
3898 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3899 == isProvisioned) {
3900 // No change in provisioning.
3901 return;
3902 }
3903 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3904 try {
3905 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003906 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003907 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3908 + ", Exception" + e.getMessage());
3909 }
3910 break;
3911 }
3912 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003913 throw new IllegalArgumentException("Tried to set provisioning for "
3914 + "MmTel capability '" + capability + "', which does not require "
3915 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003916 }
3917 }
3918
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
3921 }
3922 }
3923
3924 @Override
3925 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3926 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3927 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3928 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3929 }
3930 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003934 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003935 return true;
3936 }
3937
3938 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3939 switch (capability) {
3940 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3941 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3942 return ims.isVolteProvisionedOnDevice();
3943 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3944 return ims.isWfcProvisionedOnDevice();
3945 }
3946 // This should never happen, since we are checking tech above to make sure it
3947 // is either LTE or IWLAN.
3948 throw new IllegalArgumentException("Invalid radio technology for voice "
3949 + "capability.");
3950 }
3951 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3952 // There is currently no difference in VT provisioning type.
3953 return ims.isVtProvisionedOnDevice();
3954 }
3955 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3956 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3957 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3958 }
3959 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003960 throw new IllegalArgumentException(
3961 "Tried to get provisioning for MmTel capability '" + capability
3962 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003963 }
3964 }
3965
3966 } finally {
3967 Binder.restoreCallingIdentity(identity);
3968 }
3969 }
3970
3971 @Override
3972 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3973 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3974 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3975 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3976 }
3977 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3978 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3979 return (provisionedBits & capability) > 0;
3980 }
3981
3982 @Override
3983 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3984 boolean isProvisioned) {
3985 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3986 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3987 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3988 }
3989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3990 "setProvisioningStatusForCapability");
3991 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3992 // If the current provisioning status for capability already matches isProvisioned,
3993 // do nothing.
3994 if (((provisionedBits & capability) > 0) == isProvisioned) {
3995 return;
3996 }
3997 if (isProvisioned) {
3998 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3999 } else {
4000 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4001 }
4002 }
4003
4004 /**
4005 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4006 * technology. The bitfield should mirror the bitfield defined by
4007 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4008 */
4009 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4010 String key = getMmTelProvisioningKey(subId, tech);
4011 // Default is no capabilities are provisioned.
4012 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4013 }
4014
4015 /**
4016 * Sets the MmTel capability provisioning bitfield (defined by
4017 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4018 * technology specified.
4019 *
4020 * Note: This is a synchronous command and should not be called on UI thread.
4021 */
4022 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4023 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4024 String key = getMmTelProvisioningKey(subId, tech);
4025 editor.putInt(key, newField);
4026 editor.commit();
4027 }
4028
4029 private static String getMmTelProvisioningKey(int subId, int tech) {
4030 // resulting key is provision_ims_mmtel_{subId}_{tech}
4031 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4032 }
4033
4034 /**
4035 * Query CarrierConfig to see if the specified capability requires provisioning for the
4036 * carrier associated with the subscription id.
4037 */
4038 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4039 int capability) {
4040 CarrierConfigManager configManager = new CarrierConfigManager(context);
4041 PersistableBundle c = configManager.getConfigForSubId(subId);
4042 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004043 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004044 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4045 false);
4046 boolean requireVoiceVtProvisioning = c.getBoolean(
4047 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4048
4049 // First check to make sure that the capability requires provisioning.
4050 switch (capability) {
4051 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4052 // intentional fallthrough
4053 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4054 if (requireVoiceVtProvisioning) {
4055 // Voice and Video requires provisioning
4056 return true;
4057 }
4058 break;
4059 }
4060 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4061 if (requireUtProvisioning) {
4062 // UT requires provisioning
4063 return true;
4064 }
4065 break;
4066 }
4067 }
4068 return false;
4069 }
4070
allenwtsu99c623b2020-01-03 18:24:23 +08004071 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4072 int capability) {
4073 CarrierConfigManager configManager = new CarrierConfigManager(context);
4074 PersistableBundle c = configManager.getConfigForSubId(subId);
4075
4076 boolean requireRcsProvisioning = c.getBoolean(
4077 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4078
4079 // First check to make sure that the capability requires provisioning.
4080 switch (capability) {
4081 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4082 // intentional fallthrough
4083 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4084 if (requireRcsProvisioning) {
4085 // OPTION or PRESENCE requires provisioning
4086 return true;
4087 }
4088 break;
4089 }
4090 }
4091 return false;
4092 }
4093
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004094 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004095 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004096 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4097 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4098 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004099 enforceReadPrivilegedPermission("getImsProvisioningInt");
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004103 int slotId = getSlotIndex(subId);
4104 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4105 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4106 + subId + "' for key:" + key);
4107 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4108 }
4109 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004110 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004111 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4112 + subId + "' for key:" + key);
4113 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
4117 }
4118
4119 @Override
4120 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004121 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4122 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4123 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004124 enforceReadPrivilegedPermission("getImsProvisioningString");
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004128 int slotId = getSlotIndex(subId);
4129 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4130 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4131 + subId + "' for key:" + key);
4132 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4133 }
4134 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004136 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4137 + subId + "' for key:" + key);
4138 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004139 } finally {
4140 Binder.restoreCallingIdentity(identity);
4141 }
4142 }
4143
4144 @Override
4145 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004146 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4147 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4148 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4150 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004154 int slotId = getSlotIndex(subId);
4155 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4156 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4157 + subId + "' for key:" + key);
4158 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4159 }
4160 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004161 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004162 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4163 + "' for key:" + key);
4164 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
4168 }
4169
4170 @Override
4171 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004172 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4173 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4174 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4176 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004180 int slotId = getSlotIndex(subId);
4181 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4182 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4183 + subId + "' for key:" + key);
4184 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4185 }
4186 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004187 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004188 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4189 + "' for key:" + key);
4190 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
4194 }
4195
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 int slotId = SubscriptionManager.getSlotIndex(subId);
4198 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004199 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4200 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 }
4202 return slotId;
4203 }
4204
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004205 private int getSlotIndex(int subId) {
4206 int slotId = SubscriptionManager.getSlotIndex(subId);
4207 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4208 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4209 }
4210 return slotId;
4211 }
4212
Wink Saville36469e72014-06-11 15:17:00 -07004213 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004214 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004215 */
4216 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004217 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4218 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004219 final int targetSdk = getTargetSdk(callingPackage);
4220 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004221 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004222 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004223 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004224 mApp, subId, callingPackage, callingFeatureId,
4225 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4227 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 final Phone phone = getPhone(subId);
4232 if (phone != null) {
4233 return phone.getServiceState().getDataNetworkType();
4234 } else {
4235 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4236 }
4237 } finally {
4238 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004240 }
4241
4242 /**
4243 * Returns the data network type
4244 */
4245 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004246 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4247 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4248 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004249 }
4250
4251 /**
4252 * Returns the data network type for a subId
4253 */
4254 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004255 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4256 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004258 mApp, subId, callingPackage, callingFeatureId,
4259 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004260 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4261 }
4262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 final Phone phone = getPhone(subId);
4266 if (phone != null) {
4267 return phone.getServiceState().getDataNetworkType();
4268 } else {
4269 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4270 }
4271 } finally {
4272 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004274 }
4275
4276 /**
Wink Saville36469e72014-06-11 15:17:00 -07004277 * Returns the Voice network type for a subId
4278 */
4279 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004280 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4281 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004283 mApp, subId, callingPackage, callingFeatureId,
4284 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004285 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4286 }
4287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 final Phone phone = getPhone(subId);
4291 if (phone != null) {
4292 return phone.getServiceState().getVoiceNetworkType();
4293 } else {
4294 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4295 }
4296 } finally {
4297 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004299 }
4300
4301 /**
4302 * @return true if a ICC card is present
4303 */
4304 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004305 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004306 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4307 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004308 }
4309
4310 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004311 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004312 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004313 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004314 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 final Phone phone = PhoneFactory.getPhone(slotIndex);
4318 if (phone != null) {
4319 return phone.getIccCard().hasIccCard();
4320 } else {
4321 return false;
4322 }
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004326 }
4327
4328 /**
4329 * Return if the current radio is LTE on CDMA. This
4330 * is a tri-state return value as for a period of time
4331 * the mode may be unknown.
4332 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004333 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004334 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004335 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004336 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004337 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004338 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4339 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4340 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004341 }
4342
Sanket Padawe356d7632015-06-22 14:03:32 -07004343 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004344 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4345 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004346 try {
4347 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4348 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004349 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4350 }
4351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 final Phone phone = getPhone(subId);
4355 if (phone == null) {
4356 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4357 } else {
4358 return phone.getLteOnCdmaMode();
4359 }
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004362 }
Wink Saville36469e72014-06-11 15:17:00 -07004363 }
4364
Wink Saville36469e72014-06-11 15:17:00 -07004365 /**
4366 * {@hide}
4367 * Returns Default subId, 0 in the case of single standby.
4368 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004369 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004370 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004371 }
4372
Shishir Agrawala9f32182016-04-12 12:00:16 -07004373 private int getSlotForDefaultSubscription() {
4374 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4375 }
4376
Wink Savilleb564aae2014-10-23 10:18:09 -07004377 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004378 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004379 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004380
Pengquan Menge92a50d2018-09-21 15:54:48 -07004381 private boolean isActiveSubscription(int subId) {
4382 return mSubscriptionController.isActiveSubId(subId);
4383 }
4384
Ihab Awadf2177b72013-11-25 13:33:23 -08004385 /**
4386 * @see android.telephony.TelephonyManager.WifiCallingChoices
4387 */
4388 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389 final long identity = Binder.clearCallingIdentity();
4390 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004391 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4393 getWhenToMakeWifiCallsDefaultPreference());
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004397 }
4398
4399 /**
4400 * @see android.telephony.TelephonyManager.WifiCallingChoices
4401 */
4402 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004406 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004411 }
4412
Sailesh Nepald1e68152013-12-12 19:08:02 -08004413 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004414 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004415 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004416 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004417
Jordan Liu4c733742019-02-28 12:03:40 -08004418 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4419 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4420 if (phoneId == -1) {
4421 throw new IllegalArgumentException("Given slot index: " + slotIndex
4422 + " does not correspond to an active phone");
4423 }
4424 return PhoneFactory.getPhone(phoneId);
4425 }
4426
Shishir Agrawal566b7612013-10-28 14:41:00 -07004427 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004428 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4429 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4431 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004433 if (DBG) {
4434 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4435 }
4436 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4437 p2);
4438 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004439
Jordan Liu4c733742019-02-28 12:03:40 -08004440
4441 @Override
4442 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4443 int slotIndex, String callingPackage, String aid, int p2) {
4444 enforceModifyPermission();
4445 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4446 if (DBG) {
4447 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4448 }
4449 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4450 callingPackage, aid, p2);
4451 }
4452
4453 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4454 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 if (TextUtils.equals(ISDR_AID, aid)) {
4458 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004459 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4460 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461 if (bestComponent == null
4462 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4463 loge("The calling package is not allowed to access ISD-R.");
4464 throw new SecurityException(
4465 "The calling package is not allowed to access ISD-R.");
4466 }
Derek Tan740e1672017-06-27 14:56:27 -07004467 }
Derek Tan740e1672017-06-27 14:56:27 -07004468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004470 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4471 null /* workSource */);
4472 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473 return response;
4474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004477 }
4478
4479 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004480 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4482 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004483 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4484 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4485 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004486
Jordan Liu4c733742019-02-28 12:03:40 -08004487 @Override
4488 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4489 enforceModifyPermission();
4490 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4491 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4492 channel);
4493 }
4494
4495 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 if (channel < 0) {
4499 return false;
4500 }
Jordan Liu4c733742019-02-28 12:03:40 -08004501 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4502 null /* workSource */);
4503 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504 return success;
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004507 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004508 }
4509
4510 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004511 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004512 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4514 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004515 if (DBG) {
4516 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4517 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4518 + p3 + " data=" + data);
4519 }
4520 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4521 command, p1, p2, p3, data);
4522 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004523
Jordan Liu4c733742019-02-28 12:03:40 -08004524 @Override
4525 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4526 int command, int p1, int p2, int p3, String data) {
4527 enforceModifyPermission();
4528 if (DBG) {
4529 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4530 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4531 + p3 + " data=" + data);
4532 }
4533 return iccTransmitApduLogicalChannelWithPermission(
4534 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4535 data);
4536 }
4537
4538 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4539 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 final long identity = Binder.clearCallingIdentity();
4541 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004542 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 return "";
4544 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004547 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4548 null /* workSource */);
4549 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551 // Append the returned status code to the end of the response payload.
4552 String s = Integer.toHexString(
4553 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4554 if (response.payload != null) {
4555 s = IccUtils.bytesToHexString(response.payload) + s;
4556 }
4557 return s;
4558 } finally {
4559 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004560 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004561 }
Jake Hambye994d462014-02-03 13:10:13 -08004562
Evan Charltonc66da362014-05-16 14:06:40 -07004563 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004564 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4565 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4567 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004569 if (DBG) {
4570 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4571 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4572 }
4573 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4574 cla, command, p1, p2, p3, data);
4575 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004576
Jordan Liu4c733742019-02-28 12:03:40 -08004577 @Override
4578 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4579 int command, int p1, int p2, int p3, String data) {
4580 enforceModifyPermission();
4581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4582 if (DBG) {
4583 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4584 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4585 + " data=" + data);
4586 }
4587
4588 return iccTransmitApduBasicChannelWithPermission(
4589 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4590 p2, p3, data);
4591 }
4592
4593 // open APDU basic channel assuming the caller has sufficient permissions
4594 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4595 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 final long identity = Binder.clearCallingIdentity();
4597 try {
4598 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4599 && TextUtils.equals(ISDR_AID, data)) {
4600 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004601 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4602 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603 if (bestComponent == null
4604 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4605 loge("The calling package is not allowed to select ISD-R.");
4606 throw new SecurityException(
4607 "The calling package is not allowed to select ISD-R.");
4608 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004609 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004611 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004612 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4613 null /* workSource */);
4614 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 // Append the returned status code to the end of the response payload.
4617 String s = Integer.toHexString(
4618 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4619 if (response.payload != null) {
4620 s = IccUtils.bytesToHexString(response.payload) + s;
4621 }
4622 return s;
4623 } finally {
4624 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004625 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004626 }
4627
4628 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004629 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004630 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4632 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 final long identity = Binder.clearCallingIdentity();
4635 try {
4636 if (DBG) {
4637 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4638 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4639 }
4640
4641 IccIoResult response =
4642 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4643 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4644 subId);
4645
4646 if (DBG) {
4647 log("Exchange SIM_IO [R]" + response);
4648 }
4649
4650 byte[] result = null;
4651 int length = 2;
4652 if (response.payload != null) {
4653 length = 2 + response.payload.length;
4654 result = new byte[length];
4655 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4656 } else {
4657 result = new byte[length];
4658 }
4659
4660 result[length - 1] = (byte) response.sw2;
4661 result[length - 2] = (byte) response.sw1;
4662 return result;
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004665 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004666 }
4667
Nathan Haroldb3014052017-01-25 15:57:32 -08004668 /**
4669 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4670 * on a particular subscription
4671 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004672 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4673 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004675 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004676 return null;
4677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004678
4679 final long identity = Binder.clearCallingIdentity();
4680 try {
4681 if (appType != TelephonyManager.APPTYPE_USIM
4682 && appType != TelephonyManager.APPTYPE_SIM) {
4683 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4684 return null;
4685 }
4686 Object response = sendRequest(
4687 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4688 if (response instanceof String[]) {
4689 return (String[]) response;
4690 }
yincheng zhaod698b842019-09-06 17:06:54 -07004691 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004693 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004696 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004697 }
4698
yincheng zhaod698b842019-09-06 17:06:54 -07004699 /**
4700 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4701 * subscription.
4702 *
4703 * @param subId the id of the subscription.
4704 * @param appType the uicc app type, must be USIM or SIM.
4705 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4706 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004707 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004708 * @return number of fplmns that is successfully written to the SIM.
4709 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004710 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4711 String callingFeatureId) {
4712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4713 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004714 if (DBG) logv("no permissions for setForbiddenplmns");
4715 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4716 }
4717 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4718 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4719 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4720 }
4721 if (fplmns == null) {
4722 throw new IllegalArgumentException("Fplmn List provided is null");
4723 }
4724 for (String fplmn : fplmns) {
4725 if (!CellIdentity.isValidPlmn(fplmn)) {
4726 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4727 }
4728 }
4729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 Object response = sendRequest(
4732 CMD_SET_FORBIDDEN_PLMNS,
4733 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4734 subId);
4735 return (int) response;
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
4739 }
4740
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004741 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004742 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4744 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 final long identity = Binder.clearCallingIdentity();
4747 try {
4748 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4749 if (response.payload == null) {
4750 return "";
4751 }
Evan Charltonc66da362014-05-16 14:06:40 -07004752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 // Append the returned status code to the end of the response payload.
4754 String s = Integer.toHexString(
4755 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4756 s = IccUtils.bytesToHexString(response.payload) + s;
4757 return s;
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
4760 }
Evan Charltonc66da362014-05-16 14:06:40 -07004761 }
4762
Jake Hambye994d462014-02-03 13:10:13 -08004763 /**
4764 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4765 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4766 *
4767 * @param itemID the ID of the item to read
4768 * @return the NV item as a String, or null on error.
4769 */
4770 @Override
4771 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004772 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4774 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775
4776 final long identity = Binder.clearCallingIdentity();
4777 try {
4778 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004779 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4781 return value;
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
Jake Hambye994d462014-02-03 13:10:13 -08004785 }
4786
4787 /**
4788 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4789 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4790 *
4791 * @param itemID the ID of the item to read
4792 * @param itemValue the value to write, as a String
4793 * @return true on success; false on any failure
4794 */
4795 @Override
4796 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004797 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4799 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800
4801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4804 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004805 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4807 return success;
4808 } finally {
4809 Binder.restoreCallingIdentity(identity);
4810 }
Jake Hambye994d462014-02-03 13:10:13 -08004811 }
4812
4813 /**
4814 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4815 * Used for device configuration by some CDMA operators.
4816 *
4817 * @param preferredRoamingList byte array containing the new PRL
4818 * @return true on success; false on any failure
4819 */
4820 @Override
4821 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4823 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824
4825 final long identity = Binder.clearCallingIdentity();
4826 try {
4827 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4828 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4829 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4830 return success;
4831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
Jake Hambye994d462014-02-03 13:10:13 -08004834 }
4835
4836 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004837 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004838 * Used for device configuration by some CDMA operators.
4839 *
chen xu6dac5ab2018-10-26 17:39:23 -07004840 * @param slotIndex - device slot.
4841 *
Jake Hambye994d462014-02-03 13:10:13 -08004842 * @return true on success; false on any failure
4843 */
4844 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004845 public boolean resetModemConfig(int slotIndex) {
4846 Phone phone = PhoneFactory.getPhone(slotIndex);
4847 if (phone != null) {
4848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4849 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850
chen xu6dac5ab2018-10-26 17:39:23 -07004851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4854 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4855 return success;
4856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 }
chen xu6dac5ab2018-10-26 17:39:23 -07004860 return false;
4861 }
4862
4863 /**
4864 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4865 *
4866 * @param slotIndex - device slot.
4867 *
4868 * @return true on success; false on any failure
4869 */
4870 @Override
4871 public boolean rebootModem(int slotIndex) {
4872 Phone phone = PhoneFactory.getPhone(slotIndex);
4873 if (phone != null) {
4874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4875 mApp, phone.getSubId(), "rebootModem");
4876
4877 final long identity = Binder.clearCallingIdentity();
4878 try {
4879 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4880 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4881 return success;
4882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004887 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004888
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004889 public String[] getPcscfAddress(String apnType, String callingPackage,
4890 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004891 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4893 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004894 return new String[0];
4895 }
4896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 final long identity = Binder.clearCallingIdentity();
4898 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004899 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 } finally {
4901 Binder.restoreCallingIdentity(identity);
4902 }
Wink Saville36469e72014-06-11 15:17:00 -07004903 }
4904
Brad Ebinger51f743a2017-01-23 13:50:20 -08004905 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004906 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4907 * {@link #disableIms(int)}.
4908 * @param slotIndex device slot.
4909 */
4910 public void resetIms(int slotIndex) {
4911 enforceModifyPermission();
4912
4913 final long identity = Binder.clearCallingIdentity();
4914 try {
4915 if (mImsResolver == null) {
4916 // may happen if the does not support IMS.
4917 return;
4918 }
4919 mImsResolver.disableIms(slotIndex);
4920 mImsResolver.enableIms(slotIndex);
4921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
4924 }
4925
4926 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004927 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4928 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004929 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004930 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004931 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932
4933 final long identity = Binder.clearCallingIdentity();
4934 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004935 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004936 // may happen if the device does not support IMS.
4937 return;
4938 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004939 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004943 }
4944
4945 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004946 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4947 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004948 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004949 public void disableIms(int slotId) {
4950 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951
4952 final long identity = Binder.clearCallingIdentity();
4953 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004954 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004955 // may happen if the device does not support IMS.
4956 return;
4957 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004958 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004962 }
4963
4964 /**
4965 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4966 * feature or {@link null} if the service is not available. If the feature is available, the
4967 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4968 */
4969 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004970 IImsServiceFeatureCallback callback) {
4971 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972
4973 final long identity = Binder.clearCallingIdentity();
4974 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004975 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004976 // may happen if the device does not support IMS.
4977 return null;
4978 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004979 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 } finally {
4981 Binder.restoreCallingIdentity(identity);
4982 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004983 }
4984
4985 /**
4986 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4987 * feature during emergency calling or {@link null} if the service is not available. If the
4988 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4989 * listener for feature updates.
4990 */
4991 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4992 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993
4994 final long identity = Binder.clearCallingIdentity();
4995 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004996 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004997 // may happen if the device does not support IMS.
4998 return null;
4999 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005000 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005004 }
5005
Brad Ebinger5f64b052017-12-14 14:26:15 -08005006 /**
5007 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005008 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005009 */
5010 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5011 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012
5013 final long identity = Binder.clearCallingIdentity();
5014 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005015 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005016 // may happen if the device does not support IMS.
5017 return null;
5018 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005019 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005023 }
5024
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005025 /**
5026 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005027 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005028 */
5029 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5030 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031
5032 final long identity = Binder.clearCallingIdentity();
5033 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005034 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005035 // may happen if the device does not support IMS.
5036 return null;
5037 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005038 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 } finally {
5040 Binder.restoreCallingIdentity(identity);
5041 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005042 }
5043
Brad Ebinger884c07b2018-02-15 16:17:40 -08005044 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005045 * Sets the ImsService Package Name that Telephony will bind to.
5046 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005047 * @param slotIndex the slot ID that the ImsService should bind for.
5048 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005049 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005050 * @param featureTypes An integer array of feature types associated with a packageName.
5051 * @param packageName The name of the package that the current configuration will be replaced
5052 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005053 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005054 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005055 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5056 int[] featureTypes, String packageName) {
5057 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5058 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5060 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005061 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005065 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005066 // may happen if the device does not support IMS.
5067 return false;
5068 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005069 Map<Integer, String> featureConfig = new HashMap<>();
5070 for (int featureType : featureTypes) {
5071 featureConfig.put(featureType, packageName);
5072 }
5073 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5074 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075 } finally {
5076 Binder.restoreCallingIdentity(identity);
5077 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005078 }
5079
5080 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005081 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005082 *
5083 * @param slotId The slot that the ImsService is associated with.
5084 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5085 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005086 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005087 * @return the package name of the ImsService configuration.
5088 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005089 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5090 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005091 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005092 TelephonyPermissions
5093 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5094 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5095 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005099 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005100 // may happen if the device does not support IMS.
5101 return "";
5102 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005103 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005104 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5105 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 } finally {
5107 Binder.restoreCallingIdentity(identity);
5108 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005109 }
5110
Brad Ebinger77b832e2019-10-17 17:03:22 -07005111 /**
5112 * Get the MmTelFeature state associated with the requested subscription id.
5113 * @param subId The subscription that the MmTelFeature is associated with.
5114 * @param callback A callback with an integer containing the
5115 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5116 */
5117 @Override
5118 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5119 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5120 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5121 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5122 "IMS not available on device.");
5123 }
5124 final long token = Binder.clearCallingIdentity();
5125 try {
5126 int slotId = getSlotIndex(subId);
5127 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5128 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5129 + subId + "'");
5130 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5131 }
5132 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5133 try {
5134 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5135 } catch (RemoteException e) {
5136 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5137 + "Ignore");
5138 }
5139 });
5140 } finally {
5141 Binder.restoreCallingIdentity(token);
5142 }
5143 }
5144
Wink Saville36469e72014-06-11 15:17:00 -07005145 public void setImsRegistrationState(boolean registered) {
5146 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147
5148 final long identity = Binder.clearCallingIdentity();
5149 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005150 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
Wink Saville36469e72014-06-11 15:17:00 -07005154 }
5155
5156 /**
Stuart Scott54788802015-03-30 13:18:01 -07005157 * Set the network selection mode to automatic.
5158 *
5159 */
5160 @Override
5161 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5163 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164
5165 final long identity = Binder.clearCallingIdentity();
5166 try {
shilufc958392020-01-20 11:36:01 -08005167 if (!isActiveSubscription(subId)) {
5168 return;
5169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5171 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
Stuart Scott54788802015-03-30 13:18:01 -07005175 }
5176
Pengquan Mengea84e042018-09-20 14:57:26 -07005177 /**
5178 * Ask the radio to connect to the input network and change selection mode to manual.
5179 *
5180 * @param subId the id of the subscription.
5181 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5182 * the operator to attach to.
5183 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5184 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5185 * normal network selection next time.
5186 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005187 */
5188 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005189 public boolean setNetworkSelectionModeManual(
5190 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5192 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005193
5194 if (!isActiveSubscription(subId)) {
5195 return false;
5196 }
5197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 final long identity = Binder.clearCallingIdentity();
5199 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005200 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005202 if (DBG) {
5203 log("setNetworkSelectionModeManual: subId: " + subId
5204 + " operator: " + operatorInfo);
5205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005210 }
5211
5212 /**
5213 * Scans for available networks.
5214 */
5215 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005216 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5217 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5219 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005220 LocationAccessPolicy.LocationPermissionResult locationResult =
5221 LocationAccessPolicy.checkLocationPermission(mApp,
5222 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5223 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005224 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005225 .setCallingPid(Binder.getCallingPid())
5226 .setCallingUid(Binder.getCallingUid())
5227 .setMethod("getCellNetworkScanResults")
5228 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5229 .build());
5230 switch (locationResult) {
5231 case DENIED_HARD:
5232 throw new SecurityException("Not allowed to access scan results -- location");
5233 case DENIED_SOFT:
5234 return null;
5235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236
Pengquan Menga1bb6272018-09-06 09:59:22 -07005237 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 try {
5239 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005240 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005245 }
5246
5247 /**
sqian80370722020-01-29 15:02:51 -08005248 * Get the call forwarding info, given the call forwarding reason.
5249 */
5250 @Override
5251 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5252 enforceReadPrivilegedPermission("getCallForwarding");
5253 long identity = Binder.clearCallingIdentity();
5254 try {
5255 if (DBG) {
5256 log("getCallForwarding: subId " + subId
5257 + " callForwardingReason" + callForwardingReason);
5258 }
5259 return (CallForwardingInfo) sendRequest(
5260 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
5264 }
5265
5266 /**
5267 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5268 * reason, the number to forward, and the timeout before the forwarding is attempted.
5269 */
5270 @Override
5271 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5272 enforceModifyPermission();
5273 long identity = Binder.clearCallingIdentity();
5274 try {
5275 if (DBG) {
5276 log("setCallForwarding: subId " + subId
5277 + " callForwardingInfo" + callForwardingInfo);
5278 }
5279 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
5283 }
5284
5285 /**
5286 * Get the call forwarding info, given the call forwarding reason.
5287 */
5288 @Override
5289 public int getCallWaitingStatus(int subId) {
5290 enforceReadPrivilegedPermission("getCallForwarding");
5291 long identity = Binder.clearCallingIdentity();
5292 try {
5293 if (DBG) log("getCallWaitingStatus: subId " + subId);
5294 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5295 } finally {
5296 Binder.restoreCallingIdentity(identity);
5297 }
5298 }
5299
5300 /**
5301 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5302 * reason, the number to forward, and the timeout before the forwarding is attempted.
5303 */
5304 @Override
5305 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5306 enforceModifyPermission();
5307 long identity = Binder.clearCallingIdentity();
5308 try {
5309 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5310 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
5314 }
5315
5316 /**
yinxub1bed742017-04-17 11:45:04 -07005317 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005318 *
yinxub1bed742017-04-17 11:45:04 -07005319 * @param subId id of the subscription
5320 * @param request contains the radio access networks with bands/channels to scan
5321 * @param messenger callback messenger for scan results or errors
5322 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005323 * @return the id of the requested scan which can be used to stop the scan.
5324 */
5325 @Override
5326 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005327 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5329 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005330 LocationAccessPolicy.LocationPermissionResult locationResult =
5331 LocationAccessPolicy.checkLocationPermission(mApp,
5332 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5333 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005334 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005335 .setCallingPid(Binder.getCallingPid())
5336 .setCallingUid(Binder.getCallingUid())
5337 .setMethod("requestNetworkScan")
5338 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5339 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005340 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005341 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005342 if (e != null) {
5343 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5344 throw e;
5345 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005346 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005347 return TelephonyScanManager.INVALID_SCAN_ID;
5348 }
5349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 }
Hall Liu912dfd32019-04-25 14:02:26 -07005351 int callingUid = Binder.getCallingUid();
5352 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 return mNetworkScanRequestTracker.startNetworkScan(
5356 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005357 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
yinxu504e1392017-04-12 16:03:22 -07005361 }
5362
Hall Liub2ac8ef2019-02-28 15:56:23 -08005363 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005364 NetworkScanRequest request, int subId) {
5365 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5366 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5367 boolean hasNetworkScanPermission =
5368 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5369 == PERMISSION_GRANTED;
5370
5371 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5372 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5373 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005374 }
5375
5376 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5377 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005378 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5379 return new SecurityException("Specific channels must not be"
5380 + " scanned without location access.");
5381 }
5382 }
5383 }
5384
Hall Liub2ac8ef2019-02-28 15:56:23 -08005385 return null;
5386 }
5387
yinxu504e1392017-04-12 16:03:22 -07005388 /**
5389 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005390 *
5391 * @param subId id of the subscription
5392 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005393 */
5394 @Override
5395 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5397 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398
Hall Liu912dfd32019-04-25 14:02:26 -07005399 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 final long identity = Binder.clearCallingIdentity();
5401 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005402 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 } finally {
5404 Binder.restoreCallingIdentity(identity);
5405 }
yinxu504e1392017-04-12 16:03:22 -07005406 }
5407
5408 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005409 * Get the calculated preferred network type.
5410 * Used for debugging incorrect network type.
5411 *
5412 * @return the preferred network type, defined in RILConstants.java.
5413 */
5414 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005415 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005416 final Phone defaultPhone = getDefaultPhone();
5417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005418 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005419 return RILConstants.PREFERRED_NETWORK_MODE;
5420 }
5421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005425 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
Junda Liu84d15a22014-07-02 11:21:04 -07005429 }
5430
5431 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005432 * Get the preferred network type.
5433 * Used for device configuration by some CDMA operators.
5434 *
5435 * @return the preferred network type, defined in RILConstants.java.
5436 */
5437 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005438 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005439 TelephonyPermissions
5440 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5441 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442
5443 final long identity = Binder.clearCallingIdentity();
5444 try {
5445 if (DBG) log("getPreferredNetworkType");
5446 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5447 int networkType = (result != null ? result[0] : -1);
5448 if (DBG) log("getPreferredNetworkType: " + networkType);
5449 return networkType;
5450 } finally {
5451 Binder.restoreCallingIdentity(identity);
5452 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005453 }
5454
5455 /**
5456 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005457 *
5458 * @param networkType the preferred network type, defined in RILConstants.java.
5459 * @return true on success; false on any failure.
5460 */
5461 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005462 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5464 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005468 Settings.Global.putInt(mApp.getContentResolver(),
5469 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005470
5471 Boolean success = (Boolean) sendRequest(
5472 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5473 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5474 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 } finally {
5476 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005477 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005478 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005479
5480 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005481 * Get the allowed network types that store in the telephony provider.
5482 *
5483 * @param subId the id of the subscription.
5484 * @return allowedNetworkTypes the allowed network types.
5485 */
5486 @Override
5487 public long getAllowedNetworkTypes(int subId) {
5488 TelephonyPermissions
5489 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5490 mApp, subId, "getAllowedNetworkTypes");
5491
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 return SubscriptionManager.getLongSubscriptionProperty(
5495 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
5499 }
5500
5501 /**
5502 * Set the allowed network types.
5503 *
5504 * @param subId the id of the subscription.
5505 * @param allowedNetworkTypes the allowed network types.
5506 * @return true on success; false on any failure.
5507 */
5508 @Override
5509 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5511 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005512
calvinpan089c2a62020-03-12 14:17:55 +08005513 SubscriptionManager.setSubscriptionProperty(subId,
5514 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5515 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005516
calvinpan089c2a62020-03-12 14:17:55 +08005517 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5518 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5519 RILConstants.PREFERRED_NETWORK_MODE);
5520 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005521 }
5522
5523 /**
Miaoa84611c2019-03-15 09:21:10 +08005524 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005525 *
Miaoa84611c2019-03-15 09:21:10 +08005526 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005527 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005528 * @hide
5529 */
5530 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005531 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005532 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005534 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 try {
Miaoa84611c2019-03-15 09:21:10 +08005536 if (phone != null) {
5537 return phone.hasMatchedTetherApnSetting();
5538 } else {
5539 return false;
5540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541 } finally {
5542 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005543 }
Junda Liu475951f2014-11-07 16:45:03 -08005544 }
5545
5546 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005547 * Set mobile data enabled
5548 * Used by the user through settings etc to turn on/off mobile data
5549 *
5550 * @param enable {@code true} turn turn data on, else {@code false}
5551 */
5552 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005553 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5555 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 int phoneId = mSubscriptionController.getPhoneId(subId);
5560 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5561 Phone phone = PhoneFactory.getPhone(phoneId);
5562 if (phone != null) {
5563 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005564 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005566 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 }
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005570 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005571 }
5572
5573 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005574 * Enable or disable always reporting signal strength changes from radio.
5575 *
5576 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5577 */
5578 @Override
5579 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5580 enforceModifyPermission();
5581 enforceSystemCaller();
5582
5583 final long identity = Binder.clearCallingIdentity();
5584 final Phone phone = getPhone(subId);
5585 try {
5586 if (phone != null) {
5587 if (DBG) {
5588 log("setAlwaysReportSignalStrength: subId=" + subId
5589 + " isEnable=" + isEnable);
5590 }
5591 phone.setAlwaysReportSignalStrength(isEnable);
5592 } else {
5593 loge("setAlwaysReportSignalStrength: no phone found for subId="
5594 + subId);
5595 }
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
5599 }
5600
5601 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005602 * Get the user enabled state of Mobile Data.
5603 *
5604 * TODO: remove and use isUserDataEnabled.
5605 * This can't be removed now because some vendor codes
5606 * calls through ITelephony directly while they should
5607 * use TelephonyManager.
5608 *
5609 * @return true on enabled
5610 */
5611 @Override
5612 public boolean getDataEnabled(int subId) {
5613 return isUserDataEnabled(subId);
5614 }
5615
5616 /**
5617 * Get whether mobile data is enabled per user setting.
5618 *
5619 * There are other factors deciding whether mobile data is actually enabled, but they are
5620 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005621 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005622 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005623 *
5624 * @return {@code true} if data is enabled else {@code false}
5625 */
5626 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005627 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005628 try {
5629 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5630 null);
5631 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5633 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 int phoneId = mSubscriptionController.getPhoneId(subId);
5639 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5640 Phone phone = PhoneFactory.getPhone(phoneId);
5641 if (phone != null) {
5642 boolean retVal = phone.isUserDataEnabled();
5643 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5644 return retVal;
5645 } else {
5646 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5647 return false;
5648 }
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005651 }
5652 }
5653
5654 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005655 * Checks if the device is capable of mobile data by considering whether whether the
5656 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5657 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005658 *
Shuo Qian985d1232020-01-08 14:30:06 -08005659 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005660 */
5661 @Override
5662 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005663 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664
5665 final long identity = Binder.clearCallingIdentity();
5666 try {
5667 int phoneId = mSubscriptionController.getPhoneId(subId);
5668 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5669 Phone phone = PhoneFactory.getPhone(phoneId);
5670 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005671 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5673 return retVal;
5674 } else {
5675 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5676 return false;
5677 }
5678 } finally {
5679 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005680 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005681 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005682
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005683 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005684 Phone phone) {
5685 //load access rules from carrier configs, and check those as well: b/139133814
5686 SubscriptionController subController = SubscriptionController.getInstance();
5687 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5688 || subController == null) return privilegeFromSim;
5689
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005690 PackageManager pkgMgr = phone.getContext().getPackageManager();
5691 String[] packages = pkgMgr.getPackagesForUid(uid);
5692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5696 SubscriptionManager subManager = (SubscriptionManager)
5697 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5698 for (String pkg : packages) {
5699 if (subManager.canManageSubscription(subInfo, pkg)) {
5700 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5701 }
5702 }
5703 return privilegeFromSim;
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
5707 }
5708
5709 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5710 String pkgName) {
5711 //load access rules from carrier configs, and check those as well: b/139133814
5712 SubscriptionController subController = SubscriptionController.getInstance();
5713 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5714 || subController == null) return privilegeFromSim;
5715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5719 SubscriptionManager subManager = (SubscriptionManager)
5720 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5721 return subManager.canManageSubscription(subInfo, pkgName)
5722 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
5726 }
5727
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005728 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005729 public int getCarrierPrivilegeStatus(int subId) {
5730 final Phone phone = getPhone(subId);
5731 if (phone == null) {
5732 loge("getCarrierPrivilegeStatus: Invalid subId");
5733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5734 }
5735 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005736 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005737 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005738 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5739 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005740
5741 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5742 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005743 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005744 }
Junda Liu29340342014-07-10 15:23:27 -07005745
5746 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005747 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005748 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005749 final Phone phone = getPhone(subId);
5750 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005751 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5753 }
5754 UiccProfile profile =
5755 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5756 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005757 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005758 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5759 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005760 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005761 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005762 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005763 }
5764
5765 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005766 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5767 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005769 }
5770
5771 int phoneId = SubscriptionManager.getPhoneId(subId);
5772 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005773 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005774 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5776 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005777 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5778 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5779 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005780 }
5781
5782 @Override
5783 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005784 if (TextUtils.isEmpty(pkgName))
5785 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005786 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5787 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5788 UiccCard card = UiccController.getInstance().getUiccCard(i);
5789 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005790 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005791 continue;
5792 }
5793
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005794 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5795 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5796 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005797 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5798 break;
5799 }
5800 }
5801
5802 return result;
Junda Liu29340342014-07-10 15:23:27 -07005803 }
Derek Tan89e89d42014-07-08 17:00:10 -07005804
5805 @Override
Junda Liue64de782015-04-16 17:19:16 -07005806 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5807 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5808 loge("phoneId " + phoneId + " is not valid.");
5809 return null;
5810 }
5811 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005812 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005813 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005814 return null ;
5815 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005816 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005817 }
5818
Amith Yamasani6e118872016-02-19 12:53:51 -08005819 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005820 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005821 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005822 List<String> privilegedPackages = new ArrayList<>();
5823 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005824 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5825 // has UICC in that slot.
5826 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005827 if (card.hasCarrierPrivilegeRules()) {
5828 if (packages == null) {
5829 // Only check packages in user 0 for now
5830 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005831 PackageManager.MATCH_DISABLED_COMPONENTS
5832 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005833 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005834 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005835 }
5836 for (int p = packages.size() - 1; p >= 0; p--) {
5837 PackageInfo pkgInfo = packages.get(p);
5838 if (pkgInfo != null && pkgInfo.packageName != null
5839 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005840 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005841 privilegedPackages.add(pkgInfo.packageName);
5842 }
5843 }
5844 }
5845 }
5846 return privilegedPackages;
5847 }
5848
chen xuf7e9fe82019-05-09 19:31:02 -07005849 @Override
5850 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005851 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5852
5853 final long identity = Binder.clearCallingIdentity();
5854
chen xuf7e9fe82019-05-09 19:31:02 -07005855 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005856 try {
5857 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5858 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5859 }
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005862 }
5863 return privilegedPackages;
5864 }
5865
Wink Savilleb564aae2014-10-23 10:18:09 -07005866 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005867 final Phone phone = getPhone(subId);
5868 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005869 if (card == null) {
5870 loge("getIccId: No UICC");
5871 return null;
5872 }
5873 String iccId = card.getIccId();
5874 if (TextUtils.isEmpty(iccId)) {
5875 loge("getIccId: ICC ID is null or empty.");
5876 return null;
5877 }
5878 return iccId;
5879 }
5880
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005881 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005882 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5883 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005884 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005885 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 final long identity = Binder.clearCallingIdentity();
5888 try {
5889 final String iccId = getIccId(subId);
5890 final Phone phone = getPhone(subId);
5891 if (phone == null) {
5892 return false;
5893 }
5894 final String subscriberId = phone.getSubscriberId();
5895
5896 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005897 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 + subscriberId + " to " + number);
5899 }
5900
5901 if (TextUtils.isEmpty(iccId)) {
5902 return false;
5903 }
5904
5905 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5906
5907 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5908 if (alphaTag == null) {
5909 editor.remove(alphaTagPrefKey);
5910 } else {
5911 editor.putString(alphaTagPrefKey, alphaTag);
5912 }
5913
5914 // Record both the line number and IMSI for this ICCID, since we need to
5915 // track all merged IMSIs based on line number
5916 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5917 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5918 if (number == null) {
5919 editor.remove(numberPrefKey);
5920 editor.remove(subscriberPrefKey);
5921 } else {
5922 editor.putString(numberPrefKey, number);
5923 editor.putString(subscriberPrefKey, subscriberId);
5924 }
5925
5926 editor.commit();
5927 return true;
5928 } finally {
5929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005930 }
Derek Tan7226c842014-07-02 17:42:23 -07005931 }
5932
5933 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005934 public String getLine1NumberForDisplay(int subId, String callingPackage,
5935 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005936 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005938 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005939 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005940 return null;
5941 }
Derek Tan97ebb422014-09-05 16:55:38 -07005942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 final long identity = Binder.clearCallingIdentity();
5944 try {
5945 String iccId = getIccId(subId);
5946 if (iccId != null) {
5947 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5948 if (DBG_MERGE) {
5949 log("getLine1NumberForDisplay returning "
5950 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5951 }
5952 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5955 return null;
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005958 }
Derek Tan7226c842014-07-02 17:42:23 -07005959 }
5960
5961 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005962 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5963 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005965 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005966 return null;
5967 }
Derek Tan97ebb422014-09-05 16:55:38 -07005968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 final long identity = Binder.clearCallingIdentity();
5970 try {
5971 String iccId = getIccId(subId);
5972 if (iccId != null) {
5973 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5974 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5975 }
5976 return null;
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005979 }
Derek Tan7226c842014-07-02 17:42:23 -07005980 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005981
5982 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005983 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5984 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005985 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5986 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005988 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005989 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005990 return null;
5991 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005992
Jordan Liub49b04b2019-05-06 14:45:15 -07005993 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5994 // the process, where TelephonyManager was instantiated.
5995 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005996 final long identity = Binder.clearCallingIdentity();
5997 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005998 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 final TelephonyManager tele = TelephonyManager.from(context);
6000 final SubscriptionManager sub = SubscriptionManager.from(context);
6001
6002 // Figure out what subscribers are currently active
6003 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004
Jordan Liub49b04b2019-05-06 14:45:15 -07006005 // Only consider subs which match the current subId
6006 // This logic can be simplified. See b/131189269 for progress.
6007 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006008 activeSubscriberIds.add(tele.getSubscriberId(subId));
6009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 // First pass, find a number override for an active subscriber
6012 String mergeNumber = null;
6013 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6014 for (String key : prefs.keySet()) {
6015 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6016 final String subscriberId = (String) prefs.get(key);
6017 if (activeSubscriberIds.contains(subscriberId)) {
6018 final String iccId = key.substring(
6019 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6020 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6021 mergeNumber = (String) prefs.get(numberKey);
6022 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006023 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024 + " for active subscriber " + subscriberId);
6025 }
6026 if (!TextUtils.isEmpty(mergeNumber)) {
6027 break;
6028 }
6029 }
6030 }
6031 }
6032
6033 // Shortcut when no active merged subscribers
6034 if (TextUtils.isEmpty(mergeNumber)) {
6035 return null;
6036 }
6037
6038 // Second pass, find all subscribers under that line override
6039 final ArraySet<String> result = new ArraySet<>();
6040 for (String key : prefs.keySet()) {
6041 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6042 final String number = (String) prefs.get(key);
6043 if (mergeNumber.equals(number)) {
6044 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6045 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6046 final String subscriberId = (String) prefs.get(subscriberKey);
6047 if (!TextUtils.isEmpty(subscriberId)) {
6048 result.add(subscriberId);
6049 }
6050 }
6051 }
6052 }
6053
6054 final String[] resultArray = result.toArray(new String[result.size()]);
6055 Arrays.sort(resultArray);
6056 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006057 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6059 }
6060 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006061 } finally {
6062 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006063 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006064 }
6065
6066 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006067 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6068 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6069
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 final TelephonyManager telephonyManager = mApp.getSystemService(
6073 TelephonyManager.class);
6074 String subscriberId = telephonyManager.getSubscriberId(subId);
6075 if (subscriberId == null) {
6076 if (DBG) {
6077 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6078 + subId);
6079 }
6080 return null;
6081 }
6082
6083 final SubscriptionInfo info = SubscriptionController.getInstance()
6084 .getSubscriptionInfo(subId);
6085 final ParcelUuid groupUuid = info.getGroupUuid();
6086 // If it doesn't belong to any group, return just subscriberId of itself.
6087 if (groupUuid == null) {
6088 return new String[]{subscriberId};
6089 }
6090
6091 // Get all subscriberIds from the group.
6092 final List<String> mergedSubscriberIds = new ArrayList<>();
6093 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006094 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6095 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006096 for (SubscriptionInfo subInfo : groupInfos) {
6097 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6098 if (subscriberId != null) {
6099 mergedSubscriberIds.add(subscriberId);
6100 }
6101 }
6102
6103 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106
6107 }
6108 }
6109
6110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006111 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006112 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006113 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114
6115 final long identity = Binder.clearCallingIdentity();
6116 try {
6117 final Phone phone = getPhone(subId);
6118 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006122 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006123
6124 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006125 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006126 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6127 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006128 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6129 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130
6131 final long identity = Binder.clearCallingIdentity();
6132 try {
6133 final Phone phone = getPhone(subId);
6134 if (phone == null) {
6135 return false;
6136 }
6137 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6138 cdmaNonRoamingList);
6139 } finally {
6140 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006141 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006142 }
6143
6144 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006145 @Deprecated
6146 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6147 enforceModifyPermission();
6148
6149 int returnValue = 0;
6150 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006151 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006152 if(result.exception == null) {
6153 if (result.result != null) {
6154 byte[] responseData = (byte[])(result.result);
6155 if(responseData.length > oemResp.length) {
6156 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6157 responseData.length + "bytes. Buffer Size is " +
6158 oemResp.length + "bytes.");
6159 }
6160 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6161 returnValue = responseData.length;
6162 }
6163 } else {
6164 CommandException ex = (CommandException) result.exception;
6165 returnValue = ex.getCommandError().ordinal();
6166 if(returnValue > 0) returnValue *= -1;
6167 }
6168 } catch (RuntimeException e) {
6169 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6170 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6171 if(returnValue > 0) returnValue *= -1;
6172 }
6173
6174 return returnValue;
6175 }
6176
6177 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006178 public void setRadioCapability(RadioAccessFamily[] rafs) {
6179 try {
6180 ProxyController.getInstance().setRadioCapability(rafs);
6181 } catch (RuntimeException e) {
6182 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6183 }
6184 }
6185
6186 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006187 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006188 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006189 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006190 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006191 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 final long identity = Binder.clearCallingIdentity();
6194 try {
chen xub97461a2018-10-26 14:17:57 -07006195 TelephonyPermissions
6196 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6197 mApp, phone.getSubId(), "getRadioAccessFamily");
6198 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199 } finally {
6200 Binder.restoreCallingIdentity(identity);
6201 }
chen xub97461a2018-10-26 14:17:57 -07006202 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006203 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006204
6205 @Override
6206 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006207 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006208 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209
6210 final long identity = Binder.clearCallingIdentity();
6211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006212 ImsManager.getInstance(defaultPhone.getContext(),
6213 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 } finally {
6215 Binder.restoreCallingIdentity(identity);
6216 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006217 }
6218
6219 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006220 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006221 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6223 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006224 return false;
6225 }
Svet Ganovb320e182015-04-16 12:30:10 -07006226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 // Check the user preference and the system-level IMS setting. Even if the user has
6230 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6231 // In the long run, we may instead need to check if there exists a connection service
6232 // which can support video calling.
6233 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006234 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 return imsManager.isVtEnabledByPlatform()
6236 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6237 && imsManager.isVtEnabledByUser();
6238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006241 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006242
Andrew Leea1239f22015-03-02 17:44:07 -08006243 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006244 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6245 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006247 mApp, subId, callingPackage, callingFeatureId,
6248 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 return false;
6250 }
6251
6252 final long identity = Binder.clearCallingIdentity();
6253 try {
6254 CarrierConfigManager configManager =
6255 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006256 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6258 } finally {
6259 Binder.restoreCallingIdentity(identity);
6260 }
Andrew Leea1239f22015-03-02 17:44:07 -08006261 }
6262
6263 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006264 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006266 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 return false;
6268 }
6269
6270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 CarrierConfigManager configManager =
6273 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006274 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6276 } finally {
6277 Binder.restoreCallingIdentity(identity);
6278 }
Andrew Leea1239f22015-03-02 17:44:07 -08006279 }
6280
Andrew Lee9431b832015-03-09 18:46:45 -07006281 @Override
6282 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006283 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006284 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006285 }
6286
6287 @Override
6288 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 final long identity = Binder.clearCallingIdentity();
6290 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006291 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 } finally {
6293 Binder.restoreCallingIdentity(identity);
6294 }
Andrew Lee9431b832015-03-09 18:46:45 -07006295 }
6296
Hall Liuf6668912018-10-31 17:05:23 -07006297 /**
6298 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6299 * support for the feature and device firmware support.
6300 *
6301 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6302 */
6303 @Override
6304 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006306 final Phone phone = getPhone(subscriptionId);
6307 if (phone == null) {
6308 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6309 return false;
6310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006312 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6314 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006315 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 return isCarrierSupported && isDeviceSupported;
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
Hall Liu98187582018-01-22 19:15:32 -08006320 }
6321
Hall Liuf6668912018-10-31 17:05:23 -07006322 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006323 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6324 * RTT setting, will return true if the device and carrier both support RTT.
6325 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006326 */
6327 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 final long identity = Binder.clearCallingIdentity();
6329 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006330 boolean isRttSupported = isRttSupported(subscriptionId);
6331 boolean isUserRttSettingOn = Settings.Secure.getInt(
6332 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6333 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6334 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6335 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 } finally {
6337 Binder.restoreCallingIdentity(identity);
6338 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006339 }
6340
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006341 @Deprecated
6342 @Override
6343 public String getDeviceId(String callingPackage) {
6344 return getDeviceIdWithFeature(callingPackage, null);
6345 }
6346
Sanket Padawe7310cc72015-01-14 09:53:20 -08006347 /**
6348 * Returns the unique device ID of phone, for example, the IMEI for
6349 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6350 *
6351 * <p>Requires Permission:
6352 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6353 */
6354 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006355 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006356 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006357 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006358 return null;
6359 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006360 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006361 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006362 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006363 return null;
6364 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365
6366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 return phone.getDeviceId();
6369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006372 }
6373
Ping Sunc67b7c22016-03-02 19:16:45 +08006374 /**
6375 * {@hide}
6376 * Returns the IMS Registration Status on a particular subid
6377 *
6378 * @param subId
6379 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006380 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006381 Phone phone = getPhone(subId);
6382 if (phone != null) {
6383 return phone.isImsRegistered();
6384 } else {
6385 return false;
6386 }
6387 }
6388
Santos Cordon7a1885b2015-02-03 11:15:19 -08006389 @Override
6390 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006397 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006398
Tyler Gunnf70ed162019-04-03 15:28:53 -07006399 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006400 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006401 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006403 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006404 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6405 }
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
6412 }
6413
6414 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006415 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 Phone phone = getPhone(subscriptionId);
6419 if (phone == null) {
6420 return null;
6421 }
6422 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
6426 }
6427
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006428 /**
6429 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006430 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006431 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 Phone phone = getPhone(subId);
6435 if (phone != null) {
6436 return phone.isWifiCallingEnabled();
6437 } else {
6438 return false;
6439 }
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006442 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006443 }
6444
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006445 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006446 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006447 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006448 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 final long identity = Binder.clearCallingIdentity();
6450 try {
6451 Phone phone = getPhone(subId);
6452 if (phone != null) {
6453 return phone.isVideoEnabled();
6454 } else {
6455 return false;
6456 }
6457 } finally {
6458 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006459 }
6460 }
6461
6462 /**
6463 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6464 * defined in {@link ImsRegistrationImplBase}.
6465 */
6466 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 final long identity = Binder.clearCallingIdentity();
6468 try {
6469 Phone phone = getPhone(subId);
6470 if (phone != null) {
6471 return phone.getImsRegistrationTech();
6472 } else {
6473 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6474 }
6475 } finally {
6476 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006477 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006478 }
6479
Stuart Scott8eef64f2015-04-08 15:13:54 -07006480 @Override
6481 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006482 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006483 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6484 return;
6485 }
6486
Svet Ganovcc087f82015-05-12 20:35:54 -07006487 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006488
Svet Ganovcc087f82015-05-12 20:35:54 -07006489 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006490 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6491 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006492 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006493 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006494 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006495 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6496 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006497 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006498 // There has been issues when Sms raw table somehow stores orphan
6499 // fragments. They lead to garbled message when new fragments come
6500 // in and combined with those stale ones. In case this happens again,
6501 // user can reset all network settings which will clean up this table.
6502 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006503 // Clean up IMS settings as well here.
6504 int slotId = getSlotIndex(subId);
6505 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6506 ImsManager.getInstance(mApp, slotId).factoryReset();
6507 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006508
6509 // Erase modem config if erase modem on network setting is enabled.
6510 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6511 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6512 if (configValue != null && Boolean.parseBoolean(configValue)) {
6513 sendEraseModemConfig(getDefaultPhone());
6514 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006515 } finally {
6516 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006517 }
6518 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006519
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006520 private void cleanUpSmsRawTable(Context context) {
6521 ContentResolver resolver = context.getContentResolver();
6522 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6523 resolver.delete(uri, null, null);
6524 }
6525
Narayan Kamath1c496c22015-04-16 14:40:19 +01006526 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006527 public String getSimLocaleForSubscriber(int subId) {
6528 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6529 final Phone phone = getPhone(subId);
6530 if (phone == null) {
6531 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006532 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534 final long identity = Binder.clearCallingIdentity();
6535 try {
chen xu5d3637b2019-01-21 23:31:38 -08006536 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006537 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006538 if (info == null) {
6539 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6540 return null;
6541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 // Try and fetch the locale from the carrier properties or from the SIM language
6543 // preferences (EF-PL and EF-LI)...
6544 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006546 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6547 if (localeFromDefaultSim != null) {
6548 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6549 if (DBG) log("Using locale from subId: " + subId + " locale: "
6550 + localeFromDefaultSim);
6551 return localeFromDefaultSim.toLanguageTag();
6552 } else {
6553 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 }
6555 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 // The SIM language preferences only store a language (e.g. fr = French), not an
6558 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6559 // the SIM and carrier preferences does not include a country we add the country
6560 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006561 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006563 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 return mccLocale.toLanguageTag();
6565 }
6566
6567 if (DBG) log("No locale found - returning null");
6568 return null;
6569 } finally {
6570 Binder.restoreCallingIdentity(identity);
6571 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006572 }
6573
6574 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006575 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6576 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006577 }
6578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 /**
6580 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6581 */
6582 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006583 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6584 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006585 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006586
Chenjie Yu1ba97252018-01-11 18:16:20 -08006587 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006588 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006589
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006590 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006591 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6592 * representing the state of the modem.
6593 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006594 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6595 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006596 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006597 */
6598 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006599 public void requestModemActivityInfo(ResultReceiver result) {
6600 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602
6603 final long identity = Binder.clearCallingIdentity();
6604 try {
sqian1a1be542020-03-05 11:37:28 -08006605 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 } finally {
6607 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006608 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006609 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006610
Siddharth Rayb8114062018-06-17 15:02:38 -07006611 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6612 // less than total activity duration.
6613 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6614 if (info == null) {
6615 return false;
6616 }
6617 int activityDurationMs =
6618 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6619 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006620 int[] txTimeMs = info.getTransmitTimeMillis();
6621 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6622 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006623 }
6624 return (info.isValid()
6625 && (info.getSleepTimeMillis() <= activityDurationMs)
6626 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006627 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006628 && (totalTxTimeMs <= activityDurationMs));
6629 }
6630
Jack Yu85bd38a2015-11-09 11:34:32 -08006631 /**
6632 * {@hide}
6633 * Returns the service state information on specified subscription.
6634 */
6635 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006636 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6637 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006639 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006640 return null;
6641 }
6642
Hall Liuf19c44f2018-11-27 14:38:17 -08006643 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6644 LocationAccessPolicy.checkLocationPermission(mApp,
6645 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6646 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006647 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006648 .setCallingPid(Binder.getCallingPid())
6649 .setCallingUid(Binder.getCallingUid())
6650 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006651 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006652 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6653 .build());
6654
6655 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6656 LocationAccessPolicy.checkLocationPermission(mApp,
6657 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6658 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006659 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006660 .setCallingPid(Binder.getCallingPid())
6661 .setCallingUid(Binder.getCallingUid())
6662 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006663 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006664 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6665 .build());
6666 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6667 boolean hasFinePermission =
6668 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6669 boolean hasCoarsePermission =
6670 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 final Phone phone = getPhone(subId);
6675 if (phone == null) {
6676 return null;
6677 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006678
Hall Liuf19c44f2018-11-27 14:38:17 -08006679 ServiceState ss = phone.getServiceState();
6680
6681 // Scrub out the location info in ServiceState depending on what level of access
6682 // the caller has.
6683 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006684 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6685 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006689 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006690
6691 /**
6692 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6693 *
6694 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6695 * voicemail ringtone.
6696 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6697 * PhoneAccount.
6698 */
6699 @Override
6700 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6704 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006705 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6709 } finally {
6710 Binder.restoreCallingIdentity(identity);
6711 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006712 }
6713
6714 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006715 * Sets the per-account voicemail ringtone.
6716 *
6717 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6718 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6719 *
6720 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6721 * voicemail ringtone.
6722 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6723 * PhoneAccount.
6724 */
6725 @Override
6726 public void setVoicemailRingtoneUri(String callingPackage,
6727 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006728 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006729 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006730 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6731 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6733 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6734 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736
6737 final long identity = Binder.clearCallingIdentity();
6738 try {
6739 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6740 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006741 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742 }
6743 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6744 } finally {
6745 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006746 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006747 }
6748
6749 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006750 * Returns whether vibration is set for voicemail notification in Phone settings.
6751 *
6752 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6753 * voicemail vibration setting.
6754 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6755 */
6756 @Override
6757 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 final long identity = Binder.clearCallingIdentity();
6759 try {
6760 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6761 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006762 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6766 } finally {
6767 Binder.restoreCallingIdentity(identity);
6768 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006769 }
6770
Youhan Wange64578a2016-05-02 15:32:42 -07006771 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006772 * Sets the per-account voicemail vibration.
6773 *
6774 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6775 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6776 *
6777 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6778 * voicemail vibration setting.
6779 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6780 * specific PhoneAccount.
6781 */
6782 @Override
6783 public void setVoicemailVibrationEnabled(String callingPackage,
6784 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006785 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006787 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6788 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6790 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6791 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006792 }
6793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794 final long identity = Binder.clearCallingIdentity();
6795 try {
6796 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6797 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006798 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 }
6800 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6801 } finally {
6802 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006803 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006804 }
6805
6806 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006807 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6808 *
6809 * @throws SecurityException if the caller does not have the required permission
6810 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006811 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006812 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006813 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006814 }
6815
6816 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006817 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6818 * permission.
6819 *
6820 * @throws SecurityException if the caller does not have the required permission
6821 */
6822 private void enforceSendSmsPermission() {
6823 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6824 }
6825
6826 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006827 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006828 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006829 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006830 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006831 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006835 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 if (componentName == null) {
6837 throw new SecurityException(
6838 "Caller not current active visual voicemail package[null]");
6839 }
6840 String vvmPackage = componentName.getPackageName();
6841 if (!callingPackage.equals(vvmPackage)) {
6842 throw new SecurityException("Caller not current active visual voicemail package["
6843 + vvmPackage + "]");
6844 }
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006847 }
6848 }
6849
6850 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006851 * Return the application ID for the app type.
6852 *
6853 * @param subId the subscription ID that this request applies to.
6854 * @param appType the uicc app type.
6855 * @return Application ID for specificied app type, or null if no uicc.
6856 */
6857 @Override
6858 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006859 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006860 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861
6862 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006863 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 if (phone == null) {
6865 return null;
6866 }
6867 String aid = null;
6868 try {
6869 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6870 .getApplicationByType(appType).getAid();
6871 } catch (Exception e) {
6872 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6873 }
6874 return aid;
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006877 }
Youhan Wange64578a2016-05-02 15:32:42 -07006878 }
6879
Youhan Wang4001d252016-05-11 10:29:41 -07006880 /**
6881 * Return the Electronic Serial Number.
6882 *
6883 * @param subId the subscription ID that this request applies to.
6884 * @return ESN or null if error.
6885 */
6886 @Override
6887 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006888 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006889 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890
6891 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006892 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893 if (phone == null) {
6894 return null;
6895 }
6896 String esn = null;
6897 try {
6898 esn = phone.getEsn();
6899 } catch (Exception e) {
6900 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6901 }
6902 return esn;
6903 } finally {
6904 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006905 }
Youhan Wang4001d252016-05-11 10:29:41 -07006906 }
6907
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006908 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006909 * Return the Preferred Roaming List Version.
6910 *
6911 * @param subId the subscription ID that this request applies to.
6912 * @return PRLVersion or null if error.
6913 */
6914 @Override
6915 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006916 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006917 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918
6919 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006920 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 if (phone == null) {
6922 return null;
6923 }
6924 String cdmaPrlVersion = null;
6925 try {
6926 cdmaPrlVersion = phone.getCdmaPrlVersion();
6927 } catch (Exception e) {
6928 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6929 }
6930 return cdmaPrlVersion;
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006933 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006934 }
6935
6936 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006937 * Get snapshot of Telephony histograms
6938 * @return List of Telephony histograms
6939 * @hide
6940 */
6941 @Override
6942 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6944 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945
6946 final long identity = Binder.clearCallingIdentity();
6947 try {
6948 return RIL.getTelephonyRILTimingHistograms();
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
6951 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006952 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006953
6954 /**
6955 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006956 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6957 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006958 * Require system privileges. In the future we may add this to carrier APIs.
6959 *
Michele Berionne482f8202018-11-27 18:57:59 -08006960 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006961 */
6962 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006963 @TelephonyManager.SetCarrierRestrictionResult
6964 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006965 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006966 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006967
Michele Berionne482f8202018-11-27 18:57:59 -08006968 if (carrierRestrictionRules == null) {
6969 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006970 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 final long identity = Binder.clearCallingIdentity();
6973 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006974 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006975 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006976 } finally {
6977 Binder.restoreCallingIdentity(identity);
6978 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006979 }
6980
6981 /**
6982 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006983 * Get the allowed carrier list and the excluded carrier list, including the priority between
6984 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006985 * Require system privileges. In the future we may add this to carrier APIs.
6986 *
Michele Berionne482f8202018-11-27 18:57:59 -08006987 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006988 */
6989 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006990 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006991 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006992 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006996 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6997 if (response instanceof CarrierRestrictionRules) {
6998 return (CarrierRestrictionRules) response;
6999 }
7000 // Response is an Exception of some kind,
7001 // which is signalled to the user as a NULL retval
7002 return null;
7003 } catch (Exception e) {
7004 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7005 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007009 }
7010
fionaxu59545b42016-05-25 15:53:37 -07007011 /**
7012 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7013 * @param subId the subscription ID that this action applies to.
7014 * @param enabled control enable or disable metered apns.
7015 * {@hide}
7016 */
7017 @Override
7018 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7019 enforceModifyPermission();
7020 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021
7022 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007023 if (phone == null) {
7024 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7025 return;
7026 }
7027 try {
7028 phone.carrierActionSetMeteredApnsEnabled(enabled);
7029 } catch (Exception e) {
7030 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 } finally {
7032 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007033 }
7034 }
7035
7036 /**
7037 * Action set from carrier signalling broadcast receivers to enable/disable radio
7038 * @param subId the subscription ID that this action applies to.
7039 * @param enabled control enable or disable radio.
7040 * {@hide}
7041 */
7042 @Override
7043 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7044 enforceModifyPermission();
7045 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046
7047 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007048 if (phone == null) {
7049 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7050 return;
7051 }
7052 try {
7053 phone.carrierActionSetRadioEnabled(enabled);
7054 } catch (Exception e) {
7055 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 } finally {
7057 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007058 }
7059 }
7060
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007061 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007062 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7063 * network status based on which carrier apps could apply actions accordingly,
7064 * enable/disable default url handler for example.
7065 *
7066 * @param subId the subscription ID that this action applies to.
7067 * @param report control start/stop reporting the default network status.
7068 * {@hide}
7069 */
7070 @Override
7071 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7072 enforceModifyPermission();
7073 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074
7075 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007076 if (phone == null) {
7077 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7078 return;
7079 }
7080 try {
7081 phone.carrierActionReportDefaultNetworkStatus(report);
7082 } catch (Exception e) {
7083 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 } finally {
7085 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007086 }
7087 }
7088
7089 /**
fionaxud9622282017-07-17 17:51:30 -07007090 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7091 * @param subId the subscription ID that this action applies to.
7092 * {@hide}
7093 */
7094 @Override
7095 public void carrierActionResetAll(int subId) {
7096 enforceModifyPermission();
7097 final Phone phone = getPhone(subId);
7098 if (phone == null) {
7099 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7100 return;
7101 }
7102 try {
7103 phone.carrierActionResetAll();
7104 } catch (Exception e) {
7105 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7106 }
7107 }
7108
7109 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007110 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7111 * bug report is being generated.
7112 */
7113 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007114 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007115 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7116 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007117 writer.println("Permission Denial: can't dump Phone from pid="
7118 + Binder.getCallingPid()
7119 + ", uid=" + Binder.getCallingUid()
7120 + "without permission "
7121 + android.Manifest.permission.DUMP);
7122 return;
7123 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007124 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007125 }
Jack Yueb89b242016-06-22 13:27:47 -07007126
Brad Ebingerdac2f002018-04-03 15:17:52 -07007127 @Override
7128 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7129 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7130 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007131 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7132 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007133 }
7134
Jack Yueb89b242016-06-22 13:27:47 -07007135 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007136 * Policy control of data connection. Usually used when data limit is passed.
7137 * @param enabled True if enabling the data, otherwise disabling.
7138 * @param subId Subscription index
7139 * {@hide}
7140 */
7141 @Override
7142 public void setPolicyDataEnabled(boolean enabled, int subId) {
7143 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144
7145 final long identity = Binder.clearCallingIdentity();
7146 try {
7147 Phone phone = getPhone(subId);
7148 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007149 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 }
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007153 }
7154 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007155
7156 /**
7157 * Get Client request stats
7158 * @return List of Client Request Stats
7159 * @hide
7160 */
7161 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007162 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7163 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007165 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007166 return null;
7167 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007168 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 if (phone != null) {
7173 return phone.getClientRequestStats();
7174 }
7175
7176 return null;
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007180 }
7181
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007182 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007183 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007184 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007185 }
Jack Yueb4124c2017-02-16 15:32:43 -08007186
7187 /**
Grace Chen70990072017-03-24 17:21:30 -07007188 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007189 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007190 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007191 * @param state State of SIM (power down, power up, pass through)
7192 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7193 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7194 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007195 *
7196 **/
7197 @Override
Grace Chen70990072017-03-24 17:21:30 -07007198 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007199 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007200 Phone phone = PhoneFactory.getPhone(slotIndex);
7201
vagdeviaf9a5b92018-08-15 16:01:53 -07007202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 final long identity = Binder.clearCallingIdentity();
7205 try {
7206 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007207 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 }
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007211 }
7212 }
Shuo Qiandd210312017-04-12 22:11:33 +00007213
Tyler Gunn65d45c22017-06-05 11:22:26 -07007214 private boolean isUssdApiAllowed(int subId) {
7215 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007216 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007217 if (configManager == null) {
7218 return false;
7219 }
7220 PersistableBundle pb = configManager.getConfigForSubId(subId);
7221 if (pb == null) {
7222 return false;
7223 }
7224 return pb.getBoolean(
7225 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7226 }
7227
Shuo Qiandd210312017-04-12 22:11:33 +00007228 /**
7229 * Check if phone is in emergency callback mode
7230 * @return true if phone is in emergency callback mode
7231 * @param subId sub id
7232 */
goneil9c5f4872017-12-05 14:07:56 -08007233 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007234 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007235 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007236 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 if (phone != null) {
7241 return phone.isInEcm();
7242 } else {
7243 return false;
7244 }
7245 } finally {
7246 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007247 }
7248 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007249
7250 /**
7251 * Get the current signal strength information for the given subscription.
7252 * Because this information is not updated when the device is in a low power state
7253 * it should not be relied-upon to be current.
7254 * @param subId Subscription index
7255 * @return the most recent cached signal strength info from the modem
7256 */
7257 @Override
7258 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 final long identity = Binder.clearCallingIdentity();
7260 try {
7261 Phone p = getPhone(subId);
7262 if (p == null) {
7263 return null;
7264 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 return p.getSignalStrength();
7267 } finally {
7268 Binder.restoreCallingIdentity(identity);
7269 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007270 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007271
Pengquan Meng77b7f132018-08-22 14:49:57 -07007272 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007273 * Get the current modem radio state for the given slot.
7274 * @param slotIndex slot index.
7275 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007276 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007277 * @return the current radio power state from the modem
7278 */
7279 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007280 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007281 Phone phone = PhoneFactory.getPhone(slotIndex);
7282 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7284 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007285 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7286 }
7287
7288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 return phone.getRadioPowerState();
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
7294 }
7295 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7296 }
7297
7298 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007299 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7300 *
7301 * <p>Requires one of the following permissions:
7302 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7303 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7304 * privileges.
7305 *
7306 * @param subId subscription id
7307 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7308 * {@code false}.
7309 */
7310 @Override
7311 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007312 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7313 null /* message */);
7314
Pengquan Menga1bb6272018-09-06 09:59:22 -07007315 boolean isEnabled = false;
7316 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007317 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007318 Phone phone = getPhone(subId);
7319 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007320 } catch (Exception e) {
7321 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7322 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007323 } finally {
7324 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007325 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007326 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007327 }
7328
7329
7330 /**
7331 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7332 *
7333 * <p> Requires permission:
7334 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7335 * privileges.
7336 *
7337 * @param subId subscription id
7338 * @param isEnabled {@code true} means enable, {@code false} means disable.
7339 */
7340 @Override
7341 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7343 mApp, subId, "setDataRoamingEnabled");
7344
Pengquan Menga1bb6272018-09-06 09:59:22 -07007345 final long identity = Binder.clearCallingIdentity();
7346 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007347 Phone phone = getPhone(subId);
7348 if (phone != null) {
7349 phone.setDataRoamingEnabled(isEnabled);
7350 }
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007353 }
7354 }
7355
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007356 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007357 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007358 TelephonyPermissions
7359 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007360 mApp, subId, "isManualNetworkSelectionAllowed");
7361
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007362 boolean isAllowed = true;
7363 final long identity = Binder.clearCallingIdentity();
7364 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007365 Phone phone = getPhone(subId);
7366 if (phone != null) {
7367 isAllowed = phone.isCspPlmnEnabled();
7368 }
7369 } finally {
7370 Binder.restoreCallingIdentity(identity);
7371 }
7372 return isAllowed;
7373 }
7374
7375 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007376 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liua39e6c12020-03-04 13:59:23 -08007377 try {
7378 PackageManager pm = mApp.getPackageManager();
7379 if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) {
7380 throw new SecurityException("Calling package " + callingPackage + " does not match "
7381 + "calling UID");
7382 }
7383 } catch (PackageManager.NameNotFoundException e) {
7384 throw new SecurityException("Invalid calling package. e=" + e);
7385 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007386 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007387 try {
7388 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007389 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007390 } catch (SecurityException e) {
7391 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7392 // has carrier privileges on an active UICC
7393 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7394 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007395 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007396 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007397 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007398
7399 final long identity = Binder.clearCallingIdentity();
7400 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007401 UiccController uiccController = UiccController.getInstance();
7402 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007403 if (hasReadPermission) {
7404 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007405 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007406
7407 // Remove private info if the caller doesn't have access
7408 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7409 for (UiccCardInfo cardInfo : cardInfos) {
7410 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7411 // is available
7412 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7413 if (card == null || card.getUiccProfile() == null) {
7414 // assume no access if the card or profile is unavailable
7415 filteredInfos.add(cardInfo.getUnprivileged());
7416 continue;
7417 }
7418 UiccProfile profile = card.getUiccProfile();
7419 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7420 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7421 filteredInfos.add(cardInfo);
7422 } else {
7423 filteredInfos.add(cardInfo.getUnprivileged());
7424 }
7425 }
7426 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007427 } finally {
7428 Binder.restoreCallingIdentity(identity);
7429 }
7430 }
7431
7432 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007433 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007434 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 final long identity = Binder.clearCallingIdentity();
7437 try {
7438 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7439 if (slots == null) {
7440 Rlog.i(LOG_TAG, "slots is null.");
7441 return null;
7442 }
7443
7444 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7445 for (int i = 0; i < slots.length; i++) {
7446 UiccSlot slot = slots[i];
7447 if (slot == null) {
7448 continue;
7449 }
7450
Jordan Liu7be7e652019-05-06 18:55:02 +00007451 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 UiccCard card = slot.getUiccCard();
7453 if (card != null) {
7454 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007455 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007456 cardId = slot.getEid();
7457 if (TextUtils.isEmpty(cardId)) {
7458 cardId = slot.getIccId();
7459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 }
7461
Jordan Liu857451f2019-05-09 16:35:35 -07007462 if (cardId != null) {
7463 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7464 // if cardId is an EID, it's all digits so this is fine
7465 cardId = IccUtils.stripTrailingFs(cardId);
7466 }
7467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 int cardState = 0;
7469 switch (slot.getCardState()) {
7470 case CARDSTATE_ABSENT:
7471 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7472 break;
7473 case CARDSTATE_PRESENT:
7474 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7475 break;
7476 case CARDSTATE_ERROR:
7477 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7478 break;
7479 case CARDSTATE_RESTRICTED:
7480 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7481 break;
7482 default:
7483 break;
7484
7485 }
7486
7487 infos[i] = new UiccSlotInfo(
7488 slot.isActive(),
7489 slot.isEuicc(),
7490 cardId,
7491 cardState,
7492 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007493 slot.isExtendedApduSupported(),
7494 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 }
7496 return infos;
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007499 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007500 }
7501
7502 @Override
7503 public boolean switchSlots(int[] physicalSlots) {
7504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007512 }
Jack Yu4c988042018-02-27 15:30:01 -08007513
7514 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007515 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007516 final long identity = Binder.clearCallingIdentity();
7517 try {
7518 return UiccController.getInstance().getCardIdForDefaultEuicc();
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
7522 }
7523
Pengquan Meng85728fb2018-03-12 16:31:21 -07007524 /**
goneil47ffb6e2018-04-06 15:40:58 -07007525 * A test API to reload the UICC profile.
7526 *
7527 * <p>Requires that the calling app has permission
7528 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7529 * @hide
7530 */
7531 @Override
7532 public void refreshUiccProfile(int subId) {
7533 enforceModifyPermission();
7534
7535 final long identity = Binder.clearCallingIdentity();
7536 try {
7537 Phone phone = getPhone(subId);
7538 if (phone == null) {
7539 return;
7540 }
7541 UiccCard uiccCard = phone.getUiccCard();
7542 if (uiccCard == null) {
7543 return;
7544 }
7545 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7546 if (uiccProfile == null) {
7547 return;
7548 }
7549 uiccProfile.refresh();
7550 } finally {
7551 Binder.restoreCallingIdentity(identity);
7552 }
7553 }
7554
7555 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007556 * Returns false if the mobile data is disabled by default, otherwise return true.
7557 */
7558 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007559 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007560 }
7561
7562 /**
7563 * Returns true if the data roaming is enabled by default, i.e the system property
7564 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7565 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7566 */
7567 private boolean getDefaultDataRoamingEnabled(int subId) {
7568 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007569 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007570 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007571 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7572 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7573 return isDataRoamingEnabled;
7574 }
7575
7576 /**
7577 * Returns the default network type for the given {@code subId}, if the default network type is
7578 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7579 */
7580 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007581 List<Integer> list = TelephonyProperties.default_network();
7582 int phoneId = mSubscriptionController.getPhoneId(subId);
7583 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7584 return list.get(phoneId);
7585 }
7586 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007587 }
fionaxua13278b2018-03-21 00:08:13 -07007588
7589 @Override
7590 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007591 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007592 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 final Phone phone = getPhone(subId);
7597 if (phone == null) {
7598 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7599 return;
7600 }
chen xueaba88a2019-03-15 13:15:10 -07007601 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7602 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 } finally {
7604 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007605 }
fionaxua13278b2018-03-21 00:08:13 -07007606 }
7607
7608 @Override
7609 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007610 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611
7612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 final Phone phone = getPhone(subId);
7615 if (phone == null) {
7616 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7617 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7618 }
7619 return phone.getCarrierIdListVersion();
7620 } finally {
7621 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007622 }
fionaxua13278b2018-03-21 00:08:13 -07007623 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007624
7625 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007626 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7627 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007629 mApp, subId, callingPackage, callingFeatureId,
7630 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007631 return -1;
7632 }
7633
7634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
7640 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007641
7642 @Override
7643 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007644 TelephonyPermissions
7645 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007646 mApp, subId, "getCdmaRoamingMode");
7647
7648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
7654 }
7655
7656 @Override
7657 public boolean setCdmaRoamingMode(int subId, int mode) {
7658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7659 mApp, subId, "setCdmaRoamingMode");
7660
7661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7664 } finally {
7665 Binder.restoreCallingIdentity(identity);
7666 }
7667 }
7668
7669 @Override
7670 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7672 mApp, subId, "setCdmaSubscriptionMode");
7673
7674 final long identity = Binder.clearCallingIdentity();
7675 try {
7676 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7677 } finally {
7678 Binder.restoreCallingIdentity(identity);
7679 }
7680 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007681
sqianc5eccab2018-10-19 18:46:41 -07007682 @Override
sqian8c685422019-02-22 15:55:18 -08007683 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007684 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007686 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7687 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007688 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7689 }
7690 final long identity = Binder.clearCallingIdentity();
7691 try {
sqian854d44b2018-12-12 16:48:18 -08007692 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7693 for (Phone phone: PhoneFactory.getPhones()) {
7694 if (phone.getEmergencyNumberTracker() != null
7695 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7696 emergencyNumberListInternal.put(
7697 phone.getSubId(),
7698 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7699 }
sqian11b7a0e2018-12-05 18:48:28 -08007700 }
sqian854d44b2018-12-12 16:48:18 -08007701 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
sqianc5eccab2018-10-19 18:46:41 -07007705 }
7706
7707 @Override
sqian8c685422019-02-22 15:55:18 -08007708 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007709 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007710 if (!exactMatch) {
7711 TelephonyPermissions
7712 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007713 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007714 }
7715 final long identity = Binder.clearCallingIdentity();
7716 try {
sqian854d44b2018-12-12 16:48:18 -08007717 for (Phone phone: PhoneFactory.getPhones()) {
7718 if (phone.getEmergencyNumberTracker() != null
7719 && phone.getEmergencyNumberTracker() != null) {
7720 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7721 number, exactMatch)) {
7722 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007723 }
7724 }
sqian11b7a0e2018-12-05 18:48:28 -08007725 }
7726 return false;
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
7730 }
7731
sqianf4ca7ed2019-01-15 18:32:07 -08007732 /**
7733 * Update emergency number list for test mode.
7734 */
7735 @Override
7736 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7737 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7738 "updateEmergencyNumberListTestMode");
7739
7740 final long identity = Binder.clearCallingIdentity();
7741 try {
7742 for (Phone phone: PhoneFactory.getPhones()) {
7743 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7744 if (tracker != null) {
7745 tracker.executeEmergencyNumberTestModeCommand(action, num);
7746 }
7747 }
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
7750 }
7751 }
7752
7753 /**
7754 * Get the full emergency number list for test mode.
7755 */
7756 @Override
7757 public List<String> getEmergencyNumberListTestMode() {
7758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7759 "getEmergencyNumberListTestMode");
7760
7761 final long identity = Binder.clearCallingIdentity();
7762 try {
7763 Set<String> emergencyNumbers = new HashSet<>();
7764 for (Phone phone: PhoneFactory.getPhones()) {
7765 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7766 if (tracker != null) {
7767 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7768 emergencyNumbers.add(num.getNumber());
7769 }
7770 }
7771 }
7772 return new ArrayList<>(emergencyNumbers);
7773 } finally {
7774 Binder.restoreCallingIdentity(identity);
7775 }
7776 }
7777
chen xud6b45bd2018-10-30 22:27:10 -07007778 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007779 public int getEmergencyNumberDbVersion(int subId) {
7780 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7781
7782 final long identity = Binder.clearCallingIdentity();
7783 try {
7784 final Phone phone = getPhone(subId);
7785 if (phone == null) {
7786 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7787 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7788 }
7789 return phone.getEmergencyNumberDbVersion();
7790 } finally {
7791 Binder.restoreCallingIdentity(identity);
7792 }
7793 }
7794
7795 @Override
7796 public void notifyOtaEmergencyNumberDbInstalled() {
7797 enforceModifyPermission();
7798
7799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 for (Phone phone: PhoneFactory.getPhones()) {
7802 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7803 if (tracker != null) {
7804 tracker.updateOtaEmergencyNumberDatabase();
7805 }
7806 }
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
7810 }
7811
7812 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007813 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007814 enforceActiveEmergencySessionPermission();
7815
7816 final long identity = Binder.clearCallingIdentity();
7817 try {
7818 for (Phone phone: PhoneFactory.getPhones()) {
7819 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7820 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007821 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7822 }
7823 }
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
7827 }
7828
7829 @Override
7830 public void resetOtaEmergencyNumberDbFilePath() {
7831 enforceActiveEmergencySessionPermission();
7832
7833 final long identity = Binder.clearCallingIdentity();
7834 try {
7835 for (Phone phone: PhoneFactory.getPhones()) {
7836 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7837 if (tracker != null) {
7838 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007839 }
7840 }
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
7844 }
7845
7846 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007847 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7848 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7849 Phone phone = getPhone(subId);
7850 if (phone == null) {
7851 return null;
7852 }
7853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 UiccProfile profile = UiccController.getInstance()
7856 .getUiccProfileForPhone(phone.getPhoneId());
7857 if (profile != null) {
7858 return profile.getCertsFromCarrierPrivilegeAccessRules();
7859 }
7860 } finally {
7861 Binder.restoreCallingIdentity(identity);
7862 }
7863 return null;
7864 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007865
7866 /**
7867 * Enable or disable a modem stack.
7868 */
7869 @Override
7870 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7871 enforceModifyPermission();
7872
7873 final long identity = Binder.clearCallingIdentity();
7874 try {
7875 Phone phone = PhoneFactory.getPhone(slotIndex);
7876 if (phone == null) {
7877 return false;
7878 } else {
7879 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7880 }
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
7883 }
7884 }
Michelecea4cf22018-12-21 15:00:11 -08007885
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007886 /**
7887 * Whether a modem stack is enabled or not.
7888 */
7889 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007890 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7891 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007892 Phone phone = PhoneFactory.getPhone(slotIndex);
7893 if (phone == null) return false;
7894
7895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007896 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7897 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007898 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7899 }
7900
7901 final long identity = Binder.clearCallingIdentity();
7902 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007903 try {
7904 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7905 } catch (NoSuchElementException ex) {
7906 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7907 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007908 } finally {
7909 Binder.restoreCallingIdentity(identity);
7910 }
7911 }
7912
Michelecea4cf22018-12-21 15:00:11 -08007913 @Override
Michele0ea7d782019-03-19 14:58:42 -07007914 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007915 enforceModifyPermission();
7916
7917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007920 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007921 .commit();
7922 } finally {
7923 Binder.restoreCallingIdentity(identity);
7924 }
7925 }
7926
7927 @Override
Michele0ea7d782019-03-19 14:58:42 -07007928 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007929 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007931 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7932 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007933 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007934 }
Michelecea4cf22018-12-21 15:00:11 -08007935
7936 final long identity = Binder.clearCallingIdentity();
7937 try {
Michele0ea7d782019-03-19 14:58:42 -07007938 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
7942 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007943
Michele0ea7d782019-03-19 14:58:42 -07007944 @TelephonyManager.IsMultiSimSupportedResult
7945 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007946 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7947 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7948 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007949 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7950 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007951 }
7952 // Check if the hardware supports multisim functionality. If usage of multisim is not
7953 // supported by the modem, indicate that it is restricted.
7954 PhoneCapability staticCapability =
7955 mPhoneConfigurationManager.getStaticPhoneCapability();
7956 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007957 loge("isMultiSimSupportedInternal: no static configuration available");
7958 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007959 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00007960 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007961 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7962 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007963 }
7964 // Check if support of multiple SIMs is restricted by carrier
7965 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007966 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007967 }
7968
Michele0ea7d782019-03-19 14:58:42 -07007969 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007970 }
7971
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007972 /**
7973 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007974 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7975 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7976 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007977 * @param numOfSims number of active sims we want to switch to
7978 */
7979 @Override
7980 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007981 if (numOfSims == 1) {
7982 enforceModifyPermission();
7983 } else {
7984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7985 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7986 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007987 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007988
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007989 try {
Michele30b57b22019-03-01 12:01:14 -08007990 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007991 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007992 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7993 return;
7994 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007995 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
7998 }
7999 }
8000
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008001 @Override
8002 public boolean isApplicationOnUicc(int subId, int appType) {
8003 enforceReadPrivilegedPermission("isApplicationOnUicc");
8004 Phone phone = getPhone(subId);
8005 if (phone == null) {
8006 return false;
8007 }
8008 final long identity = Binder.clearCallingIdentity();
8009 try {
8010 UiccCard uiccCard = phone.getUiccCard();
8011 if (uiccCard == null) {
8012 return false;
8013 }
8014 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8015 if (uiccProfile == null) {
8016 return false;
8017 }
8018 if (TelephonyManager.APPTYPE_SIM <= appType
8019 && appType <= TelephonyManager.APPTYPE_ISIM) {
8020 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8021 }
8022 return false;
8023 } finally {
8024 Binder.restoreCallingIdentity(identity);
8025 }
8026 }
8027
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008028 /**
chen xub4baa772019-04-03 10:23:41 -07008029 * Get whether making changes to modem configurations will trigger reboot.
8030 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008031 */
8032 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008033 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8034 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008036 mApp, subId, callingPackage, callingFeatureId,
8037 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008038 return false;
8039 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8043 } finally {
8044 Binder.restoreCallingIdentity(identity);
8045 }
8046 }
8047
Nathan Harold29f5f052019-02-15 13:41:57 -08008048 private void updateModemStateMetrics() {
8049 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8050 // TODO: check the state for each modem if the api is ready.
8051 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8052 }
8053
Pengquan Meng3889a572019-01-23 11:16:29 -08008054 @Override
8055 public int[] getSlotsMapping() {
8056 enforceReadPrivilegedPermission("getSlotsMapping");
8057
8058 final long identity = Binder.clearCallingIdentity();
8059 try {
8060 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8061 // All logical slots should have a mapping to a physical slot.
8062 int[] logicalSlotsMapping = new int[phoneCount];
8063 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8064 for (int i = 0; i < slotInfos.length; i++) {
8065 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8066 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8067 }
8068 }
8069 return logicalSlotsMapping;
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
8072 }
8073 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008074
8075 /**
8076 * Get the IRadio HAL Version
8077 */
8078 @Override
8079 public int getRadioHalVersion() {
8080 Phone phone = getDefaultPhone();
8081 if (phone == null) return -1;
8082 HalVersion hv = phone.getHalVersion();
8083 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8084 return hv.major * 100 + hv.minor;
8085 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008086
8087 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008088 * Get the current calling package name.
8089 * @return the current calling package name
8090 */
8091 @Override
8092 public String getCurrentPackageName() {
8093 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8094 }
8095
8096 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008097 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8098 * corresponding network requests on a subId.
8099 *
8100 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008101 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008102 * 2) APN is un-metered for this subscription, or
8103 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008104 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008105 *
8106 * @return whether data is allowed for a apn type.
8107 *
8108 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008109 */
8110 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008111 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008112 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8113 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008114
8115 // Now that all security checks passes, perform the operation as ourselves.
8116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 Phone phone = getPhone(subId);
8119 if (phone == null) return false;
8120
Jack Yu41407ee2019-05-13 16:54:09 -07008121 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008122 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8123 } finally {
8124 Binder.restoreCallingIdentity(identity);
8125 }
8126 }
8127
8128 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008129 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008130 enforceReadPrivilegedPermission("isApnMetered");
8131
8132 // Now that all security checks passes, perform the operation as ourselves.
8133 final long identity = Binder.clearCallingIdentity();
8134 try {
8135 Phone phone = getPhone(subId);
8136 if (phone == null) return true; // By default return true.
8137
Jack Yu41407ee2019-05-13 16:54:09 -07008138 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141 }
8142 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008143
8144 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008145 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8146 int subscriptionId, IBooleanConsumer resultCallback) {
8147 enforceModifyPermission();
8148 long token = Binder.clearCallingIdentity();
8149 try {
8150 Phone phone = getPhone(subscriptionId);
8151 if (phone == null) {
8152 try {
8153 if (resultCallback != null) {
8154 resultCallback.accept(false);
8155 }
8156 } catch (RemoteException e) {
8157 // ignore
8158 }
8159 return;
8160 }
8161 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8162 Pair.create(specifiers, (x) -> {
8163 try {
8164 if (resultCallback != null) {
8165 resultCallback.accept(x);
8166 }
8167 } catch (RemoteException e) {
8168 // ignore
8169 }
8170 });
8171 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8172 } finally {
8173 Binder.restoreCallingIdentity(token);
8174 }
8175 }
8176
8177 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008178 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8179 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8180 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8181 if (iccRecords == null) {
8182 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8183 return false;
8184 }
8185 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8186 }
8187
8188 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008189 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8190 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008191 if (callingPackage == null) {
8192 callingPackage = getCurrentPackageName();
8193 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008194 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8195 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008196 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8197 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008198 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8199 }
8200 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8201 Intent intent = new Intent();
8202 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8203 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8204 // Bring up choose default SMS subscription dialog right now
8205 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8206 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8207 mApp.startActivity(intent);
8208 }
chen xud5ca2d52019-05-28 15:20:57 -07008209
8210 @Override
8211 public String getMmsUAProfUrl(int subId) {
8212 //TODO investigate if this API should require proper permission check in R b/133791609
8213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8216 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8217 } finally {
8218 Binder.restoreCallingIdentity(identity);
8219 }
8220 }
8221
8222 @Override
8223 public String getMmsUserAgent(int subId) {
8224 //TODO investigate if this API should require proper permission check in R b/133791609
8225 final long identity = Binder.clearCallingIdentity();
8226 try {
8227 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8228 .getString(com.android.internal.R.string.config_mms_user_agent);
8229 } finally {
8230 Binder.restoreCallingIdentity(identity);
8231 }
8232 }
Jack Yub07d4972019-05-28 16:12:25 -07008233
8234 @Override
8235 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8236 enforceModifyPermission();
8237
8238 // Now that all security checks passes, perform the operation as ourselves.
8239 final long identity = Binder.clearCallingIdentity();
8240 try {
8241 Phone phone = getPhone(subId);
8242 if (phone == null) return false;
8243
8244 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
8248 }
8249
8250 @Override
8251 public boolean isDataAllowedInVoiceCall(int subId) {
8252 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8253
8254 // Now that all security checks passes, perform the operation as ourselves.
8255 final long identity = Binder.clearCallingIdentity();
8256 try {
8257 Phone phone = getPhone(subId);
8258 if (phone == null) return false;
8259
8260 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8261 } finally {
8262 Binder.restoreCallingIdentity(identity);
8263 }
8264 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008265
changbetty97defcf2019-12-24 15:40:37 +08008266 @Override
8267 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8268 enforceModifyPermission();
8269
8270 // Now that all security checks passes, perform the operation as ourselves.
8271 final long identity = Binder.clearCallingIdentity();
8272 try {
8273 Phone phone = getPhone(subId);
8274 if (phone == null) return false;
8275
8276 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
8280 }
8281
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008282 /**
8283 * Updates whether conference event pacakge handling is enabled.
8284 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8285 * otherwise.
8286 */
8287 @Override
8288 public void setCepEnabled(boolean isCepEnabled) {
8289 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8290
8291 final long identity = Binder.clearCallingIdentity();
8292 try {
8293 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8294 for (Phone phone : PhoneFactory.getPhones()) {
8295 Phone defaultPhone = phone.getImsPhone();
8296 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8297 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8298 ImsPhoneCallTracker imsPhoneCallTracker =
8299 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8300 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8301 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8302 + imsPhone.getMsisdn());
8303 }
8304 }
8305 } finally {
8306 Binder.restoreCallingIdentity(identity);
8307 }
8308 }
allenwtsu46dcc572020-01-08 18:24:03 +08008309
8310 /**
8311 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8312 *
8313 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8314 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8315 * before being read.
8316 */
8317 @Override
8318 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8319 isCompressed) {
8320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8321 mApp, subId, "notifyRcsAutoConfigurationReceived");
8322 try {
8323 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8324 if (configBinder == null) {
8325 Rlog.e(LOG_TAG, "null result for getImsConfig");
8326 } else {
8327 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8328 }
8329 } catch (RemoteException e) {
8330 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8331 }
8332 }
zoey chenf95ca592019-12-30 16:11:23 +08008333
8334 @Override
8335 public boolean isIccLockEnabled(int subId) {
8336 enforceReadPrivilegedPermission("isIccLockEnabled");
8337
8338 // Now that all security checks passes, perform the operation as ourselves.
8339 final long identity = Binder.clearCallingIdentity();
8340 try {
8341 Phone phone = getPhone(subId);
8342 if (phone != null && phone.getIccCard() != null) {
8343 return phone.getIccCard().getIccLockEnabled();
8344 } else {
8345 return false;
8346 }
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
8349 }
8350 }
8351
8352 /**
8353 * Set the ICC pin lock enabled or disabled..
8354 *
8355 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8356 * 0 or a positive integer as the attempts remaining value.
8357 *
8358 */
8359 @Override
8360 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8361 enforceModifyPermission();
8362
8363 Phone phone = getPhone(subId);
8364 if (phone == null) {
8365 return 0;
8366 }
8367 // Now that all security checks passes, perform the operation as ourselves.
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8371 new Pair<Boolean, String>(enabled, password), phone, null);
8372 return attemptsRemaining;
8373
8374 } catch (Exception e) {
8375 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8376 } finally {
8377 Binder.restoreCallingIdentity(identity);
8378 }
8379 return 0;
8380 }
8381
8382 /**
8383 * Change the ICC password used in ICC pin lock.
8384 *
8385 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8386 * 0 or a positive integer as the attempts remaining value.
8387 *
8388 */
8389 @Override
8390 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8391 enforceModifyPermission();
8392
8393 Phone phone = getPhone(subId);
8394 if (phone == null) {
8395 return 0;
8396 }
8397 // Now that all security checks passes, perform the operation as ourselves.
8398 final long identity = Binder.clearCallingIdentity();
8399 try {
8400 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8401 new Pair<String, String>(oldPassword, newPassword), phone, null);
8402 return attemptsRemaining;
8403
8404 } catch (Exception e) {
8405 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8406 } finally {
8407 Binder.restoreCallingIdentity(identity);
8408 }
8409 return 0;
8410 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008411
8412 @Override
8413 public boolean canConnectTo5GInDsdsMode() {
8414 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008416}