blob: 3372aaeeb8b4be2a4f1242d31ba1e7edf34af6c7 [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;
sqian80370722020-01-29 15:02:51 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800174import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700175import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800177import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700179import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800180import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800181
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700182import java.io.FileDescriptor;
183import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800186import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800188import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100189import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700191import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800192import java.util.Set;
Hall Liud0d1dc92020-01-20 13:42:00 -0800193import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
195/**
196 * Implementation of the ITelephony interface.
197 */
Santos Cordon117fee72014-05-16 17:56:12 -0700198public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199 private static final String LOG_TAG = "PhoneInterfaceManager";
200 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
201 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203
204 // Message codes used with mMainThreadHandler
205 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700206 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
207 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700208 private static final int CMD_OPEN_CHANNEL = 9;
209 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
210 private static final int CMD_CLOSE_CHANNEL = 11;
211 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800212 private static final int CMD_NV_READ_ITEM = 13;
213 private static final int EVENT_NV_READ_ITEM_DONE = 14;
214 private static final int CMD_NV_WRITE_ITEM = 15;
215 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
216 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
217 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700218 private static final int CMD_RESET_MODEM_CONFIG = 19;
219 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800220 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
221 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
222 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
223 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800224 private static final int CMD_SEND_ENVELOPE = 25;
225 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000226 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
227 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700228 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
229 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
230 private static final int CMD_EXCHANGE_SIM_IO = 31;
231 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800232 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
233 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700234 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700236 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
237 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700238 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
239 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
240 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
241 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700242 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
243 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
244 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
245 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700246 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800247 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
248 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000249 private static final int CMD_SWITCH_SLOTS = 50;
250 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700251 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
252 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
253 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
254 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
255 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
256 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
257 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
258 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700259 private static final int CMD_GET_ALL_CELL_INFO = 60;
260 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
261 private static final int CMD_GET_CELL_LOCATION = 62;
262 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_MODEM_REBOOT = 64;
264 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700265 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
266 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800267 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
268 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700269 private static final int CMD_GET_MODEM_STATUS = 70;
270 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700271 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
272 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700273 private static final int CMD_ERASE_MODEM_CONFIG = 74;
274 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800275 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
276 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
277 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
278 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800279 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
280 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
sqian80370722020-01-29 15:02:51 -0800281 private static final int CMD_GET_CALL_FORWARDING = 83;
282 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
283 private static final int CMD_SET_CALL_FORWARDING = 85;
284 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
285 private static final int CMD_GET_CALL_WAITING = 87;
286 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
287 private static final int CMD_SET_CALL_WAITING = 89;
288 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800290 // Parameters of select command.
291 private static final int SELECT_COMMAND = 0xA4;
292 private static final int SELECT_P1 = 0x04;
293 private static final int SELECT_P2 = 0;
294 private static final int SELECT_P3 = 0x10;
295
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 /** The singleton instance. */
297 private static PhoneInterfaceManager sInstance;
298
Wink Saville3ab207e2014-11-20 13:07:20 -0800299 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800300 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800301 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700302 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private AppOpsManager mAppOps;
304 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800305 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700307 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308
Derek Tan97ebb422014-09-05 16:55:38 -0700309 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
310 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800311 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800312 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700313
Michelecea4cf22018-12-21 15:00:11 -0800314 // String to store multi SIM allowed
315 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
316
Derek Tan740e1672017-06-27 14:56:27 -0700317 // The AID of ISD-R.
318 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
319
yinxub1bed742017-04-17 11:45:04 -0700320 private NetworkScanRequestTracker mNetworkScanRequestTracker;
321
David Kelly5e06a7f2018-03-12 14:10:59 +0000322 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
323 private static final int MANUFACTURER_CODE_LENGTH = 8;
324
Derek Tan89e89d42014-07-08 17:00:10 -0700325 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700326 * Experiment flag to enable erase modem config on reset network, default value is false
327 */
328 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
329 "reset_network_erase_modem_config_enabled";
330
331 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700332 * A request object to use for transmitting data to an ICC.
333 */
334 private static final class IccAPDUArgument {
335 public int channel, cla, command, p1, p2, p3;
336 public String data;
337
338 public IccAPDUArgument(int channel, int cla, int command,
339 int p1, int p2, int p3, String data) {
340 this.channel = channel;
341 this.cla = cla;
342 this.command = command;
343 this.p1 = p1;
344 this.p2 = p2;
345 this.p3 = p3;
346 this.data = data;
347 }
348 }
349
350 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700351 * A request object to use for transmitting data to an ICC.
352 */
353 private static final class ManualNetworkSelectionArgument {
354 public OperatorInfo operatorInfo;
355 public boolean persistSelection;
356
357 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
358 this.operatorInfo = operatorInfo;
359 this.persistSelection = persistSelection;
360 }
361 }
362
363 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
365 * request after sending. The main thread will notify the request when it is complete.
366 */
367 private static final class MainThreadRequest {
368 /** The argument to use for the request */
369 public Object argument;
370 /** The result of the request that is run on the main thread */
371 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800372 // The subscriber id that this request applies to. Defaults to
373 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
374 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Nathan Harold92bed182018-10-12 18:16:49 -0700376 // In cases where subId is unavailable, the caller needs to specify the phone.
377 public Phone phone;
378
vagdeviaf9a5b92018-08-15 16:01:53 -0700379 public WorkSource workSource;
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 public MainThreadRequest(Object argument) {
382 this.argument = argument;
383 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800384
Nathan Harold92bed182018-10-12 18:16:49 -0700385 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
386 this.argument = argument;
387 if (phone != null) {
388 this.phone = phone;
389 }
390 this.workSource = workSource;
391 }
392
vagdeviaf9a5b92018-08-15 16:01:53 -0700393 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800394 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800395 if (subId != null) {
396 this.subId = subId;
397 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700398 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 }
401
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800402 private static final class IncomingThirdPartyCallArgs {
403 public final ComponentName component;
404 public final String callId;
405 public final String callerDisplayName;
406
407 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
408 String callerDisplayName) {
409 this.component = component;
410 this.callId = callId;
411 this.callerDisplayName = callerDisplayName;
412 }
413 }
414
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 /**
416 * A handler that processes messages on the main thread in the phone process. Since many
417 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
418 * inbound binder threads to the main thread in the phone process. The Binder thread
419 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
420 * on, which will be notified when the operation completes and will contain the result of the
421 * request.
422 *
423 * <p>If a MainThreadRequest object is provided in the msg.obj field,
424 * note that request.result must be set to something non-null for the calling thread to
425 * unblock.
426 */
427 private final class MainThreadHandler extends Handler {
428 @Override
429 public void handleMessage(Message msg) {
430 MainThreadRequest request;
431 Message onCompleted;
432 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800433 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800435 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436
437 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 case CMD_HANDLE_USSD_REQUEST: {
439 request = (MainThreadRequest) msg.obj;
440 final Phone phone = getPhoneFromRequest(request);
441 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
442 String ussdRequest = ussdObject.first;
443 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700444
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 if (!isUssdApiAllowed(request.subId)) {
446 // Carrier does not support use of this API, return failure.
447 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
448 UssdResponse response = new UssdResponse(ussdRequest, null);
449 Bundle returnData = new Bundle();
450 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
451 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700452
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 request.result = true;
454 notifyRequester(request);
455 return;
456 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700457
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 try {
459 request.result = phone != null
460 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
461 } catch (CallStateException cse) {
462 request.result = false;
463 }
464 // Wake up the requesting thread
465 notifyRequester(request);
466 break;
pkanwar32d516d2016-10-14 19:37:38 -0700467 }
468
Yorke Lee716f67e2015-06-17 15:39:16 -0700469 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700471 final Phone phone = getPhoneFromRequest(request);
472 request.result = phone != null ?
473 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
474 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700476 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700484 if (uiccCard == null) {
485 loge("iccTransmitApduLogicalChannel: No UICC");
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700488 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
490 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 iccArgument.channel, iccArgument.cla, iccArgument.command,
493 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 break;
497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700499 ar = (AsyncResult) msg.obj;
500 request = (MainThreadRequest) ar.userObj;
501 if (ar.exception == null && ar.result != null) {
502 request.result = ar.result;
503 } else {
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
505 if (ar.result == null) {
506 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800507 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800509 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 } else {
511 loge("iccTransmitApduLogicalChannel: Unknown exception");
512 }
513 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 break;
516
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
518 request = (MainThreadRequest) msg.obj;
519 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800520 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700521 if (uiccCard == null) {
522 loge("iccTransmitApduBasicChannel: No UICC");
523 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 } else {
526 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
527 request);
528 uiccCard.iccTransmitApduBasicChannel(
529 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
530 iccArgument.p3, iccArgument.data, onCompleted);
531 }
532 break;
533
534 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
535 ar = (AsyncResult) msg.obj;
536 request = (MainThreadRequest) ar.userObj;
537 if (ar.exception == null && ar.result != null) {
538 request.result = ar.result;
539 } else {
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
541 if (ar.result == null) {
542 loge("iccTransmitApduBasicChannel: Empty response");
543 } else if (ar.exception instanceof CommandException) {
544 loge("iccTransmitApduBasicChannel: CommandException: " +
545 ar.exception);
546 } else {
547 loge("iccTransmitApduBasicChannel: Unknown exception");
548 }
549 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 break;
552
553 case CMD_EXCHANGE_SIM_IO:
554 request = (MainThreadRequest) msg.obj;
555 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 if (uiccCard == null) {
558 loge("iccExchangeSimIO: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
563 request);
564 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
565 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
566 iccArgument.data, onCompleted);
567 }
568 break;
569
570 case EVENT_EXCHANGE_SIM_IO_DONE:
571 ar = (AsyncResult) msg.obj;
572 request = (MainThreadRequest) ar.userObj;
573 if (ar.exception == null && ar.result != null) {
574 request.result = ar.result;
575 } else {
576 request.result = new IccIoResult(0x6f, 0, (byte[])null);
577 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700579 break;
580
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 case CMD_SEND_ENVELOPE:
582 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800583 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 if (uiccCard == null) {
585 loge("sendEnvelopeWithStatus: No UICC");
586 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
590 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
591 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 break;
593
594 case EVENT_SEND_ENVELOPE_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700597 if (ar.exception == null && ar.result != null) {
598 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
601 if (ar.result == null) {
602 loge("sendEnvelopeWithStatus: Empty response");
603 } else if (ar.exception instanceof CommandException) {
604 loge("sendEnvelopeWithStatus: CommandException: " +
605 ar.exception);
606 } else {
607 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
608 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800611 break;
612
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 case CMD_OPEN_CHANNEL:
614 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800615 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800616 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 if (uiccCard == null) {
618 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800619 request.result = new IccOpenLogicalChannelResponse(-1,
620 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 } else {
623 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800624 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
625 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 break;
628
629 case EVENT_OPEN_CHANNEL_DONE:
630 ar = (AsyncResult) msg.obj;
631 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 int[] result = (int[]) ar.result;
635 int channelId = result[0];
636 byte[] selectResponse = null;
637 if (result.length > 1) {
638 selectResponse = new byte[result.length - 1];
639 for (int i = 1; i < result.length; ++i) {
640 selectResponse[i - 1] = (byte) result[i];
641 }
642 }
643 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700644 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 if (ar.result == null) {
647 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 if (ar.exception != null) {
650 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
651 }
652
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700654 if (ar.exception instanceof CommandException) {
655 CommandException.Error error =
656 ((CommandException) (ar.exception)).getCommandError();
657 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700658 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700659 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 }
662 }
663 openChannelResp = new IccOpenLogicalChannelResponse(
664 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700666 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 break;
669
670 case CMD_CLOSE_CHANNEL:
671 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800672 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 if (uiccCard == null) {
674 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900675 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 } else {
678 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
679 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
680 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 break;
682
683 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800684 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
685 break;
686
687 case CMD_NV_READ_ITEM:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
691 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
694 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800697 if (ar.exception == null && ar.result != null) {
698 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800700 request.result = "";
701 if (ar.result == null) {
702 loge("nvReadItem: Empty response");
703 } else if (ar.exception instanceof CommandException) {
704 loge("nvReadItem: CommandException: " +
705 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 }
709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 break;
712
Jake Hambye994d462014-02-03 13:10:13 -0800713 case CMD_NV_WRITE_ITEM:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
716 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800717 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700718 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800719 break;
720
721 case EVENT_NV_WRITE_ITEM_DONE:
722 handleNullReturnEvent(msg, "nvWriteItem");
723 break;
724
725 case CMD_NV_WRITE_CDMA_PRL:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800728 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800729 break;
730
731 case EVENT_NV_WRITE_CDMA_PRL_DONE:
732 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
733 break;
734
chen xu6dac5ab2018-10-26 17:39:23 -0700735 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800736 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700737 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800738 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800739 break;
740
chen xu6dac5ab2018-10-26 17:39:23 -0700741 case EVENT_RESET_MODEM_CONFIG_DONE:
742 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800743 break;
744
Jake Hamby7c27be32014-03-03 13:25:59 -0800745 case CMD_GET_PREFERRED_NETWORK_TYPE:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700748 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800749 break;
750
751 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
752 ar = (AsyncResult) msg.obj;
753 request = (MainThreadRequest) ar.userObj;
754 if (ar.exception == null && ar.result != null) {
755 request.result = ar.result; // Integer
756 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800757 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 if (ar.result == null) {
759 loge("getPreferredNetworkType: Empty response");
760 } else if (ar.exception instanceof CommandException) {
761 loge("getPreferredNetworkType: CommandException: " +
762 ar.exception);
763 } else {
764 loge("getPreferredNetworkType: Unknown exception");
765 }
766 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700767 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800768 break;
769
770 case CMD_SET_PREFERRED_NETWORK_TYPE:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
773 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700774 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800775 break;
776
777 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
778 handleNullReturnEvent(msg, "setPreferredNetworkType");
779 break;
780
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000781 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
782 request = (MainThreadRequest)msg.obj;
783 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000785 break;
786
787 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
788 ar = (AsyncResult)msg.obj;
789 request = (MainThreadRequest)ar.userObj;
790 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700791 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 break;
793
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800794 case CMD_SET_VOICEMAIL_NUMBER:
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
797 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800798 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
799 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800800 break;
801
802 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
803 handleNullReturnEvent(msg, "setVoicemailNumber");
804 break;
805
Stuart Scott54788802015-03-30 13:18:01 -0700806 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
809 request);
810 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
811 break;
812
813 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
814 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
815 break;
816
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 case CMD_PERFORM_NETWORK_SCAN:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
820 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
821 break;
822
sqian80370722020-01-29 15:02:51 -0800823 case CMD_GET_CALL_FORWARDING:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
826 int callForwardingReason = (Integer) request.argument;
827 getPhoneFromRequest(request).getCallForwardingOption(
828 callForwardingReason, onCompleted);
829 break;
830
831 case EVENT_GET_CALL_FORWARDING_DONE:
832 ar = (AsyncResult) msg.obj;
833 request = (MainThreadRequest) ar.userObj;
834 CallForwardingInfo callForwardingInfo = null;
835 if (ar.exception == null && ar.result != null) {
836 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
837 for (CallForwardInfo callForwardInfo : callForwardInfos) {
838 // Service Class is a bit mask per 3gpp 27.007. Search for
839 // any service for voice call.
840 if ((callForwardInfo.serviceClass
841 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
842 callForwardingInfo = new CallForwardingInfo(
843 callForwardInfo.serviceClass, callForwardInfo.reason,
844 callForwardInfo.number,
845 callForwardInfo.timeSeconds);
846 break;
847 }
848 }
849 // Didn't find a call forward info for voice call.
850 if (callForwardingInfo == null) {
851 callForwardingInfo = new CallForwardingInfo(
852 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
853 0 /* reason */, null /* number */, 0 /* timeout */);
854 }
855 } else {
856 if (ar.result == null) {
857 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
858 }
859 if (ar.exception != null) {
860 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
861 }
862 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
863 if (ar.exception instanceof CommandException) {
864 CommandException.Error error =
865 ((CommandException) (ar.exception)).getCommandError();
866 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
867 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
868 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
869 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
870 }
871 }
872 callForwardingInfo = new CallForwardingInfo(
873 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
874 }
875 request.result = callForwardingInfo;
876 notifyRequester(request);
877 break;
878
879 case CMD_SET_CALL_FORWARDING:
880 request = (MainThreadRequest) msg.obj;
881 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
882 CallForwardingInfo callForwardingInfoToSet =
883 (CallForwardingInfo) request.argument;
884 getPhoneFromRequest(request).setCallForwardingOption(
885 callForwardingInfoToSet.getStatus(),
886 callForwardingInfoToSet.getReason(),
887 callForwardingInfoToSet.getNumber(),
888 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
889 break;
890
891 case EVENT_SET_CALL_FORWARDING_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null) {
895 request.result = true;
896 } else {
897 request.result = false;
898 loge("setCallForwarding exception: " + ar.exception);
899 }
900 notifyRequester(request);
901 break;
902
903 case CMD_GET_CALL_WAITING:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
906 getPhoneFromRequest(request).getCallWaiting(onCompleted);
907 break;
908
909 case EVENT_GET_CALL_WAITING_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
913 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800914 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800915 // Service Class is a bit mask per 3gpp 27.007.
916 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800917 if (callForwardResults.length > 1
918 && ((callForwardResults[1]
919 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
920 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800921 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
922 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
923 } else {
924 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
925 }
926 } else {
927 if (ar.result == null) {
928 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
929 }
930 if (ar.exception != null) {
931 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
932 }
933 if (ar.exception instanceof CommandException) {
934 CommandException.Error error =
935 ((CommandException) (ar.exception)).getCommandError();
936 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
937 callForwardingStatus =
938 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
939 }
940 }
941 }
942 request.result = callForwardingStatus;
943 notifyRequester(request);
944 break;
945
946 case CMD_SET_CALL_WAITING:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
949 boolean isEnable = (Boolean) request.argument;
950 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
951 break;
952
953 case EVENT_SET_CALL_WAITING_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 if (ar.exception == null) {
957 request.result = true;
958 } else {
959 request.result = false;
960 loge("setCallWaiting exception: " + ar.exception);
961 }
962 notifyRequester(request);
963 break;
964
Shishir Agrawal302c8692015-06-19 13:49:39 -0700965 case EVENT_PERFORM_NETWORK_SCAN_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 CellNetworkScanResult cellScanResult;
969 if (ar.exception == null && ar.result != null) {
970 cellScanResult = new CellNetworkScanResult(
971 CellNetworkScanResult.STATUS_SUCCESS,
972 (List<OperatorInfo>) ar.result);
973 } else {
974 if (ar.result == null) {
975 loge("getCellNetworkScanResults: Empty response");
976 }
977 if (ar.exception != null) {
978 loge("getCellNetworkScanResults: Exception: " + ar.exception);
979 }
980 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
981 if (ar.exception instanceof CommandException) {
982 CommandException.Error error =
983 ((CommandException) (ar.exception)).getCommandError();
984 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
985 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
986 } else if (error == CommandException.Error.GENERIC_FAILURE) {
987 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
988 }
989 }
990 cellScanResult = new CellNetworkScanResult(errorCode, null);
991 }
992 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700993 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700994 break;
995
996 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
997 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700998 ManualNetworkSelectionArgument selArg =
999 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001000 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1001 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001002 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1003 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001004 break;
1005
1006 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception == null) {
1010 request.result = true;
1011 } else {
1012 request.result = false;
1013 loge("setNetworkSelectionModeManual " + ar.exception);
1014 }
1015 notifyRequester(request);
1016 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001017 break;
1018
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001019 case CMD_GET_MODEM_ACTIVITY_INFO:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001022 if (defaultPhone != null) {
1023 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001024 } else {
1025 ResultReceiver result = (ResultReceiver) request.argument;
1026 Bundle bundle = new Bundle();
1027 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1028 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1029 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001030 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001031 break;
1032
1033 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001036 ResultReceiver result = (ResultReceiver) request.argument;
1037
1038 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001039 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001040 // Update the last modem activity info and the result of the request.
1041 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1042 if (isModemActivityInfoValid(info)) {
1043 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1044 int[] txTimeMs = info.getTransmitTimeMillis();
1045 int[] lastModemTxTimeMs = mLastModemActivityInfo
1046 .getTransmitTimeMillis();
1047 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1048 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1049 }
1050 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1051 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1052 + mLastModemActivityInfo.getSleepTimeMillis());
1053 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1054 + mLastModemActivityInfo.getIdleTimeMillis());
1055 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1056 mLastModemActivityInfo.setReceiveTimeMillis(
1057 info.getReceiveTimeMillis()
1058 + mLastModemActivityInfo.getReceiveTimeMillis());
1059 }
1060 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1061 mLastModemActivityInfo.getSleepTimeMillis(),
1062 mLastModemActivityInfo.getIdleTimeMillis(),
1063 mLastModemActivityInfo.getTransmitTimeMillis(),
1064 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001065 } else {
1066 if (ar.result == null) {
1067 loge("queryModemActivityInfo: Empty response");
1068 } else if (ar.exception instanceof CommandException) {
1069 loge("queryModemActivityInfo: CommandException: " +
1070 ar.exception);
1071 } else {
1072 loge("queryModemActivityInfo: Unknown exception");
1073 }
1074 }
sqian1a1be542020-03-05 11:37:28 -08001075 Bundle bundle = new Bundle();
1076 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1077 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001078 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001079 break;
1080
Meng Wang1a7c35a2016-05-05 20:56:15 -07001081 case CMD_SET_ALLOWED_CARRIERS:
1082 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001083 CarrierRestrictionRules argument =
1084 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001085 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001086 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001087 break;
1088
1089 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
1092 if (ar.exception == null && ar.result != null) {
1093 request.result = ar.result;
1094 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001095 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1096 if (ar.exception instanceof CommandException) {
1097 loge("setAllowedCarriers: CommandException: " + ar.exception);
1098 CommandException.Error error =
1099 ((CommandException) (ar.exception)).getCommandError();
1100 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1101 request.result =
1102 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1103 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001104 } else {
1105 loge("setAllowedCarriers: Unknown exception");
1106 }
1107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001108 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001109 break;
1110
1111 case CMD_GET_ALLOWED_CARRIERS:
1112 request = (MainThreadRequest) msg.obj;
1113 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001114 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001115 break;
1116
1117 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1118 ar = (AsyncResult) msg.obj;
1119 request = (MainThreadRequest) ar.userObj;
1120 if (ar.exception == null && ar.result != null) {
1121 request.result = ar.result;
1122 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001123 request.result = new IllegalStateException(
1124 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001125 if (ar.result == null) {
1126 loge("getAllowedCarriers: Empty response");
1127 } else if (ar.exception instanceof CommandException) {
1128 loge("getAllowedCarriers: CommandException: " +
1129 ar.exception);
1130 } else {
1131 loge("getAllowedCarriers: Unknown exception");
1132 }
1133 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001134 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001135 break;
1136
Nathan Haroldb3014052017-01-25 15:57:32 -08001137 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 if (ar.exception == null && ar.result != null) {
1141 request.result = ar.result;
1142 } else {
1143 request.result = new IllegalArgumentException(
1144 "Failed to retrieve Forbidden Plmns");
1145 if (ar.result == null) {
1146 loge("getForbiddenPlmns: Empty response");
1147 } else {
1148 loge("getForbiddenPlmns: Unknown exception");
1149 }
1150 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001151 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001152 break;
1153
1154 case CMD_GET_FORBIDDEN_PLMNS:
1155 request = (MainThreadRequest) msg.obj;
1156 uiccCard = getUiccCardFromRequest(request);
1157 if (uiccCard == null) {
1158 loge("getForbiddenPlmns() UiccCard is null");
1159 request.result = new IllegalArgumentException(
1160 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001161 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001162 break;
1163 }
1164 Integer appType = (Integer) request.argument;
1165 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1166 if (uiccApp == null) {
1167 loge("getForbiddenPlmns() no app with specified type -- "
1168 + appType);
1169 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001171 break;
1172 } else {
1173 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1174 + " specified type -- " + appType);
1175 }
1176 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1177 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1178 onCompleted);
1179 break;
1180
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001181 case CMD_SWITCH_SLOTS:
1182 request = (MainThreadRequest) msg.obj;
1183 int[] physicalSlots = (int[]) request.argument;
1184 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1185 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1186 break;
1187
1188 case EVENT_SWITCH_SLOTS_DONE:
1189 ar = (AsyncResult) msg.obj;
1190 request = (MainThreadRequest) ar.userObj;
1191 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001192 notifyRequester(request);
1193 break;
1194 case CMD_GET_NETWORK_SELECTION_MODE:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1197 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1198 break;
1199
1200 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1201 ar = (AsyncResult) msg.obj;
1202 request = (MainThreadRequest) ar.userObj;
1203 if (ar.exception != null) {
1204 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1205 } else {
1206 int mode = ((int[]) ar.result)[0];
1207 if (mode == 0) {
1208 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1209 } else {
1210 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1211 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001212 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001213 notifyRequester(request);
1214 break;
1215 case CMD_GET_CDMA_ROAMING_MODE:
1216 request = (MainThreadRequest) msg.obj;
1217 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1218 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1219 break;
1220 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1221 ar = (AsyncResult) msg.obj;
1222 request = (MainThreadRequest) ar.userObj;
1223 if (ar.exception != null) {
1224 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1225 } else {
1226 request.result = ((int[]) ar.result)[0];
1227 }
1228 notifyRequester(request);
1229 break;
1230 case CMD_SET_CDMA_ROAMING_MODE:
1231 request = (MainThreadRequest) msg.obj;
1232 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1233 int mode = (int) request.argument;
1234 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1235 break;
1236 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1237 ar = (AsyncResult) msg.obj;
1238 request = (MainThreadRequest) ar.userObj;
1239 request.result = ar.exception == null;
1240 notifyRequester(request);
1241 break;
1242 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1243 request = (MainThreadRequest) msg.obj;
1244 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1245 int subscriptionMode = (int) request.argument;
1246 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1247 break;
1248 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1249 ar = (AsyncResult) msg.obj;
1250 request = (MainThreadRequest) ar.userObj;
1251 request.result = ar.exception == null;
1252 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001253 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001254 case CMD_GET_ALL_CELL_INFO:
1255 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001256 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001257 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001258 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001259 case EVENT_GET_ALL_CELL_INFO_DONE:
1260 ar = (AsyncResult) msg.obj;
1261 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001262 // If a timeout occurs, the response will be null
1263 request.result = (ar.exception == null && ar.result != null)
1264 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 synchronized (request) {
1266 request.notifyAll();
1267 }
1268 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001269 case CMD_REQUEST_CELL_INFO_UPDATE:
1270 request = (MainThreadRequest) msg.obj;
1271 request.phone.requestCellInfoUpdate(request.workSource,
1272 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1273 break;
1274 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
1277 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1278 try {
1279 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001280 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001281 cb.onError(
1282 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1283 ar.exception.getClass().getName(),
1284 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001285 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001287 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001288 } else {
1289 // use the result as returned
1290 cb.onCellInfo((List<CellInfo>) ar.result);
1291 }
1292 } catch (RemoteException re) {
1293 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1294 }
1295 break;
1296 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001297 request = (MainThreadRequest) msg.obj;
1298 WorkSource ws = (WorkSource) request.argument;
1299 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001300 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001301 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001302 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null) {
1306 request.result = ar.result;
1307 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001308 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001309 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001310 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001311 }
1312
1313 synchronized (request) {
1314 request.notifyAll();
1315 }
1316 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001317 case CMD_MODEM_REBOOT:
1318 request = (MainThreadRequest) msg.obj;
1319 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001320 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001321 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001322 case EVENT_CMD_MODEM_REBOOT_DONE:
1323 handleNullReturnEvent(msg, "rebootModem");
1324 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001325 case CMD_REQUEST_ENABLE_MODEM:
1326 request = (MainThreadRequest) msg.obj;
1327 boolean enable = (boolean) request.argument;
1328 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001329 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001330 PhoneConfigurationManager.getInstance()
1331 .enablePhone(request.phone, enable, onCompleted);
1332 break;
1333 case EVENT_ENABLE_MODEM_DONE:
1334 ar = (AsyncResult) msg.obj;
1335 request = (MainThreadRequest) ar.userObj;
1336 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001337 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001338 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001339 if ((boolean) request.result) {
1340 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1341 updateModemStateMetrics();
1342 } else {
1343 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1344 + ar.exception);
1345 }
1346 notifyRequester(request);
1347 break;
1348 case CMD_GET_MODEM_STATUS:
1349 request = (MainThreadRequest) msg.obj;
1350 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1351 PhoneConfigurationManager.getInstance()
1352 .getPhoneStatusFromModem(request.phone, onCompleted);
1353 break;
1354 case EVENT_GET_MODEM_STATUS_DONE:
1355 ar = (AsyncResult) msg.obj;
1356 request = (MainThreadRequest) ar.userObj;
1357 int id = request.phone.getPhoneId();
1358 if (ar.exception == null && ar.result != null) {
1359 request.result = ar.result;
1360 //update the cache as modem status has changed
1361 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1362 (boolean) request.result);
1363 } else {
1364 // Return true if modem status cannot be retrieved. For most cases,
1365 // modem status is on. And for older version modems, GET_MODEM_STATUS
1366 // and disable modem are not supported. Modem is always on.
1367 // TODO: this should be fixed in R to support a third
1368 // status UNKNOWN b/131631629
1369 request.result = true;
1370 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1371 + ar.exception);
1372 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001373 notifyRequester(request);
1374 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001375 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1376 request = (MainThreadRequest) msg.obj;
1377 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1378 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1379 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1380 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1381 break;
1382 }
1383 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1384 ar = (AsyncResult) msg.obj;
1385 request = (MainThreadRequest) ar.userObj;
1386 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1387 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1388 args.second.accept(ar.exception == null);
1389 notifyRequester(request);
1390 break;
1391 }
yincheng zhaod698b842019-09-06 17:06:54 -07001392 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 if (ar.exception == null && ar.result != null) {
1396 request.result = ar.result;
1397 } else {
1398 request.result = -1;
1399 loge("Failed to set Forbidden Plmns");
1400 if (ar.result == null) {
1401 loge("setForbidenPlmns: Empty response");
1402 } else if (ar.exception != null) {
1403 loge("setForbiddenPlmns: Exception: " + ar.exception);
1404 request.result = -1;
1405 } else {
1406 loge("setForbiddenPlmns: Unknown exception");
1407 }
1408 }
1409 notifyRequester(request);
1410 break;
1411 case CMD_SET_FORBIDDEN_PLMNS:
1412 request = (MainThreadRequest) msg.obj;
1413 uiccCard = getUiccCardFromRequest(request);
1414 if (uiccCard == null) {
1415 loge("setForbiddenPlmns: UiccCard is null");
1416 request.result = -1;
1417 notifyRequester(request);
1418 break;
1419 }
1420 Pair<Integer, List<String>> setFplmnsArgs =
1421 (Pair<Integer, List<String>>) request.argument;
1422 appType = setFplmnsArgs.first;
1423 List<String> fplmns = setFplmnsArgs.second;
1424 uiccApp = uiccCard.getApplicationByType(appType);
1425 if (uiccApp == null) {
1426 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1427 request.result = -1;
1428 loge("Failed to get UICC App");
1429 notifyRequester(request);
1430 } else {
1431 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1432 ((SIMRecords) uiccApp.getIccRecords())
1433 .setForbiddenPlmns(onCompleted, fplmns);
1434 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001435 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001436 case CMD_ERASE_MODEM_CONFIG:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1439 defaultPhone.eraseModemConfig(onCompleted);
1440 break;
1441 case EVENT_ERASE_MODEM_CONFIG_DONE:
1442 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001443 break;
zoey chenf95ca592019-12-30 16:11:23 +08001444
1445 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1448 Pair<String, String> changed = (Pair<String, String>) request.argument;
1449 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1450 changed.first, changed.second, onCompleted);
1451 break;
1452 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
1455 if (ar.exception == null) {
1456 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1457 } else {
1458 request.result = msg.arg1;
1459 }
1460 notifyRequester(request);
1461 break;
1462
1463 case CMD_SET_ICC_LOCK_ENABLED:
1464 request = (MainThreadRequest) msg.obj;
1465 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1466 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1467 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1468 enabled.first, enabled.second, onCompleted);
1469 break;
1470 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
1473 if (ar.exception == null) {
1474 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1475 } else {
1476 request.result = msg.arg1;
1477 }
1478 notifyRequester(request);
1479 break;
1480
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 default:
1482 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1483 break;
1484 }
1485 }
Jake Hambye994d462014-02-03 13:10:13 -08001486
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 private void notifyRequester(MainThreadRequest request) {
1488 synchronized (request) {
1489 request.notifyAll();
1490 }
1491 }
1492
Jake Hambye994d462014-02-03 13:10:13 -08001493 private void handleNullReturnEvent(Message msg, String command) {
1494 AsyncResult ar = (AsyncResult) msg.obj;
1495 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1496 if (ar.exception == null) {
1497 request.result = true;
1498 } else {
1499 request.result = false;
1500 if (ar.exception instanceof CommandException) {
1501 loge(command + ": CommandException: " + ar.exception);
1502 } else {
1503 loge(command + ": Unknown exception");
1504 }
1505 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001506 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 }
1509
1510 /**
1511 * Posts the specified command to be executed on the main thread,
1512 * waits for the request to complete, and returns the result.
1513 * @see #sendRequestAsync
1514 */
1515 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001516 return sendRequest(
1517 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001518 }
1519
1520 /**
1521 * Posts the specified command to be executed on the main thread,
1522 * waits for the request to complete, and returns the result.
1523 * @see #sendRequestAsync
1524 */
1525 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1526 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001527 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001528 }
1529
1530 /**
1531 * Posts the specified command to be executed on the main thread,
1532 * waits for the request to complete, and returns the result.
1533 * @see #sendRequestAsync
1534 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001535 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001536 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001537 }
1538
1539 /**
1540 * Posts the specified command to be executed on the main thread,
1541 * waits for the request to complete, and returns the result.
1542 * @see #sendRequestAsync
1543 */
Nathan Harold92bed182018-10-12 18:16:49 -07001544 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1545 return sendRequest(command, argument, subId, null, workSource);
1546 }
1547
1548 /**
1549 * Posts the specified command to be executed on the main thread,
1550 * waits for the request to complete, and returns the result.
1551 * @see #sendRequestAsync
1552 */
1553 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1554 return sendRequest(
1555 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1556 }
1557
1558 /**
1559 * Posts the specified command to be executed on the main thread,
1560 * waits for the request to complete, and returns the result.
1561 * @see #sendRequestAsync
1562 */
1563 private Object sendRequest(
1564 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1566 throw new RuntimeException("This method will deadlock if called from the main thread.");
1567 }
1568
Nathan Harold92bed182018-10-12 18:16:49 -07001569 MainThreadRequest request = null;
1570 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1571 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1572 } else if (phone != null) {
1573 request = new MainThreadRequest(argument, phone, workSource);
1574 } else {
1575 request = new MainThreadRequest(argument, subId, workSource);
1576 }
1577
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 Message msg = mMainThreadHandler.obtainMessage(command, request);
1579 msg.sendToTarget();
1580
1581 // Wait for the request to complete
1582 synchronized (request) {
1583 while (request.result == null) {
1584 try {
1585 request.wait();
1586 } catch (InterruptedException e) {
1587 // Do nothing, go back and wait until the request is complete
1588 }
1589 }
1590 }
1591 return request.result;
1592 }
1593
1594 /**
1595 * Asynchronous ("fire and forget") version of sendRequest():
1596 * Posts the specified command to be executed on the main thread, and
1597 * returns immediately.
1598 * @see #sendRequest
1599 */
1600 private void sendRequestAsync(int command) {
1601 mMainThreadHandler.sendEmptyMessage(command);
1602 }
1603
1604 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001605 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001606 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001607 */
1608 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001609 sendRequestAsync(command, argument, null, null);
1610 }
1611
1612 /**
1613 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1614 * @see {@link #sendRequest(int,Object)}
1615 */
1616 private void sendRequestAsync(
1617 int command, Object argument, Phone phone, WorkSource workSource) {
1618 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001619 Message msg = mMainThreadHandler.obtainMessage(command, request);
1620 msg.sendToTarget();
1621 }
1622
1623 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 * Initialize the singleton PhoneInterfaceManager instance.
1625 * This is only done once, at startup, from PhoneApp.onCreate().
1626 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001627 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 synchronized (PhoneInterfaceManager.class) {
1629 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001630 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 } else {
1632 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1633 }
1634 return sInstance;
1635 }
1636 }
1637
1638 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001639 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001642 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001643 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1645 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001646 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001647 mTelephonySharedPreferences =
1648 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001649 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001650 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001651
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 publish();
1653 }
1654
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001655 private Phone getDefaultPhone() {
1656 Phone thePhone = getPhone(getDefaultSubscription());
1657 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1658 }
1659
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 private void publish() {
1661 if (DBG) log("publish: " + this);
1662
1663 ServiceManager.addService("phone", this);
1664 }
1665
Stuart Scott584921c2015-01-15 17:10:34 -08001666 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001667 if (request.phone != null) {
1668 return request.phone;
1669 } else {
1670 return getPhoneFromSubId(request.subId);
1671 }
1672 }
1673
1674 private Phone getPhoneFromSubId(int subId) {
1675 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1676 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001677 }
1678
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001679 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1680 Phone phone = getPhoneFromRequest(request);
1681 return phone == null ? null :
1682 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1683 }
1684
Wink Saville36469e72014-06-11 15:17:00 -07001685 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001687 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001690 private void sendEraseModemConfig(Phone phone) {
1691 if (phone != null) {
1692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1693 mApp, phone.getSubId(), "eraseModemConfig");
1694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1697 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
1700 }
1701 }
1702 }
1703
Peter Wang050bb052020-01-13 23:33:09 -08001704 private boolean isImsAvailableOnDevice() {
1705 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1706 if (pm == null) {
1707 // For some reason package manger is not available.. This will fail internally anyway,
1708 // so do not throw error and allow.
1709 return true;
1710 }
1711 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1712 }
1713
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001715 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001716 }
1717
Wink Savilleb564aae2014-10-23 10:18:09 -07001718 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 if (DBG) log("dial: " + number);
1720 // No permission check needed here: This is just a wrapper around the
1721 // ACTION_DIAL intent, which is available to any app since it puts up
1722 // the UI before it does anything.
1723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001724 final long identity = Binder.clearCallingIdentity();
1725 try {
1726 String url = createTelUrl(number);
1727 if (url == null) {
1728 return;
1729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731 // PENDING: should we just silently fail if phone is offhook or ringing?
1732 PhoneConstants.State state = mCM.getState(subId);
1733 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1734 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1735 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1736 mApp.startActivity(intent);
1737 }
1738 } finally {
1739 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741 }
1742
1743 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001744 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001745 }
1746
Wink Savilleb564aae2014-10-23 10:18:09 -07001747 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 if (DBG) log("call: " + number);
1749
1750 // This is just a wrapper around the ACTION_CALL intent, but we still
1751 // need to do a permission check since we're calling startActivity()
1752 // from the context of the phone app.
1753 enforceCallPermission();
1754
Jordan Liu1617b712019-07-10 15:06:26 -07001755 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 != AppOpsManager.MODE_ALLOWED) {
1757 return;
1758 }
1759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 String url = createTelUrl(number);
1763 if (url == null) {
1764 return;
1765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 boolean isValid = false;
1768 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1769 if (slist != null) {
1770 for (SubscriptionInfo subInfoRecord : slist) {
1771 if (subInfoRecord.getSubscriptionId() == subId) {
1772 isValid = true;
1773 break;
1774 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001775 }
Wink Saville08874612014-08-31 19:19:58 -07001776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001777 if (!isValid) {
1778 return;
1779 }
Wink Saville08874612014-08-31 19:19:58 -07001780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001781 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1782 intent.putExtra(SUBSCRIPTION_KEY, subId);
1783 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1784 mApp.startActivity(intent);
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
1787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
Wink Savilleb564aae2014-10-23 10:18:09 -07001790 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001791 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001792 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1793 }
1794
Wink Savilleb564aae2014-10-23 10:18:09 -07001795 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001796 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001797 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1798 }
1799
Wink Savilleb564aae2014-10-23 10:18:09 -07001800 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1806 checkSimPin.start();
1807 return checkSimPin.unlockSim(null, pin);
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
1810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
Wink Savilleb564aae2014-10-23 10:18:09 -07001813 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815
1816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1819 checkSimPuk.start();
1820 return checkSimPuk.unlockSim(puk, pin);
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
1823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
1826 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001827 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 * a synchronous one.
1829 */
1830 private static class UnlockSim extends Thread {
1831
1832 private final IccCard mSimCard;
1833
1834 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001835 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1836 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837
1838 // For replies from SimCard interface
1839 private Handler mHandler;
1840
1841 // For async handler to identify request type
1842 private static final int SUPPLY_PIN_COMPLETE = 100;
1843
1844 public UnlockSim(IccCard simCard) {
1845 mSimCard = simCard;
1846 }
1847
1848 @Override
1849 public void run() {
1850 Looper.prepare();
1851 synchronized (UnlockSim.this) {
1852 mHandler = new Handler() {
1853 @Override
1854 public void handleMessage(Message msg) {
1855 AsyncResult ar = (AsyncResult) msg.obj;
1856 switch (msg.what) {
1857 case SUPPLY_PIN_COMPLETE:
1858 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1859 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001860 mRetryCount = msg.arg1;
1861 if (ar.exception != null) {
1862 if (ar.exception instanceof CommandException &&
1863 ((CommandException)(ar.exception)).getCommandError()
1864 == CommandException.Error.PASSWORD_INCORRECT) {
1865 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1866 } else {
1867 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1868 }
1869 } else {
1870 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 mDone = true;
1873 UnlockSim.this.notifyAll();
1874 }
1875 break;
1876 }
1877 }
1878 };
1879 UnlockSim.this.notifyAll();
1880 }
1881 Looper.loop();
1882 }
1883
1884 /*
1885 * Use PIN or PUK to unlock SIM card
1886 *
1887 * If PUK is null, unlock SIM card with PIN
1888 *
1889 * If PUK is not null, unlock SIM card with PUK and set PIN code
1890 */
Wink Saville9de0f752013-10-22 19:04:03 -07001891 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892
1893 while (mHandler == null) {
1894 try {
1895 wait();
1896 } catch (InterruptedException e) {
1897 Thread.currentThread().interrupt();
1898 }
1899 }
1900 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1901
1902 if (puk == null) {
1903 mSimCard.supplyPin(pin, callback);
1904 } else {
1905 mSimCard.supplyPuk(puk, pin, callback);
1906 }
1907
1908 while (!mDone) {
1909 try {
1910 Log.d(LOG_TAG, "wait for done");
1911 wait();
1912 } catch (InterruptedException e) {
1913 // Restore the interrupted status
1914 Thread.currentThread().interrupt();
1915 }
1916 }
1917 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001918 int[] resultArray = new int[2];
1919 resultArray[0] = mResult;
1920 resultArray[1] = mRetryCount;
1921 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923 }
1924
1925 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001926 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001927
1928 }
1929
Wink Savilleb564aae2014-10-23 10:18:09 -07001930 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 // No permission check needed here: this call is harmless, and it's
1932 // needed for the ServiceState.requestStateUpdate() call (which is
1933 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 final long identity = Binder.clearCallingIdentity();
1935 try {
1936 final Phone phone = getPhone(subId);
1937 if (phone != null) {
1938 phone.updateServiceLocation();
1939 }
1940 } finally {
1941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001945 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001946 @Override
1947 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001948 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001949 }
1950
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001951 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001952 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1953 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1954 callingFeatureId);
1955 }
1956
1957 @Deprecated
1958 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001960 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1961 }
1962
1963 @Override
1964 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1965 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001967 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001968 return false;
1969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001970
1971 final long identity = Binder.clearCallingIdentity();
1972 try {
1973 return isRadioOnForSubscriber(subId);
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
1976 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001977 }
1978
1979 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 final long identity = Binder.clearCallingIdentity();
1981 try {
1982 final Phone phone = getPhone(subId);
1983 if (phone != null) {
1984 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1985 } else {
1986 return false;
1987 }
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
1993 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001994 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
Wink Saville36469e72014-06-11 15:17:00 -07001996
Wink Savilleb564aae2014-10-23 10:18:09 -07001997 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999
2000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Wink Saville36469e72014-06-11 15:17:00 -07002009 }
2010
2011 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002012 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002013 }
2014
Wink Savilleb564aae2014-10-23 10:18:09 -07002015 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017
2018 final long identity = Binder.clearCallingIdentity();
2019 try {
2020 final Phone phone = getPhone(subId);
2021 if (phone == null) {
2022 return false;
2023 }
2024 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2025 toggleRadioOnOffForSubscriber(subId);
2026 }
2027 return true;
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
Wink Saville36469e72014-06-11 15:17:00 -07002032
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002033 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002034 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002035 /*
2036 * If any of the Radios are available, it will need to be
2037 * shutdown. So return true if any Radio is available.
2038 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 final long identity = Binder.clearCallingIdentity();
2040 try {
2041 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2042 Phone phone = PhoneFactory.getPhone(i);
2043 if (phone != null && phone.isRadioAvailable()) return true;
2044 }
2045 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2046 return false;
2047 } finally {
2048 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002049 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002050 }
2051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002052 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002053 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 enforceModifyPermission();
2055
2056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2059 logv("Shutting down Phone " + i);
2060 shutdownRadioUsingPhoneId(i);
2061 }
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002064 }
2065 }
2066
2067 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002068 Phone phone = PhoneFactory.getPhone(phoneId);
2069 if (phone != null && phone.isRadioAvailable()) {
2070 phone.shutdownRadio();
2071 }
2072 }
2073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002075 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2080 if (defaultPhone != null) {
2081 defaultPhone.setRadioPower(turnOn);
2082 return true;
2083 } else {
2084 loge("There's no default phone.");
2085 return false;
2086 }
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002089 }
Wink Saville36469e72014-06-11 15:17:00 -07002090 }
2091
Wink Savilleb564aae2014-10-23 10:18:09 -07002092 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094
2095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 final Phone phone = getPhone(subId);
2098 if (phone != null) {
2099 phone.setRadioPower(turnOn);
2100 return true;
2101 } else {
2102 return false;
2103 }
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108
Wink Saville36469e72014-06-11 15:17:00 -07002109 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002110 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 public boolean enableDataConnectivity() {
2112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 int subId = mSubscriptionController.getDefaultDataSubId();
2117 final Phone phone = getPhone(subId);
2118 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002119 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120 return true;
2121 } else {
2122 return false;
2123 }
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Wink Saville36469e72014-06-11 15:17:00 -07002129 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002130 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 public boolean disableDataConnectivity() {
2132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 int subId = mSubscriptionController.getDefaultDataSubId();
2137 final Phone phone = getPhone(subId);
2138 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002139 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002140 return true;
2141 } else {
2142 return false;
2143 }
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 }
2148
Sanket Padawe356d7632015-06-22 14:03:32 -07002149 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002150 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002151 final long identity = Binder.clearCallingIdentity();
2152 try {
2153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002155 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 } else {
2157 return false;
2158 }
2159 } finally {
2160 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 }
2163
2164 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002165 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
pkanwarae03a6b2016-11-06 20:37:09 -08002168 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002169 enforceCallPermission();
2170
2171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2174 return;
2175 }
2176 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2177 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
2180 }
pkanwar32d516d2016-10-14 19:37:38 -07002181 };
2182
Wink Savilleb564aae2014-10-23 10:18:09 -07002183 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185
2186 final long identity = Binder.clearCallingIdentity();
2187 try {
2188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2189 return false;
2190 }
2191 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002198 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002201 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 Phone phone = PhoneFactory.getPhone(slotIndex);
2205 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2206 PhoneConstantConversions.convertCallState(phone.getState());
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
2209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
Sanket Padawe356d7632015-06-22 14:03:32 -07002212 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002213 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002214 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2215 }
2216
2217 @Override
2218 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 final long identity = Binder.clearCallingIdentity();
2220 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002221 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 if (phone != null) {
2223 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2224 } else {
2225 return PhoneConstantConversions.convertDataState(
2226 PhoneConstants.DataState.DISCONNECTED);
2227 }
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002234 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002235 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2236 }
2237
2238 @Override
2239 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 final long identity = Binder.clearCallingIdentity();
2241 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002242 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243 if (phone != null) {
2244 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2245 } else {
2246 return TelephonyManager.DATA_ACTIVITY_NONE;
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
2253 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002254 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002255 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002256 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002257
2258 LocationAccessPolicy.LocationPermissionResult locationResult =
2259 LocationAccessPolicy.checkLocationPermission(mApp,
2260 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2261 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002262 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002263 .setCallingPid(Binder.getCallingPid())
2264 .setCallingUid(Binder.getCallingUid())
2265 .setMethod("getCellLocation")
Hall Liu460a6de2020-01-24 18:07:12 -08002266 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002267 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2268 .build());
2269 switch (locationResult) {
2270 case DENIED_HARD:
2271 throw new SecurityException("Not allowed to access cell location");
2272 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002273 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2274 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002281 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002282 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002283 } finally {
2284 Binder.restoreCallingIdentity(identity);
2285 }
Svetoslav64fad262015-04-14 14:35:21 -07002286 }
2287
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 @Override
Jack Yu01425032020-02-22 19:38:58 -08002289 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002290 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2291 // registered cell info, so return a NULL country instead.
2292 final long identity = Binder.clearCallingIdentity();
2293 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002294 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2295 // Get default phone in this case.
2296 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2297 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002298 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002300 if (phone == null) return "";
2301 ServiceStateTracker sst = phone.getServiceStateTracker();
2302 if (sst == null) return "";
2303 LocaleTracker lt = sst.getLocaleTracker();
2304 if (lt == null) return "";
2305 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2306 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2307 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002308 } finally {
2309 Binder.restoreCallingIdentity(identity);
2310 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002311 }
2312
2313 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002315 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002319 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 mApp.enforceCallingOrSelfPermission(
2321 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002322
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 final Phone phone = getPhone(subId);
2326 if (phone != null) {
2327 phone.enableLocationUpdates();
2328 }
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333
2334 @Override
2335 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002336 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002337 }
2338
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mApp.enforceCallingOrSelfPermission(
2342 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 final Phone phone = getPhone(subId);
2347 if (phone != null) {
2348 phone.disableLocationUpdates();
2349 }
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
Nathan Harold31d7ff32018-10-15 20:20:30 -07002355 /**
2356 * Returns the target SDK version number for a given package name.
2357 *
Nathan Haroldec184742019-07-10 17:04:16 -07002358 * This call MUST be invoked before clearing the calling UID.
2359 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002360 * @return target SDK if the package is found or INT_MAX.
2361 */
2362 private int getTargetSdk(String packageName) {
2363 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002364 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002365 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002366 if (ai != null) return ai.targetSdkVersion;
2367 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002368 loge("Failed to get package info for pkg="
2369 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002370 }
2371 return Integer.MAX_VALUE;
2372 }
2373
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 @Override
2375 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002376 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2377 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002378 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002379 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2380 throw new SecurityException(
2381 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2382 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002383
Jordan Liu1617b712019-07-10 15:06:26 -07002384 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2386 return null;
2387 }
Svetoslav64fad262015-04-14 14:35:21 -07002388
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002389 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002391 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002392 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393
Nathan Haroldf180aac2018-06-01 18:43:55 -07002394 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2395 for (CellInfo ci : info) {
2396 if (ci instanceof CellInfoGsm) {
2397 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2398 } else if (ci instanceof CellInfoWcdma) {
2399 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002402 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002405 private List<CellInfo> getCachedCellInfo() {
2406 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2407 for (Phone phone : PhoneFactory.getPhones()) {
2408 List<CellInfo> info = phone.getAllCellInfo();
2409 if (info != null) cellInfos.addAll(info);
2410 }
2411 return cellInfos;
2412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413
2414 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002415 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002416 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002417 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002418
2419 LocationAccessPolicy.LocationPermissionResult locationResult =
2420 LocationAccessPolicy.checkLocationPermission(mApp,
2421 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2422 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002423 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002424 .setCallingPid(Binder.getCallingPid())
2425 .setCallingUid(Binder.getCallingUid())
2426 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002427 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002428 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2429 .build());
2430 switch (locationResult) {
2431 case DENIED_HARD:
2432 throw new SecurityException("Not allowed to access cell info");
2433 case DENIED_SOFT:
2434 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002437 final int targetSdk = getTargetSdk(callingPackage);
2438 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2439 return getCachedCellInfo();
2440 }
2441
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002442 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2447 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002448 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002449 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450 if (info != null) cellInfos.addAll(info);
2451 }
2452 return cellInfos;
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 }
2456 }
2457
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002458 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002459 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2460 String callingFeatureId) {
2461 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2462 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002463 }
2464
2465 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002466 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2467 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002468 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002469 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002470 }
2471
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002472 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2473 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002474 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002475 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002476
2477 LocationAccessPolicy.LocationPermissionResult locationResult =
2478 LocationAccessPolicy.checkLocationPermission(mApp,
2479 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2480 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002481 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002482 .setCallingPid(Binder.getCallingPid())
2483 .setCallingUid(Binder.getCallingUid())
2484 .setMethod("requestCellInfoUpdate")
2485 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2486 .build());
2487 switch (locationResult) {
2488 case DENIED_HARD:
2489 throw new SecurityException("Not allowed to access cell info");
2490 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002491 try {
2492 cb.onCellInfo(new ArrayList<CellInfo>());
2493 } catch (RemoteException re) {
2494 // Drop without consequences
2495 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002496 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 }
2498
Nathan Harolda939a962019-05-09 10:13:47 -07002499
2500 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002501 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2502
2503 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2504 }
2505
2506 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002508 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002513 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Shishir Agrawala9f32182016-04-12 12:00:16 -07002519 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002520 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002521 Phone phone = PhoneFactory.getPhone(slotIndex);
2522 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002523 return null;
2524 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002525 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002526 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002527 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 return null;
2529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 return phone.getImei();
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002537 }
2538
2539 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002540 public String getTypeAllocationCodeForSlot(int slotIndex) {
2541 Phone phone = PhoneFactory.getPhone(slotIndex);
2542 String tac = null;
2543 if (phone != null) {
2544 String imei = phone.getImei();
2545 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2546 }
2547 return tac;
2548 }
2549
2550 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002551 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002552 Phone phone = PhoneFactory.getPhone(slotIndex);
2553 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002554 return null;
2555 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002556
Jeff Davidson913390f2018-02-23 17:11:49 -08002557 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002558 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002559 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002560 return null;
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 return phone.getMeid();
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Jack Yu2af8d712017-03-15 17:14:14 -07002569 }
2570
2571 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002572 public String getManufacturerCodeForSlot(int slotIndex) {
2573 Phone phone = PhoneFactory.getPhone(slotIndex);
2574 String manufacturerCode = null;
2575 if (phone != null) {
2576 String meid = phone.getMeid();
2577 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2578 }
2579 return manufacturerCode;
2580 }
2581
2582 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002583 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2584 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002585 Phone phone = PhoneFactory.getPhone(slotIndex);
2586 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002587 return null;
2588 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 int subId = phone.getSubId();
2590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002591 mApp, subId, callingPackage, callingFeatureId,
2592 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002593 return null;
2594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 return phone.getDeviceSvn();
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
2601 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002602 }
2603
fionaxu43304da2017-11-27 22:51:16 -08002604 @Override
2605 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 final Phone phone = getPhone(subId);
2609 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
2612 }
fionaxu43304da2017-11-27 22:51:16 -08002613 }
2614
2615 @Override
2616 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 final Phone phone = getPhone(subId);
2620 return phone == null ? null : phone.getCarrierName();
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
fionaxu43304da2017-11-27 22:51:16 -08002624 }
2625
calvinpanffe225e2018-11-01 19:43:06 +08002626 @Override
chen xu0026ca62019-03-06 15:28:50 -08002627 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 final Phone phone = getPhone(subId);
2631 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002632 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
2636 }
2637
2638 @Override
chen xu0026ca62019-03-06 15:28:50 -08002639 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002643 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
2647 }
2648
chen xu651eec72018-11-11 19:03:44 -08002649 @Override
chen xu864e11c2018-12-06 22:10:03 -08002650 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2651 if (!isSubscriptionMccMnc) {
2652 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2653 }
chen xu651eec72018-11-11 19:03:44 -08002654 final Phone phone = PhoneFactory.getPhone(slotIndex);
2655 if (phone == null) {
2656 return TelephonyManager.UNKNOWN_CARRIER_ID;
2657 }
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
2664 }
2665
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 //
2667 // Internal helper methods.
2668 //
2669
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002670 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2672 *
2673 * @throws SecurityException if the caller does not have the required permission
2674 */
2675 private void enforceModifyPermission() {
2676 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2677 }
2678
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002679 /**
2680 * Make sure the caller is system.
2681 *
2682 * @throws SecurityException if the caller is not system.
2683 */
2684 private void enforceSystemCaller() {
2685 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2686 throw new SecurityException("Caller must be system");
2687 }
2688 }
2689
Shuo Qianf2b2df42019-11-13 17:43:31 -08002690 private void enforceActiveEmergencySessionPermission() {
2691 mApp.enforceCallingOrSelfPermission(
2692 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2693 }
2694
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 /**
2696 * Make sure the caller has the CALL_PHONE permission.
2697 *
2698 * @throws SecurityException if the caller does not have the required permission
2699 */
2700 private void enforceCallPermission() {
2701 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2702 }
2703
paulhu423b5f22019-08-23 19:17:33 +08002704 private void enforceSettingsPermission() {
2705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002706 }
2707
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 private String createTelUrl(String number) {
2709 if (TextUtils.isEmpty(number)) {
2710 return null;
2711 }
2712
Jake Hambye994d462014-02-03 13:10:13 -08002713 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
Ihab Awadf9e92732013-12-05 18:02:52 -08002716 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2718 }
2719
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 private static void logv(String msg) {
2721 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2722 }
2723
Ihab Awadf9e92732013-12-05 18:02:52 -08002724 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2726 }
2727
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002728 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002730 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002731 }
2732
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002734 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 final Phone phone = PhoneFactory.getPhone(slotIndex);
2738 if (phone == null) {
2739 return PhoneConstants.PHONE_TYPE_NONE;
2740 } else {
2741 return phone.getPhoneType();
2742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
2747
2748 /**
2749 * Returns the CDMA ERI icon index to display
2750 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002751 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002752 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2753 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2754 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002755 }
2756
Sanket Padawe356d7632015-06-22 14:03:32 -07002757 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002758 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2759 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002761 mApp, subId, callingPackage, callingFeatureId,
2762 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002763 return -1;
2764 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(subId);
2769 if (phone != null) {
2770 return phone.getCdmaEriIconIndex();
2771 } else {
2772 return -1;
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
2779 /**
2780 * Returns the CDMA ERI icon mode,
2781 * 0 - ON
2782 * 1 - FLASHING
2783 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002784 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002785 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2786 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2787 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002788 }
2789
Sanket Padawe356d7632015-06-22 14:03:32 -07002790 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002791 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2792 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002794 mApp, subId, callingPackage, callingFeatureId,
2795 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002796 return -1;
2797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
2803 return phone.getCdmaEriIconMode();
2804 } else {
2805 return -1;
2806 }
2807 } finally {
2808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 }
2811
2812 /**
2813 * Returns the CDMA ERI text,
2814 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002815 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002816 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2817 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2818 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002819 }
2820
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002822 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2823 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002825 mApp, subId, callingPackage, callingFeatureId,
2826 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002827 return null;
2828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 final Phone phone = getPhone(subId);
2833 if (phone != null) {
2834 return phone.getCdmaEriText();
2835 } else {
2836 return null;
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
2843 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002844 * Returns the CDMA MDN.
2845 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002847 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2849 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002854 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 return phone.getLine1Number();
2856 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 return null;
2859 }
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002862 }
2863 }
2864
2865 /**
2866 * Returns the CDMA MIN.
2867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002869 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2871 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 final Phone phone = getPhone(subId);
2876 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2877 return phone.getCdmaMin();
2878 } else {
2879 return null;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002883 }
2884 }
2885
Hall Liud892bec2018-11-30 14:51:45 -08002886 @Override
2887 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2888 INumberVerificationCallback callback, String callingPackage) {
2889 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2890 != PERMISSION_GRANTED) {
2891 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2892 }
2893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2894
2895 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2896 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2897 throw new SecurityException("Calling package must be configured in the device config");
2898 }
2899
2900 if (range == null) {
2901 throw new NullPointerException("Range must be non-null");
2902 }
2903
2904 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002905 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002906
2907 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2908 }
2909
Junda Liuca05d5d2014-08-14 22:36:34 -07002910 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 * Returns true if CDMA provisioning needs to run.
2912 */
2913 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 final long identity = Binder.clearCallingIdentity();
2915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002916 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
2922 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002923 * Sets the voice mail number of a given subId.
2924 */
2925 @Override
2926 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2928 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2933 new Pair<String, String>(alphaTag, number), new Integer(subId));
2934 return success;
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002938 }
2939
Ta-wei Yen87c49842016-05-13 21:19:52 -07002940 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002941 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002943 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2944 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002945 if (!TextUtils.equals(callingPackage, systemDialer)) {
2946 throw new SecurityException("caller must be system dialer");
2947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2952 if (phoneAccountHandle == null) {
2953 return null;
2954 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 } finally {
2957 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002958 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002959 }
2960
2961 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002962 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2963 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002964 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002966 mApp, subId, callingPackage, callingFeatureId,
2967 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002968 return null;
2969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002971 final long identity = Binder.clearCallingIdentity();
2972 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002973 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002974 } finally {
2975 Binder.restoreCallingIdentity(identity);
2976 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002977 }
2978
2979 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002980 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2981 VisualVoicemailSmsFilterSettings settings) {
2982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002991 }
2992
2993 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002994 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003000 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003004 }
3005
3006 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003007 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3008 String callingPackage, int subId) {
3009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003018 }
3019
3020 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003021 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003022 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003031 }
3032
3033 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003034 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3035 String callingAttributionTag, int subId, String number, int port, String text,
3036 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003038 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003039 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003040 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003041 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3042 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003043 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003044
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003045 /**
fionaxu0152e512016-11-14 13:36:14 -08003046 * Sets the voice activation state of a given subId.
3047 */
3048 @Override
3049 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3051 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052
3053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 final Phone phone = getPhone(subId);
3056 if (phone != null) {
3057 phone.setVoiceActivationState(activationState);
3058 } else {
3059 loge("setVoiceActivationState fails with invalid subId: " + subId);
3060 }
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003063 }
3064 }
3065
3066 /**
3067 * Sets the data activation state of a given subId.
3068 */
3069 @Override
3070 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3072 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 final Phone phone = getPhone(subId);
3077 if (phone != null) {
3078 phone.setDataActivationState(activationState);
3079 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003080 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081 }
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003084 }
3085 }
3086
3087 /**
3088 * Returns the voice activation state of a given subId.
3089 */
3090 @Override
3091 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003092 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093
fionaxu0152e512016-11-14 13:36:14 -08003094 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 if (phone != null) {
3098 return phone.getVoiceActivationState();
3099 } else {
3100 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3101 }
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003104 }
3105 }
3106
3107 /**
3108 * Returns the data activation state of a given subId.
3109 */
3110 @Override
3111 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113
fionaxu0152e512016-11-14 13:36:14 -08003114 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 if (phone != null) {
3118 return phone.getDataActivationState();
3119 } else {
3120 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3121 }
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003124 }
3125 }
3126
3127 /**
Wink Saville36469e72014-06-11 15:17:00 -07003128 * Returns the unread count of voicemails for a subId
3129 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003130 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003131 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3132 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003134 mApp, subId, callingPackage, callingFeatureId,
3135 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003136 return 0;
3137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 final Phone phone = getPhone(subId);
3141 if (phone != null) {
3142 return phone.getVoiceMessageCount();
3143 } else {
3144 return 0;
3145 }
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 }
3150
3151 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003152 * returns true, if the device is in a state where both voice and data
3153 * are supported simultaneously. This can change based on location or network condition.
3154 */
3155 @Override
3156 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 final Phone phone = getPhone(subId);
3160 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3161 } finally {
3162 Binder.restoreCallingIdentity(identity);
3163 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003164 }
3165
3166 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003167 * Send the dialer code if called from the current default dialer or the caller has
3168 * carrier privilege.
3169 * @param inputCode The dialer code to send
3170 */
3171 @Override
3172 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003174 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003175 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3176 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003177 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003178 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003179 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003184 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
fionaxu235cc5e2017-03-06 22:25:57 -08003188 }
3189
Pengquan Menga1bb6272018-09-06 09:59:22 -07003190 @Override
3191 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003192 TelephonyPermissions
3193 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3194 mApp, subId, "getNetworkSelectionMode");
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 if (!isActiveSubscription(subId)) {
3198 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3199 }
3200 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003203 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003204 }
3205
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003207 public boolean isInEmergencySmsMode() {
3208 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3209 final long identity = Binder.clearCallingIdentity();
3210 try {
3211 for (Phone phone : PhoneFactory.getPhones()) {
3212 if (phone.isInEmergencySmsMode()) {
3213 return true;
3214 }
3215 }
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 return false;
3220 }
3221
shilu366312e2019-12-17 09:28:10 -08003222 /**
3223 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3224 * @param subId The subscription to use to check the configuration.
3225 * @param c The callback that will be used to send the result.
3226 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003227 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003228 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3229 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003230 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3231 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003232
Brad Ebinger77b832e2019-10-17 17:03:22 -07003233 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3234 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3235 "IMS not available on device.");
3236 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 final long token = Binder.clearCallingIdentity();
3238 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003240 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 } catch (ImsException e) {
3243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 } finally {
3245 Binder.restoreCallingIdentity(token);
3246 }
3247 }
3248
shilu366312e2019-12-17 09:28:10 -08003249 /**
3250 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3251 * @param subId The subscription to use to check the configuration.
3252 * @param c The callback that will be used to send the result.
3253 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003255 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003256 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3257 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003258 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3259 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3260 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003261 final long token = Binder.clearCallingIdentity();
3262 try {
3263 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3264 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3265 .removeRegistrationCallbackForSubscription(c, subId);
3266 } catch (ImsException e) {
3267 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3268 + "is inactive, ignoring unregister.");
3269 // If the subscription is no longer active, just return, since the callback
3270 // will already have been removed internally.
3271 } finally {
3272 Binder.restoreCallingIdentity(token);
3273 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 }
3275
Brad Ebinger774ba362019-10-22 17:36:18 -07003276 /**
3277 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3278 */
3279 @Override
3280 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3281 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3282 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3283 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3284 "IMS not available on device.");
3285 }
3286 final long token = Binder.clearCallingIdentity();
3287 try {
3288 Phone phone = getPhone(subId);
3289 if (phone == null) {
3290 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3291 + subId + "'");
3292 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3293 }
3294 phone.getImsRegistrationState(regState -> {
3295 try {
3296 consumer.accept((regState == null)
3297 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3298 } catch (RemoteException e) {
3299 // Ignore if the remote process is no longer available to call back.
3300 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3301 }
3302 });
3303 } finally {
3304 Binder.restoreCallingIdentity(token);
3305 }
3306 }
3307
3308 /**
3309 * Get the transport type for the IMS service registration state.
3310 */
3311 @Override
3312 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003313 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3314 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003315 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3316 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3317 "IMS not available on device.");
3318 }
3319 final long token = Binder.clearCallingIdentity();
3320 try {
3321 Phone phone = getPhone(subId);
3322 if (phone == null) {
3323 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3324 + subId + "'");
3325 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3326 }
3327 phone.getImsRegistrationTech(regTech -> {
3328 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3329 int regTechConverted = (regTech == null)
3330 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3331 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3332 regTechConverted);
3333 try {
3334 consumer.accept(regTechConverted);
3335 } catch (RemoteException e) {
3336 // Ignore if the remote process is no longer available to call back.
3337 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3338 }
3339 });
3340 } finally {
3341 Binder.restoreCallingIdentity(token);
3342 }
3343 }
3344
shilu366312e2019-12-17 09:28:10 -08003345 /**
3346 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3347 * @param subId The subscription to use to check the configuration.
3348 * @param c The callback that will be used to send the result.
3349 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003351 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3352 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003353 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3354 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003355 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3356 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3357 "IMS not available on device.");
3358 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3360 final long token = Binder.clearCallingIdentity();
3361 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003364 } catch (ImsException e) {
3365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 } finally {
3367 Binder.restoreCallingIdentity(token);
3368 }
3369 }
3370
shilu366312e2019-12-17 09:28:10 -08003371 /**
3372 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3373 * @param subId The subscription to use to check the configuration.
3374 * @param c The callback that will be used to send the result.
3375 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003376 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003377 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003378 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3379 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003380 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3381 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3382 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003383
3384 final long token = Binder.clearCallingIdentity();
3385 try {
3386 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3387 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003388 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003389 } catch (ImsException e) {
3390 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3391 + "is inactive, ignoring unregister.");
3392 // If the subscription is no longer active, just return, since the callback
3393 // will already have been removed internally.
3394 } finally {
3395 Binder.restoreCallingIdentity(token);
3396 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 }
3398
3399 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003400 public boolean isCapable(int subId, int capability, int regTech) {
3401 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3403 final long token = Binder.clearCallingIdentity();
3404 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003405 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003407 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003408 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3409 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003410 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003411 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3412 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 } finally {
3414 Binder.restoreCallingIdentity(token);
3415 }
3416 }
3417
3418 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003419 public boolean isAvailable(int subId, int capability, int regTech) {
3420 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 final long token = Binder.clearCallingIdentity();
3422 try {
3423 Phone phone = getPhone(subId);
3424 if (phone == null) return false;
3425 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003426 } catch (com.android.ims.ImsException e) {
3427 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3428 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 } finally {
3430 Binder.restoreCallingIdentity(token);
3431 }
3432 }
3433
Brad Ebinger77b832e2019-10-17 17:03:22 -07003434 /**
3435 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3436 * subscription.
3437 * @param subId The subscription to use to check the configuration.
3438 * @param callback The callback that will be used to send the result.
3439 * @param capability The MmTelFeature capability that will be used to send the result.
3440 * @param transportType The transport type of the MmTelFeature capability.
3441 */
3442 @Override
3443 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3444 int transportType) {
3445 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3446 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3447 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3448 "IMS not available on device.");
3449 }
3450 final long token = Binder.clearCallingIdentity();
3451 try {
3452 int slotId = getSlotIndex(subId);
3453 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3454 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3455 + subId + "'");
3456 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3457 }
3458 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3459 transportType, aBoolean -> {
3460 try {
3461 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3462 } catch (RemoteException e) {
3463 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3464 + "running. Ignore");
3465 }
3466 });
3467 } finally {
3468 Binder.restoreCallingIdentity(token);
3469 }
3470 }
3471
shilu366312e2019-12-17 09:28:10 -08003472 /**
3473 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3474 * @param subId The subscription to use to check the configuration.
3475 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 @Override
3477 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003478 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3479 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003480
Brad Ebinger35c841c2018-10-01 10:40:55 -07003481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3482 final long token = Binder.clearCallingIdentity();
3483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003484 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003485 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003486 } catch (ImsException e) {
3487 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003488 } finally {
3489 Binder.restoreCallingIdentity(token);
3490 }
3491 }
3492
3493 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003494 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003496 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003500 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003502 } catch (ImsException e) {
3503 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 } finally {
3505 Binder.restoreCallingIdentity(identity);
3506 }
3507 }
3508
shilu366312e2019-12-17 09:28:10 -08003509 /**
3510 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3511 * @param subId The subscription to use to check the configuration.
3512 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003514 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003515 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3516 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003520 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3521 } catch (ImsException e) {
3522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
3526 }
3527
3528 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003529 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003531 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003536 } catch (ImsException e) {
3537 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
3541 }
3542
shilu366312e2019-12-17 09:28:10 -08003543 /**
3544 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3545 * @param subId The subscription to use to check the configuration.
3546 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 @Override
3548 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003549 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3550 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003554 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003556 } catch (ImsException e) {
3557 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
3561 }
3562
3563 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003564 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003566 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003571 } catch (ImsException e) {
3572 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
shilu366312e2019-12-17 09:28:10 -08003578 /**
3579 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3580 * @param subId The subscription to use to check the configuration.
3581 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 @Override
3583 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003584 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3585 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003589 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003591 } catch (ImsException e) {
3592 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
3598 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003599 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003601 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003607 } catch (ImsException e) {
3608 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 } finally {
3610 Binder.restoreCallingIdentity(identity);
3611 }
3612 }
3613
3614 @Override
3615 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3617 "setVoWiFiNonPersistent");
3618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003621 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003622 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003623 } catch (ImsException e) {
3624 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
3628 }
3629
shilu366312e2019-12-17 09:28:10 -08003630 /**
3631 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3632 * @param subId The subscription to use to check the configuration.
3633 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 @Override
3635 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003636 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3637 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003641 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003643 } catch (ImsException e) {
3644 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
3648 }
3649
3650 @Override
3651 public void setVoWiFiModeSetting(int subId, int mode) {
3652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3653 "setVoWiFiModeSetting");
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003659 } catch (ImsException e) {
3660 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
3664 }
3665
3666 @Override
3667 public int getVoWiFiRoamingModeSetting(int subId) {
3668 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003674 } catch (ImsException e) {
3675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
3679 }
3680
3681 @Override
3682 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3684 "setVoWiFiRoamingModeSetting");
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003690 } catch (ImsException e) {
3691 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
3697 @Override
3698 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3700 "setRttCapabilityEnabled");
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003704 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3705 } catch (ImsException e) {
3706 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
3710 }
3711
shilu366312e2019-12-17 09:28:10 -08003712 /**
3713 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3714 * @param subId The subscription to use to check the configuration.
3715 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 @Override
3717 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003718 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3719 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003732 @Override
3733 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3734 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003737 if (!isImsAvailableOnDevice()) {
3738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3739 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003740 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003743 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003744 } catch (ImsException e) {
3745 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
3749 }
3750
3751 @Override
3752 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3753 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3754 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003755 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3756 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3757 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003758 try {
3759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003761 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003763 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3764 + "is inactive, ignoring unregister.");
3765 // If the subscription is no longer active, just return, since the callback will already
3766 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
3770 }
3771
allenwtsu99c623b2020-01-03 18:24:23 +08003772
3773 private void checkModifyPhoneStatePermission(int subId, String message) {
3774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3775 message);
3776 }
3777
3778 private boolean isImsProvisioningRequired(int subId, int capability,
3779 boolean isMmtelCapability) {
3780 Phone phone = getPhone(subId);
3781 if (phone == null) {
3782 loge("phone instance null for subid " + subId);
3783 return false;
3784 }
3785 if (isMmtelCapability) {
3786 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3787 return false;
3788 }
3789 } else {
3790 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3791 return false;
3792 }
3793 }
3794 return true;
3795 }
3796
3797 @Override
3798 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3799 boolean isProvisioned) {
3800 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3801
3802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3805 if (!isImsProvisioningRequired(subId, capability, false)) {
3806 return;
3807 }
3808
3809 // this capability requires provisioning, route to the correct API.
3810 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3811 switch (capability) {
3812 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3813 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3814 ims.setEabProvisioned(isProvisioned);
3815 break;
3816 default: {
3817 throw new IllegalArgumentException("Tried to set provisioning for "
3818 + "rcs capability '" + capability + "', which does not require "
3819 + "provisioning.");
3820 }
3821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
3825
3826 }
3827
3828
3829 @Override
3830 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3831 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3835 if (!isImsProvisioningRequired(subId, capability, false)) {
3836 return true;
3837 }
3838
3839 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3840 switch (capability) {
3841 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3842 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3843 return ims.isEabProvisionedOnDevice();
3844
3845 default: {
3846 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3847 + "capability '" + capability + "', which does not require "
3848 + "provisioning.");
3849 }
3850 }
3851
3852 } finally {
3853 Binder.restoreCallingIdentity(identity);
3854 }
3855 }
3856
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003857 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003858 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3859 boolean isProvisioned) {
3860 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3861 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3862 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3863 }
allenwtsu99c623b2020-01-03 18:24:23 +08003864 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003868 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003869 return;
3870 }
3871
3872 // this capability requires provisioning, route to the correct API.
3873 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3874 switch (capability) {
3875 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3876 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3877 ims.setVolteProvisioned(isProvisioned);
3878 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3879 ims.setWfcProvisioned(isProvisioned);
3880 }
3881 break;
3882 }
3883 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3884 // There is currently no difference in VT provisioning type.
3885 ims.setVtProvisioned(isProvisioned);
3886 break;
3887 }
3888 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3889 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3890 // change the capability of the feature instead if needed.
3891 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3892 == isProvisioned) {
3893 // No change in provisioning.
3894 return;
3895 }
3896 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3897 try {
3898 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003899 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003900 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3901 + ", Exception" + e.getMessage());
3902 }
3903 break;
3904 }
3905 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003906 throw new IllegalArgumentException("Tried to set provisioning for "
3907 + "MmTel capability '" + capability + "', which does not require "
3908 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003909 }
3910 }
3911
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
3915 }
3916
3917 @Override
3918 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3919 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3920 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3921 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3922 }
3923 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003927 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003928 return true;
3929 }
3930
3931 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3932 switch (capability) {
3933 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3934 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3935 return ims.isVolteProvisionedOnDevice();
3936 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3937 return ims.isWfcProvisionedOnDevice();
3938 }
3939 // This should never happen, since we are checking tech above to make sure it
3940 // is either LTE or IWLAN.
3941 throw new IllegalArgumentException("Invalid radio technology for voice "
3942 + "capability.");
3943 }
3944 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3945 // There is currently no difference in VT provisioning type.
3946 return ims.isVtProvisionedOnDevice();
3947 }
3948 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3949 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3950 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3951 }
3952 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003953 throw new IllegalArgumentException(
3954 "Tried to get provisioning for MmTel capability '" + capability
3955 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003956 }
3957 }
3958
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
3962 }
3963
3964 @Override
3965 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3966 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3967 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3968 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3969 }
3970 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3971 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3972 return (provisionedBits & capability) > 0;
3973 }
3974
3975 @Override
3976 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3977 boolean isProvisioned) {
3978 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3979 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3980 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3981 }
3982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3983 "setProvisioningStatusForCapability");
3984 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3985 // If the current provisioning status for capability already matches isProvisioned,
3986 // do nothing.
3987 if (((provisionedBits & capability) > 0) == isProvisioned) {
3988 return;
3989 }
3990 if (isProvisioned) {
3991 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3992 } else {
3993 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3994 }
3995 }
3996
3997 /**
3998 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3999 * technology. The bitfield should mirror the bitfield defined by
4000 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4001 */
4002 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4003 String key = getMmTelProvisioningKey(subId, tech);
4004 // Default is no capabilities are provisioned.
4005 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4006 }
4007
4008 /**
4009 * Sets the MmTel capability provisioning bitfield (defined by
4010 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4011 * technology specified.
4012 *
4013 * Note: This is a synchronous command and should not be called on UI thread.
4014 */
4015 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4016 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4017 String key = getMmTelProvisioningKey(subId, tech);
4018 editor.putInt(key, newField);
4019 editor.commit();
4020 }
4021
4022 private static String getMmTelProvisioningKey(int subId, int tech) {
4023 // resulting key is provision_ims_mmtel_{subId}_{tech}
4024 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4025 }
4026
4027 /**
4028 * Query CarrierConfig to see if the specified capability requires provisioning for the
4029 * carrier associated with the subscription id.
4030 */
4031 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4032 int capability) {
4033 CarrierConfigManager configManager = new CarrierConfigManager(context);
4034 PersistableBundle c = configManager.getConfigForSubId(subId);
4035 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004036 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004037 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4038 false);
4039 boolean requireVoiceVtProvisioning = c.getBoolean(
4040 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4041
4042 // First check to make sure that the capability requires provisioning.
4043 switch (capability) {
4044 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4045 // intentional fallthrough
4046 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4047 if (requireVoiceVtProvisioning) {
4048 // Voice and Video requires provisioning
4049 return true;
4050 }
4051 break;
4052 }
4053 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4054 if (requireUtProvisioning) {
4055 // UT requires provisioning
4056 return true;
4057 }
4058 break;
4059 }
4060 }
4061 return false;
4062 }
4063
allenwtsu99c623b2020-01-03 18:24:23 +08004064 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4065 int capability) {
4066 CarrierConfigManager configManager = new CarrierConfigManager(context);
4067 PersistableBundle c = configManager.getConfigForSubId(subId);
4068
4069 boolean requireRcsProvisioning = c.getBoolean(
4070 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4071
4072 // First check to make sure that the capability requires provisioning.
4073 switch (capability) {
4074 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4075 // intentional fallthrough
4076 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4077 if (requireRcsProvisioning) {
4078 // OPTION or PRESENCE requires provisioning
4079 return true;
4080 }
4081 break;
4082 }
4083 }
4084 return false;
4085 }
4086
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004087 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004088 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004089 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4090 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4091 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004092 enforceReadPrivilegedPermission("getImsProvisioningInt");
4093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004096 int slotId = getSlotIndex(subId);
4097 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4098 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4099 + subId + "' for key:" + key);
4100 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4101 }
4102 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004103 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004104 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4105 + subId + "' for key:" + key);
4106 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004107 } finally {
4108 Binder.restoreCallingIdentity(identity);
4109 }
4110 }
4111
4112 @Override
4113 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4115 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4116 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004117 enforceReadPrivilegedPermission("getImsProvisioningString");
4118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004121 int slotId = getSlotIndex(subId);
4122 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4123 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4124 + subId + "' for key:" + key);
4125 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4126 }
4127 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004129 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4130 + subId + "' for key:" + key);
4131 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
4135 }
4136
4137 @Override
4138 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004139 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4140 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4141 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4143 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004147 int slotId = getSlotIndex(subId);
4148 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4149 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4150 + subId + "' for key:" + key);
4151 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4152 }
4153 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004154 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004155 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4156 + "' for key:" + key);
4157 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 }
4162
4163 @Override
4164 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004165 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4166 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4167 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4169 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004170 final long identity = Binder.clearCallingIdentity();
4171 try {
4172 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004173 int slotId = getSlotIndex(subId);
4174 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4175 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4176 + subId + "' for key:" + key);
4177 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4178 }
4179 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004180 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004181 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4182 + "' for key:" + key);
4183 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
4187 }
4188
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004189 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 int slotId = SubscriptionManager.getSlotIndex(subId);
4191 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004192 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4193 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 }
4195 return slotId;
4196 }
4197
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004198 private int getSlotIndex(int subId) {
4199 int slotId = SubscriptionManager.getSlotIndex(subId);
4200 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4201 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4202 }
4203 return slotId;
4204 }
4205
Wink Saville36469e72014-06-11 15:17:00 -07004206 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004207 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004208 */
4209 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004210 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4211 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004212 final int targetSdk = getTargetSdk(callingPackage);
4213 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004214 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004215 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004216 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004217 mApp, subId, callingPackage, callingFeatureId,
4218 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004219 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4220 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222 final long identity = Binder.clearCallingIdentity();
4223 try {
4224 final Phone phone = getPhone(subId);
4225 if (phone != null) {
4226 return phone.getServiceState().getDataNetworkType();
4227 } else {
4228 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4229 }
4230 } finally {
4231 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004233 }
4234
4235 /**
4236 * Returns the data network type
4237 */
4238 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004239 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4240 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4241 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004242 }
4243
4244 /**
4245 * Returns the data network type for a subId
4246 */
4247 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004248 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4249 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004251 mApp, subId, callingPackage, callingFeatureId,
4252 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004253 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4254 }
4255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 final long identity = Binder.clearCallingIdentity();
4257 try {
4258 final Phone phone = getPhone(subId);
4259 if (phone != null) {
4260 return phone.getServiceState().getDataNetworkType();
4261 } else {
4262 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4263 }
4264 } finally {
4265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004267 }
4268
4269 /**
Wink Saville36469e72014-06-11 15:17:00 -07004270 * Returns the Voice network type for a subId
4271 */
4272 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004273 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4274 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004276 mApp, subId, callingPackage, callingFeatureId,
4277 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004278 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4279 }
4280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 final Phone phone = getPhone(subId);
4284 if (phone != null) {
4285 return phone.getServiceState().getVoiceNetworkType();
4286 } else {
4287 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4288 }
4289 } finally {
4290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004292 }
4293
4294 /**
4295 * @return true if a ICC card is present
4296 */
4297 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004298 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004299 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4300 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004301 }
4302
4303 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004304 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004305 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004306 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004307 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 final Phone phone = PhoneFactory.getPhone(slotIndex);
4311 if (phone != null) {
4312 return phone.getIccCard().hasIccCard();
4313 } else {
4314 return false;
4315 }
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004319 }
4320
4321 /**
4322 * Return if the current radio is LTE on CDMA. This
4323 * is a tri-state return value as for a period of time
4324 * the mode may be unknown.
4325 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004326 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004327 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004328 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004329 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004330 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004331 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4332 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4333 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004334 }
4335
Sanket Padawe356d7632015-06-22 14:03:32 -07004336 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004337 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4338 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004339 try {
4340 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4341 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004342 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4343 }
4344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 final Phone phone = getPhone(subId);
4348 if (phone == null) {
4349 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4350 } else {
4351 return phone.getLteOnCdmaMode();
4352 }
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004355 }
Wink Saville36469e72014-06-11 15:17:00 -07004356 }
4357
Wink Saville36469e72014-06-11 15:17:00 -07004358 /**
4359 * {@hide}
4360 * Returns Default subId, 0 in the case of single standby.
4361 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004362 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004363 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004364 }
4365
Shishir Agrawala9f32182016-04-12 12:00:16 -07004366 private int getSlotForDefaultSubscription() {
4367 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4368 }
4369
Wink Savilleb564aae2014-10-23 10:18:09 -07004370 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004371 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004372 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004373
Pengquan Menge92a50d2018-09-21 15:54:48 -07004374 private boolean isActiveSubscription(int subId) {
4375 return mSubscriptionController.isActiveSubId(subId);
4376 }
4377
Ihab Awadf2177b72013-11-25 13:33:23 -08004378 /**
4379 * @see android.telephony.TelephonyManager.WifiCallingChoices
4380 */
4381 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 final long identity = Binder.clearCallingIdentity();
4383 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004384 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4386 getWhenToMakeWifiCallsDefaultPreference());
4387 } finally {
4388 Binder.restoreCallingIdentity(identity);
4389 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004390 }
4391
4392 /**
4393 * @see android.telephony.TelephonyManager.WifiCallingChoices
4394 */
4395 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004399 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004404 }
4405
Sailesh Nepald1e68152013-12-12 19:08:02 -08004406 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004407 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004408 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004409 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004410
Jordan Liu4c733742019-02-28 12:03:40 -08004411 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4412 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4413 if (phoneId == -1) {
4414 throw new IllegalArgumentException("Given slot index: " + slotIndex
4415 + " does not correspond to an active phone");
4416 }
4417 return PhoneFactory.getPhone(phoneId);
4418 }
4419
Shishir Agrawal566b7612013-10-28 14:41:00 -07004420 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004421 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4422 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4424 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004426 if (DBG) {
4427 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4428 }
4429 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4430 p2);
4431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004432
Jordan Liu4c733742019-02-28 12:03:40 -08004433
4434 @Override
4435 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4436 int slotIndex, String callingPackage, String aid, int p2) {
4437 enforceModifyPermission();
4438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4439 if (DBG) {
4440 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4441 }
4442 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4443 callingPackage, aid, p2);
4444 }
4445
4446 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4447 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 if (TextUtils.equals(ISDR_AID, aid)) {
4451 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004452 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4453 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454 if (bestComponent == null
4455 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4456 loge("The calling package is not allowed to access ISD-R.");
4457 throw new SecurityException(
4458 "The calling package is not allowed to access ISD-R.");
4459 }
Derek Tan740e1672017-06-27 14:56:27 -07004460 }
Derek Tan740e1672017-06-27 14:56:27 -07004461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004463 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4464 null /* workSource */);
4465 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 return response;
4467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004470 }
4471
4472 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004473 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4475 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004476 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4477 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4478 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004479
Jordan Liu4c733742019-02-28 12:03:40 -08004480 @Override
4481 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4482 enforceModifyPermission();
4483 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4484 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4485 channel);
4486 }
4487
4488 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489 final long identity = Binder.clearCallingIdentity();
4490 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 if (channel < 0) {
4492 return false;
4493 }
Jordan Liu4c733742019-02-28 12:03:40 -08004494 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4495 null /* workSource */);
4496 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 return success;
4498 } finally {
4499 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004500 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004501 }
4502
4503 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004504 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004505 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4507 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004508 if (DBG) {
4509 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4510 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4511 + p3 + " data=" + data);
4512 }
4513 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4514 command, p1, p2, p3, data);
4515 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004516
Jordan Liu4c733742019-02-28 12:03:40 -08004517 @Override
4518 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4519 int command, int p1, int p2, int p3, String data) {
4520 enforceModifyPermission();
4521 if (DBG) {
4522 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4523 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4524 + p3 + " data=" + data);
4525 }
4526 return iccTransmitApduLogicalChannelWithPermission(
4527 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4528 data);
4529 }
4530
4531 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4532 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004535 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536 return "";
4537 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004540 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4541 null /* workSource */);
4542 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544 // Append the returned status code to the end of the response payload.
4545 String s = Integer.toHexString(
4546 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4547 if (response.payload != null) {
4548 s = IccUtils.bytesToHexString(response.payload) + s;
4549 }
4550 return s;
4551 } finally {
4552 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004553 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004554 }
Jake Hambye994d462014-02-03 13:10:13 -08004555
Evan Charltonc66da362014-05-16 14:06:40 -07004556 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004557 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4558 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4560 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004562 if (DBG) {
4563 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4564 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4565 }
4566 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4567 cla, command, p1, p2, p3, data);
4568 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004569
Jordan Liu4c733742019-02-28 12:03:40 -08004570 @Override
4571 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4572 int command, int p1, int p2, int p3, String data) {
4573 enforceModifyPermission();
4574 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4575 if (DBG) {
4576 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4577 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4578 + " data=" + data);
4579 }
4580
4581 return iccTransmitApduBasicChannelWithPermission(
4582 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4583 p2, p3, data);
4584 }
4585
4586 // open APDU basic channel assuming the caller has sufficient permissions
4587 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4588 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
4590 try {
4591 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4592 && TextUtils.equals(ISDR_AID, data)) {
4593 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004594 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4595 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 if (bestComponent == null
4597 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4598 loge("The calling package is not allowed to select ISD-R.");
4599 throw new SecurityException(
4600 "The calling package is not allowed to select ISD-R.");
4601 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004602 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004605 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4606 null /* workSource */);
4607 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 // Append the returned status code to the end of the response payload.
4610 String s = Integer.toHexString(
4611 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4612 if (response.payload != null) {
4613 s = IccUtils.bytesToHexString(response.payload) + s;
4614 }
4615 return s;
4616 } finally {
4617 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004618 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004619 }
4620
4621 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004622 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004623 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4625 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 final long identity = Binder.clearCallingIdentity();
4628 try {
4629 if (DBG) {
4630 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4631 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4632 }
4633
4634 IccIoResult response =
4635 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4636 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4637 subId);
4638
4639 if (DBG) {
4640 log("Exchange SIM_IO [R]" + response);
4641 }
4642
4643 byte[] result = null;
4644 int length = 2;
4645 if (response.payload != null) {
4646 length = 2 + response.payload.length;
4647 result = new byte[length];
4648 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4649 } else {
4650 result = new byte[length];
4651 }
4652
4653 result[length - 1] = (byte) response.sw2;
4654 result[length - 2] = (byte) response.sw1;
4655 return result;
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004658 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004659 }
4660
Nathan Haroldb3014052017-01-25 15:57:32 -08004661 /**
4662 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4663 * on a particular subscription
4664 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004665 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4666 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004668 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004669 return null;
4670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671
4672 final long identity = Binder.clearCallingIdentity();
4673 try {
4674 if (appType != TelephonyManager.APPTYPE_USIM
4675 && appType != TelephonyManager.APPTYPE_SIM) {
4676 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4677 return null;
4678 }
4679 Object response = sendRequest(
4680 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4681 if (response instanceof String[]) {
4682 return (String[]) response;
4683 }
yincheng zhaod698b842019-09-06 17:06:54 -07004684 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004686 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687 } finally {
4688 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004689 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004690 }
4691
yincheng zhaod698b842019-09-06 17:06:54 -07004692 /**
4693 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4694 * subscription.
4695 *
4696 * @param subId the id of the subscription.
4697 * @param appType the uicc app type, must be USIM or SIM.
4698 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4699 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004700 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004701 * @return number of fplmns that is successfully written to the SIM.
4702 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004703 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4704 String callingFeatureId) {
4705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4706 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004707 if (DBG) logv("no permissions for setForbiddenplmns");
4708 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4709 }
4710 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4711 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4712 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4713 }
4714 if (fplmns == null) {
4715 throw new IllegalArgumentException("Fplmn List provided is null");
4716 }
4717 for (String fplmn : fplmns) {
4718 if (!CellIdentity.isValidPlmn(fplmn)) {
4719 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4720 }
4721 }
4722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 Object response = sendRequest(
4725 CMD_SET_FORBIDDEN_PLMNS,
4726 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4727 subId);
4728 return (int) response;
4729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
4732 }
4733
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004734 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004735 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4737 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4742 if (response.payload == null) {
4743 return "";
4744 }
Evan Charltonc66da362014-05-16 14:06:40 -07004745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 // Append the returned status code to the end of the response payload.
4747 String s = Integer.toHexString(
4748 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4749 s = IccUtils.bytesToHexString(response.payload) + s;
4750 return s;
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
4753 }
Evan Charltonc66da362014-05-16 14:06:40 -07004754 }
4755
Jake Hambye994d462014-02-03 13:10:13 -08004756 /**
4757 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4758 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4759 *
4760 * @param itemID the ID of the item to read
4761 * @return the NV item as a String, or null on error.
4762 */
4763 @Override
4764 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004765 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4767 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004768
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004772 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4774 return value;
4775 } finally {
4776 Binder.restoreCallingIdentity(identity);
4777 }
Jake Hambye994d462014-02-03 13:10:13 -08004778 }
4779
4780 /**
4781 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4782 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4783 *
4784 * @param itemID the ID of the item to read
4785 * @param itemValue the value to write, as a String
4786 * @return true on success; false on any failure
4787 */
4788 @Override
4789 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004790 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4792 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793
4794 final long identity = Binder.clearCallingIdentity();
4795 try {
4796 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4797 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004798 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4800 return success;
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
Jake Hambye994d462014-02-03 13:10:13 -08004804 }
4805
4806 /**
4807 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4808 * Used for device configuration by some CDMA operators.
4809 *
4810 * @param preferredRoamingList byte array containing the new PRL
4811 * @return true on success; false on any failure
4812 */
4813 @Override
4814 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4816 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817
4818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4821 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4822 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4823 return success;
4824 } finally {
4825 Binder.restoreCallingIdentity(identity);
4826 }
Jake Hambye994d462014-02-03 13:10:13 -08004827 }
4828
4829 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004830 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004831 * Used for device configuration by some CDMA operators.
4832 *
chen xu6dac5ab2018-10-26 17:39:23 -07004833 * @param slotIndex - device slot.
4834 *
Jake Hambye994d462014-02-03 13:10:13 -08004835 * @return true on success; false on any failure
4836 */
4837 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004838 public boolean resetModemConfig(int slotIndex) {
4839 Phone phone = PhoneFactory.getPhone(slotIndex);
4840 if (phone != null) {
4841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4842 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004843
chen xu6dac5ab2018-10-26 17:39:23 -07004844 final long identity = Binder.clearCallingIdentity();
4845 try {
4846 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4847 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4848 return success;
4849 } finally {
4850 Binder.restoreCallingIdentity(identity);
4851 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 }
chen xu6dac5ab2018-10-26 17:39:23 -07004853 return false;
4854 }
4855
4856 /**
4857 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4858 *
4859 * @param slotIndex - device slot.
4860 *
4861 * @return true on success; false on any failure
4862 */
4863 @Override
4864 public boolean rebootModem(int slotIndex) {
4865 Phone phone = PhoneFactory.getPhone(slotIndex);
4866 if (phone != null) {
4867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4868 mApp, phone.getSubId(), "rebootModem");
4869
4870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4873 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4874 return success;
4875 } finally {
4876 Binder.restoreCallingIdentity(identity);
4877 }
4878 }
4879 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004880 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004881
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004882 public String[] getPcscfAddress(String apnType, String callingPackage,
4883 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004884 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4886 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004887 return new String[0];
4888 }
4889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 final long identity = Binder.clearCallingIdentity();
4891 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004892 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
Wink Saville36469e72014-06-11 15:17:00 -07004896 }
4897
Brad Ebinger51f743a2017-01-23 13:50:20 -08004898 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004899 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4900 * {@link #disableIms(int)}.
4901 * @param slotIndex device slot.
4902 */
4903 public void resetIms(int slotIndex) {
4904 enforceModifyPermission();
4905
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 if (mImsResolver == null) {
4909 // may happen if the does not support IMS.
4910 return;
4911 }
4912 mImsResolver.disableIms(slotIndex);
4913 mImsResolver.enableIms(slotIndex);
4914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
4917 }
4918
4919 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004920 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4921 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004922 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004923 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004924 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004928 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004929 // may happen if the device does not support IMS.
4930 return;
4931 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004932 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004936 }
4937
4938 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004939 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4940 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004941 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004942 public void disableIms(int slotId) {
4943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944
4945 final long identity = Binder.clearCallingIdentity();
4946 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004947 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004948 // may happen if the device does not support IMS.
4949 return;
4950 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004951 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004955 }
4956
4957 /**
4958 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4959 * feature or {@link null} if the service is not available. If the feature is available, the
4960 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4961 */
4962 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004963 IImsServiceFeatureCallback callback) {
4964 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965
4966 final long identity = Binder.clearCallingIdentity();
4967 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004968 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004969 // may happen if the device does not support IMS.
4970 return null;
4971 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004972 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004976 }
4977
4978 /**
4979 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4980 * feature during emergency calling or {@link null} if the service is not available. If the
4981 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4982 * listener for feature updates.
4983 */
4984 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986
4987 final long identity = Binder.clearCallingIdentity();
4988 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004989 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004990 // may happen if the device does not support IMS.
4991 return null;
4992 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004993 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004997 }
4998
Brad Ebinger5f64b052017-12-14 14:26:15 -08004999 /**
5000 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005001 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005002 */
5003 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005
5006 final long identity = Binder.clearCallingIdentity();
5007 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005008 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005009 // may happen if the device does not support IMS.
5010 return null;
5011 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005012 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005016 }
5017
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005018 /**
5019 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005020 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005021 */
5022 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005027 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005028 // may happen if the device does not support IMS.
5029 return null;
5030 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005031 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 } finally {
5033 Binder.restoreCallingIdentity(identity);
5034 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005035 }
5036
Brad Ebinger884c07b2018-02-15 16:17:40 -08005037 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005038 * Sets the ImsService Package Name that Telephony will bind to.
5039 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005040 * @param slotIndex the slot ID that the ImsService should bind for.
5041 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005042 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005043 * @param featureTypes An integer array of feature types associated with a packageName.
5044 * @param packageName The name of the package that the current configuration will be replaced
5045 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005046 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005047 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005048 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5049 int[] featureTypes, String packageName) {
5050 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5053 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005054 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005058 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005059 // may happen if the device does not support IMS.
5060 return false;
5061 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005062 Map<Integer, String> featureConfig = new HashMap<>();
5063 for (int featureType : featureTypes) {
5064 featureConfig.put(featureType, packageName);
5065 }
5066 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5067 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 } finally {
5069 Binder.restoreCallingIdentity(identity);
5070 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005071 }
5072
5073 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005074 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005075 *
5076 * @param slotId The slot that the ImsService is associated with.
5077 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5078 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005079 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005080 * @return the package name of the ImsService configuration.
5081 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005082 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5083 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005084 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005085 TelephonyPermissions
5086 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5087 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5088 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005092 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005093 // may happen if the device does not support IMS.
5094 return "";
5095 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005096 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005097 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5098 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 } finally {
5100 Binder.restoreCallingIdentity(identity);
5101 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005102 }
5103
Brad Ebinger77b832e2019-10-17 17:03:22 -07005104 /**
5105 * Get the MmTelFeature state associated with the requested subscription id.
5106 * @param subId The subscription that the MmTelFeature is associated with.
5107 * @param callback A callback with an integer containing the
5108 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5109 */
5110 @Override
5111 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5112 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5113 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5114 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5115 "IMS not available on device.");
5116 }
5117 final long token = Binder.clearCallingIdentity();
5118 try {
5119 int slotId = getSlotIndex(subId);
5120 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5121 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5122 + subId + "'");
5123 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5124 }
5125 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5126 try {
5127 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5128 } catch (RemoteException e) {
5129 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5130 + "Ignore");
5131 }
5132 });
5133 } finally {
5134 Binder.restoreCallingIdentity(token);
5135 }
5136 }
5137
Wink Saville36469e72014-06-11 15:17:00 -07005138 public void setImsRegistrationState(boolean registered) {
5139 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140
5141 final long identity = Binder.clearCallingIdentity();
5142 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005143 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Wink Saville36469e72014-06-11 15:17:00 -07005147 }
5148
5149 /**
Stuart Scott54788802015-03-30 13:18:01 -07005150 * Set the network selection mode to automatic.
5151 *
5152 */
5153 @Override
5154 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5156 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157
5158 final long identity = Binder.clearCallingIdentity();
5159 try {
shilufc958392020-01-20 11:36:01 -08005160 if (!isActiveSubscription(subId)) {
5161 return;
5162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5164 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
Stuart Scott54788802015-03-30 13:18:01 -07005168 }
5169
Pengquan Mengea84e042018-09-20 14:57:26 -07005170 /**
5171 * Ask the radio to connect to the input network and change selection mode to manual.
5172 *
5173 * @param subId the id of the subscription.
5174 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5175 * the operator to attach to.
5176 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5177 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5178 * normal network selection next time.
5179 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005180 */
5181 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005182 public boolean setNetworkSelectionModeManual(
5183 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5185 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005186
5187 if (!isActiveSubscription(subId)) {
5188 return false;
5189 }
5190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 final long identity = Binder.clearCallingIdentity();
5192 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005193 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005195 if (DBG) {
5196 log("setNetworkSelectionModeManual: subId: " + subId
5197 + " operator: " + operatorInfo);
5198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005203 }
5204
5205 /**
5206 * Scans for available networks.
5207 */
5208 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005209 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5210 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5212 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005213 LocationAccessPolicy.LocationPermissionResult locationResult =
5214 LocationAccessPolicy.checkLocationPermission(mApp,
5215 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5216 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005217 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005218 .setCallingPid(Binder.getCallingPid())
5219 .setCallingUid(Binder.getCallingUid())
5220 .setMethod("getCellNetworkScanResults")
5221 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5222 .build());
5223 switch (locationResult) {
5224 case DENIED_HARD:
5225 throw new SecurityException("Not allowed to access scan results -- location");
5226 case DENIED_SOFT:
5227 return null;
5228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229
Pengquan Menga1bb6272018-09-06 09:59:22 -07005230 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 try {
5232 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005233 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005238 }
5239
5240 /**
sqian80370722020-01-29 15:02:51 -08005241 * Get the call forwarding info, given the call forwarding reason.
5242 */
5243 @Override
5244 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5245 enforceReadPrivilegedPermission("getCallForwarding");
5246 long identity = Binder.clearCallingIdentity();
5247 try {
5248 if (DBG) {
5249 log("getCallForwarding: subId " + subId
5250 + " callForwardingReason" + callForwardingReason);
5251 }
5252 return (CallForwardingInfo) sendRequest(
5253 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
5257 }
5258
5259 /**
5260 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5261 * reason, the number to forward, and the timeout before the forwarding is attempted.
5262 */
5263 @Override
5264 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5265 enforceModifyPermission();
5266 long identity = Binder.clearCallingIdentity();
5267 try {
5268 if (DBG) {
5269 log("setCallForwarding: subId " + subId
5270 + " callForwardingInfo" + callForwardingInfo);
5271 }
5272 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
5276 }
5277
5278 /**
5279 * Get the call forwarding info, given the call forwarding reason.
5280 */
5281 @Override
5282 public int getCallWaitingStatus(int subId) {
5283 enforceReadPrivilegedPermission("getCallForwarding");
5284 long identity = Binder.clearCallingIdentity();
5285 try {
5286 if (DBG) log("getCallWaitingStatus: subId " + subId);
5287 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
5290 }
5291 }
5292
5293 /**
5294 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5295 * reason, the number to forward, and the timeout before the forwarding is attempted.
5296 */
5297 @Override
5298 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5299 enforceModifyPermission();
5300 long identity = Binder.clearCallingIdentity();
5301 try {
5302 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5303 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
5307 }
5308
5309 /**
yinxub1bed742017-04-17 11:45:04 -07005310 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005311 *
yinxub1bed742017-04-17 11:45:04 -07005312 * @param subId id of the subscription
5313 * @param request contains the radio access networks with bands/channels to scan
5314 * @param messenger callback messenger for scan results or errors
5315 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005316 * @return the id of the requested scan which can be used to stop the scan.
5317 */
5318 @Override
5319 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005320 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5322 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005323 LocationAccessPolicy.LocationPermissionResult locationResult =
5324 LocationAccessPolicy.checkLocationPermission(mApp,
5325 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5326 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005327 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005328 .setCallingPid(Binder.getCallingPid())
5329 .setCallingUid(Binder.getCallingUid())
5330 .setMethod("requestNetworkScan")
5331 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5332 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005333 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005334 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005335 if (e != null) {
5336 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5337 throw e;
5338 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005339 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005340 return TelephonyScanManager.INVALID_SCAN_ID;
5341 }
5342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 }
Hall Liu912dfd32019-04-25 14:02:26 -07005344 int callingUid = Binder.getCallingUid();
5345 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005346 final long identity = Binder.clearCallingIdentity();
5347 try {
5348 return mNetworkScanRequestTracker.startNetworkScan(
5349 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005350 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
yinxu504e1392017-04-12 16:03:22 -07005354 }
5355
Hall Liub2ac8ef2019-02-28 15:56:23 -08005356 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005357 NetworkScanRequest request, int subId) {
5358 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5359 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5360 boolean hasNetworkScanPermission =
5361 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5362 == PERMISSION_GRANTED;
5363
5364 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5365 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5366 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005367 }
5368
5369 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5370 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005371 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5372 return new SecurityException("Specific channels must not be"
5373 + " scanned without location access.");
5374 }
5375 }
5376 }
5377
Hall Liub2ac8ef2019-02-28 15:56:23 -08005378 return null;
5379 }
5380
yinxu504e1392017-04-12 16:03:22 -07005381 /**
5382 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005383 *
5384 * @param subId id of the subscription
5385 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005386 */
5387 @Override
5388 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5390 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391
Hall Liu912dfd32019-04-25 14:02:26 -07005392 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005395 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
yinxu504e1392017-04-12 16:03:22 -07005399 }
5400
5401 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005402 * Get the calculated preferred network type.
5403 * Used for debugging incorrect network type.
5404 *
5405 * @return the preferred network type, defined in RILConstants.java.
5406 */
5407 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005408 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005409 final Phone defaultPhone = getDefaultPhone();
5410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005411 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005412 return RILConstants.PREFERRED_NETWORK_MODE;
5413 }
5414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005418 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 } finally {
5420 Binder.restoreCallingIdentity(identity);
5421 }
Junda Liu84d15a22014-07-02 11:21:04 -07005422 }
5423
5424 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005425 * Get the preferred network type.
5426 * Used for device configuration by some CDMA operators.
5427 *
5428 * @return the preferred network type, defined in RILConstants.java.
5429 */
5430 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005431 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005432 TelephonyPermissions
5433 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5434 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435
5436 final long identity = Binder.clearCallingIdentity();
5437 try {
5438 if (DBG) log("getPreferredNetworkType");
5439 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5440 int networkType = (result != null ? result[0] : -1);
5441 if (DBG) log("getPreferredNetworkType: " + networkType);
5442 return networkType;
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
5445 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005446 }
5447
5448 /**
5449 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005450 *
5451 * @param networkType the preferred network type, defined in RILConstants.java.
5452 * @return true on success; false on any failure.
5453 */
5454 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005455 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5457 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005461 Settings.Global.putInt(mApp.getContentResolver(),
5462 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005463
5464 Boolean success = (Boolean) sendRequest(
5465 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5466 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5467 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 } finally {
5469 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005470 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005471 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005472
5473 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005474 * Get the allowed network types that store in the telephony provider.
5475 *
5476 * @param subId the id of the subscription.
5477 * @return allowedNetworkTypes the allowed network types.
5478 */
5479 @Override
5480 public long getAllowedNetworkTypes(int subId) {
5481 TelephonyPermissions
5482 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5483 mApp, subId, "getAllowedNetworkTypes");
5484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 return SubscriptionManager.getLongSubscriptionProperty(
5488 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
5492 }
5493
5494 /**
5495 * Set the allowed network types.
5496 *
5497 * @param subId the id of the subscription.
5498 * @param allowedNetworkTypes the allowed network types.
5499 * @return true on success; false on any failure.
5500 */
5501 @Override
5502 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5504 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005505
calvinpan089c2a62020-03-12 14:17:55 +08005506 SubscriptionManager.setSubscriptionProperty(subId,
5507 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5508 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005509
calvinpan089c2a62020-03-12 14:17:55 +08005510 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5511 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5512 RILConstants.PREFERRED_NETWORK_MODE);
5513 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005514 }
5515
5516 /**
Miaoa84611c2019-03-15 09:21:10 +08005517 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005518 *
Miaoa84611c2019-03-15 09:21:10 +08005519 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005520 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005521 * @hide
5522 */
5523 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005524 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005527 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 try {
Miaoa84611c2019-03-15 09:21:10 +08005529 if (phone != null) {
5530 return phone.hasMatchedTetherApnSetting();
5531 } else {
5532 return false;
5533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 } finally {
5535 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005536 }
Junda Liu475951f2014-11-07 16:45:03 -08005537 }
5538
5539 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005540 * Set mobile data enabled
5541 * Used by the user through settings etc to turn on/off mobile data
5542 *
5543 * @param enable {@code true} turn turn data on, else {@code false}
5544 */
5545 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005546 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5548 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549
5550 final long identity = Binder.clearCallingIdentity();
5551 try {
5552 int phoneId = mSubscriptionController.getPhoneId(subId);
5553 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5554 Phone phone = PhoneFactory.getPhone(phoneId);
5555 if (phone != null) {
5556 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005557 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005559 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 }
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005563 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005564 }
5565
5566 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005567 * Enable or disable always reporting signal strength changes from radio.
5568 *
5569 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5570 */
5571 @Override
5572 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5573 enforceModifyPermission();
5574 enforceSystemCaller();
5575
5576 final long identity = Binder.clearCallingIdentity();
5577 final Phone phone = getPhone(subId);
5578 try {
5579 if (phone != null) {
5580 if (DBG) {
5581 log("setAlwaysReportSignalStrength: subId=" + subId
5582 + " isEnable=" + isEnable);
5583 }
5584 phone.setAlwaysReportSignalStrength(isEnable);
5585 } else {
5586 loge("setAlwaysReportSignalStrength: no phone found for subId="
5587 + subId);
5588 }
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
5592 }
5593
5594 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005595 * Get the user enabled state of Mobile Data.
5596 *
5597 * TODO: remove and use isUserDataEnabled.
5598 * This can't be removed now because some vendor codes
5599 * calls through ITelephony directly while they should
5600 * use TelephonyManager.
5601 *
5602 * @return true on enabled
5603 */
5604 @Override
5605 public boolean getDataEnabled(int subId) {
5606 return isUserDataEnabled(subId);
5607 }
5608
5609 /**
5610 * Get whether mobile data is enabled per user setting.
5611 *
5612 * There are other factors deciding whether mobile data is actually enabled, but they are
5613 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005614 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005615 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005616 *
5617 * @return {@code true} if data is enabled else {@code false}
5618 */
5619 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005620 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005621 try {
5622 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5623 null);
5624 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
5629 final long identity = Binder.clearCallingIdentity();
5630 try {
5631 int phoneId = mSubscriptionController.getPhoneId(subId);
5632 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5633 Phone phone = PhoneFactory.getPhone(phoneId);
5634 if (phone != null) {
5635 boolean retVal = phone.isUserDataEnabled();
5636 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5637 return retVal;
5638 } else {
5639 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5640 return false;
5641 }
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005644 }
5645 }
5646
5647 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005648 * Checks if the device is capable of mobile data by considering whether whether the
5649 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5650 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005651 *
Shuo Qian985d1232020-01-08 14:30:06 -08005652 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005653 */
5654 @Override
5655 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005656 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 int phoneId = mSubscriptionController.getPhoneId(subId);
5661 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5662 Phone phone = PhoneFactory.getPhone(phoneId);
5663 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005664 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5666 return retVal;
5667 } else {
5668 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5669 return false;
5670 }
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005673 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005674 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005675
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005676 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005677 Phone phone) {
5678 //load access rules from carrier configs, and check those as well: b/139133814
5679 SubscriptionController subController = SubscriptionController.getInstance();
5680 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5681 || subController == null) return privilegeFromSim;
5682
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005683 PackageManager pkgMgr = phone.getContext().getPackageManager();
5684 String[] packages = pkgMgr.getPackagesForUid(uid);
5685
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5689 SubscriptionManager subManager = (SubscriptionManager)
5690 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5691 for (String pkg : packages) {
5692 if (subManager.canManageSubscription(subInfo, pkg)) {
5693 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5694 }
5695 }
5696 return privilegeFromSim;
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
5700 }
5701
5702 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5703 String pkgName) {
5704 //load access rules from carrier configs, and check those as well: b/139133814
5705 SubscriptionController subController = SubscriptionController.getInstance();
5706 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5707 || subController == null) return privilegeFromSim;
5708
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5712 SubscriptionManager subManager = (SubscriptionManager)
5713 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5714 return subManager.canManageSubscription(subInfo, pkgName)
5715 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
5719 }
5720
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005721 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005722 public int getCarrierPrivilegeStatus(int subId) {
5723 final Phone phone = getPhone(subId);
5724 if (phone == null) {
5725 loge("getCarrierPrivilegeStatus: Invalid subId");
5726 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5727 }
5728 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005729 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005730 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005731 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5732 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005733
5734 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5735 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005736 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005737 }
Junda Liu29340342014-07-10 15:23:27 -07005738
5739 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005740 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005741 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005742 final Phone phone = getPhone(subId);
5743 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005744 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005745 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5746 }
5747 UiccProfile profile =
5748 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5749 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005750 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5752 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005753 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005754 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005755 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005756 }
5757
5758 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005759 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5760 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005762 }
5763
5764 int phoneId = SubscriptionManager.getPhoneId(subId);
5765 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005766 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005767 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5769 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005770 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5771 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5772 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005773 }
5774
5775 @Override
5776 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005777 if (TextUtils.isEmpty(pkgName))
5778 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005779 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5780 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5781 UiccCard card = UiccController.getInstance().getUiccCard(i);
5782 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005783 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005784 continue;
5785 }
5786
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005787 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5788 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5789 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005790 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5791 break;
5792 }
5793 }
5794
5795 return result;
Junda Liu29340342014-07-10 15:23:27 -07005796 }
Derek Tan89e89d42014-07-08 17:00:10 -07005797
5798 @Override
Junda Liue64de782015-04-16 17:19:16 -07005799 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5800 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5801 loge("phoneId " + phoneId + " is not valid.");
5802 return null;
5803 }
5804 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005805 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005806 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005807 return null ;
5808 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005809 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005810 }
5811
Amith Yamasani6e118872016-02-19 12:53:51 -08005812 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005813 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005814 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005815 List<String> privilegedPackages = new ArrayList<>();
5816 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005817 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5818 // has UICC in that slot.
5819 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005820 if (card.hasCarrierPrivilegeRules()) {
5821 if (packages == null) {
5822 // Only check packages in user 0 for now
5823 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005824 PackageManager.MATCH_DISABLED_COMPONENTS
5825 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005826 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005827 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005828 }
5829 for (int p = packages.size() - 1; p >= 0; p--) {
5830 PackageInfo pkgInfo = packages.get(p);
5831 if (pkgInfo != null && pkgInfo.packageName != null
5832 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005833 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005834 privilegedPackages.add(pkgInfo.packageName);
5835 }
5836 }
5837 }
5838 }
5839 return privilegedPackages;
5840 }
5841
chen xuf7e9fe82019-05-09 19:31:02 -07005842 @Override
5843 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005844 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5845
5846 final long identity = Binder.clearCallingIdentity();
5847
chen xuf7e9fe82019-05-09 19:31:02 -07005848 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005849 try {
5850 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5851 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5852 }
5853 } finally {
5854 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005855 }
5856 return privilegedPackages;
5857 }
5858
Wink Savilleb564aae2014-10-23 10:18:09 -07005859 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005860 final Phone phone = getPhone(subId);
5861 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005862 if (card == null) {
5863 loge("getIccId: No UICC");
5864 return null;
5865 }
5866 String iccId = card.getIccId();
5867 if (TextUtils.isEmpty(iccId)) {
5868 loge("getIccId: ICC ID is null or empty.");
5869 return null;
5870 }
5871 return iccId;
5872 }
5873
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005874 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005875 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5876 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005877 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005878 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 final String iccId = getIccId(subId);
5883 final Phone phone = getPhone(subId);
5884 if (phone == null) {
5885 return false;
5886 }
5887 final String subscriberId = phone.getSubscriberId();
5888
5889 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005890 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 + subscriberId + " to " + number);
5892 }
5893
5894 if (TextUtils.isEmpty(iccId)) {
5895 return false;
5896 }
5897
5898 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5899
5900 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5901 if (alphaTag == null) {
5902 editor.remove(alphaTagPrefKey);
5903 } else {
5904 editor.putString(alphaTagPrefKey, alphaTag);
5905 }
5906
5907 // Record both the line number and IMSI for this ICCID, since we need to
5908 // track all merged IMSIs based on line number
5909 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5910 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5911 if (number == null) {
5912 editor.remove(numberPrefKey);
5913 editor.remove(subscriberPrefKey);
5914 } else {
5915 editor.putString(numberPrefKey, number);
5916 editor.putString(subscriberPrefKey, subscriberId);
5917 }
5918
5919 editor.commit();
5920 return true;
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005923 }
Derek Tan7226c842014-07-02 17:42:23 -07005924 }
5925
5926 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005927 public String getLine1NumberForDisplay(int subId, String callingPackage,
5928 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005929 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005931 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005932 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005933 return null;
5934 }
Derek Tan97ebb422014-09-05 16:55:38 -07005935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 final long identity = Binder.clearCallingIdentity();
5937 try {
5938 String iccId = getIccId(subId);
5939 if (iccId != null) {
5940 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5941 if (DBG_MERGE) {
5942 log("getLine1NumberForDisplay returning "
5943 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5944 }
5945 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5948 return null;
5949 } finally {
5950 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005951 }
Derek Tan7226c842014-07-02 17:42:23 -07005952 }
5953
5954 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005955 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5956 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005958 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005959 return null;
5960 }
Derek Tan97ebb422014-09-05 16:55:38 -07005961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 String iccId = getIccId(subId);
5965 if (iccId != null) {
5966 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5967 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5968 }
5969 return null;
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005972 }
Derek Tan7226c842014-07-02 17:42:23 -07005973 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005974
5975 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005976 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5977 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005978 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5979 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005981 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005982 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005983 return null;
5984 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005985
Jordan Liub49b04b2019-05-06 14:45:15 -07005986 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5987 // the process, where TelephonyManager was instantiated.
5988 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005989 final long identity = Binder.clearCallingIdentity();
5990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005991 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 final TelephonyManager tele = TelephonyManager.from(context);
5993 final SubscriptionManager sub = SubscriptionManager.from(context);
5994
5995 // Figure out what subscribers are currently active
5996 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997
Jordan Liub49b04b2019-05-06 14:45:15 -07005998 // Only consider subs which match the current subId
5999 // This logic can be simplified. See b/131189269 for progress.
6000 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006001 activeSubscriberIds.add(tele.getSubscriberId(subId));
6002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 // First pass, find a number override for an active subscriber
6005 String mergeNumber = null;
6006 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6007 for (String key : prefs.keySet()) {
6008 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6009 final String subscriberId = (String) prefs.get(key);
6010 if (activeSubscriberIds.contains(subscriberId)) {
6011 final String iccId = key.substring(
6012 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6013 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6014 mergeNumber = (String) prefs.get(numberKey);
6015 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006016 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 + " for active subscriber " + subscriberId);
6018 }
6019 if (!TextUtils.isEmpty(mergeNumber)) {
6020 break;
6021 }
6022 }
6023 }
6024 }
6025
6026 // Shortcut when no active merged subscribers
6027 if (TextUtils.isEmpty(mergeNumber)) {
6028 return null;
6029 }
6030
6031 // Second pass, find all subscribers under that line override
6032 final ArraySet<String> result = new ArraySet<>();
6033 for (String key : prefs.keySet()) {
6034 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6035 final String number = (String) prefs.get(key);
6036 if (mergeNumber.equals(number)) {
6037 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6038 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6039 final String subscriberId = (String) prefs.get(subscriberKey);
6040 if (!TextUtils.isEmpty(subscriberId)) {
6041 result.add(subscriberId);
6042 }
6043 }
6044 }
6045 }
6046
6047 final String[] resultArray = result.toArray(new String[result.size()]);
6048 Arrays.sort(resultArray);
6049 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006050 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6052 }
6053 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006054 } finally {
6055 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006056 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006057 }
6058
6059 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006060 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6061 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6062
6063 final long identity = Binder.clearCallingIdentity();
6064 try {
6065 final TelephonyManager telephonyManager = mApp.getSystemService(
6066 TelephonyManager.class);
6067 String subscriberId = telephonyManager.getSubscriberId(subId);
6068 if (subscriberId == null) {
6069 if (DBG) {
6070 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6071 + subId);
6072 }
6073 return null;
6074 }
6075
6076 final SubscriptionInfo info = SubscriptionController.getInstance()
6077 .getSubscriptionInfo(subId);
6078 final ParcelUuid groupUuid = info.getGroupUuid();
6079 // If it doesn't belong to any group, return just subscriberId of itself.
6080 if (groupUuid == null) {
6081 return new String[]{subscriberId};
6082 }
6083
6084 // Get all subscriberIds from the group.
6085 final List<String> mergedSubscriberIds = new ArrayList<>();
6086 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006087 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6088 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006089 for (SubscriptionInfo subInfo : groupInfos) {
6090 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6091 if (subscriberId != null) {
6092 mergedSubscriberIds.add(subscriberId);
6093 }
6094 }
6095
6096 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099
6100 }
6101 }
6102
6103 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006104 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006105 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006106 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 final Phone phone = getPhone(subId);
6111 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006115 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006116
6117 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006118 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006119 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6120 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6122 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123
6124 final long identity = Binder.clearCallingIdentity();
6125 try {
6126 final Phone phone = getPhone(subId);
6127 if (phone == null) {
6128 return false;
6129 }
6130 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6131 cdmaNonRoamingList);
6132 } finally {
6133 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006134 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006135 }
6136
6137 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006138 @Deprecated
6139 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6140 enforceModifyPermission();
6141
6142 int returnValue = 0;
6143 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006144 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006145 if(result.exception == null) {
6146 if (result.result != null) {
6147 byte[] responseData = (byte[])(result.result);
6148 if(responseData.length > oemResp.length) {
6149 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6150 responseData.length + "bytes. Buffer Size is " +
6151 oemResp.length + "bytes.");
6152 }
6153 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6154 returnValue = responseData.length;
6155 }
6156 } else {
6157 CommandException ex = (CommandException) result.exception;
6158 returnValue = ex.getCommandError().ordinal();
6159 if(returnValue > 0) returnValue *= -1;
6160 }
6161 } catch (RuntimeException e) {
6162 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6163 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6164 if(returnValue > 0) returnValue *= -1;
6165 }
6166
6167 return returnValue;
6168 }
6169
6170 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006171 public void setRadioCapability(RadioAccessFamily[] rafs) {
6172 try {
6173 ProxyController.getInstance().setRadioCapability(rafs);
6174 } catch (RuntimeException e) {
6175 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6176 }
6177 }
6178
6179 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006180 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006181 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006182 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006183 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006184 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006185 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 final long identity = Binder.clearCallingIdentity();
6187 try {
chen xub97461a2018-10-26 14:17:57 -07006188 TelephonyPermissions
6189 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6190 mApp, phone.getSubId(), "getRadioAccessFamily");
6191 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
chen xub97461a2018-10-26 14:17:57 -07006195 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006196 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006197
6198 @Override
6199 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006200 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006201 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202
6203 final long identity = Binder.clearCallingIdentity();
6204 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006205 ImsManager.getInstance(defaultPhone.getContext(),
6206 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006210 }
6211
6212 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006213 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006214 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6216 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006217 return false;
6218 }
Svet Ganovb320e182015-04-16 12:30:10 -07006219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 // Check the user preference and the system-level IMS setting. Even if the user has
6223 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6224 // In the long run, we may instead need to check if there exists a connection service
6225 // which can support video calling.
6226 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006227 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 return imsManager.isVtEnabledByPlatform()
6229 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6230 && imsManager.isVtEnabledByUser();
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006234 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006235
Andrew Leea1239f22015-03-02 17:44:07 -08006236 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006237 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6238 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006240 mApp, subId, callingPackage, callingFeatureId,
6241 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 return false;
6243 }
6244
6245 final long identity = Binder.clearCallingIdentity();
6246 try {
6247 CarrierConfigManager configManager =
6248 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006249 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6251 } finally {
6252 Binder.restoreCallingIdentity(identity);
6253 }
Andrew Leea1239f22015-03-02 17:44:07 -08006254 }
6255
6256 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006257 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006259 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 return false;
6261 }
6262
6263 final long identity = Binder.clearCallingIdentity();
6264 try {
6265 CarrierConfigManager configManager =
6266 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006267 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
Andrew Leea1239f22015-03-02 17:44:07 -08006272 }
6273
Andrew Lee9431b832015-03-09 18:46:45 -07006274 @Override
6275 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006276 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006277 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006278 }
6279
6280 @Override
6281 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 final long identity = Binder.clearCallingIdentity();
6283 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006284 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006285 } finally {
6286 Binder.restoreCallingIdentity(identity);
6287 }
Andrew Lee9431b832015-03-09 18:46:45 -07006288 }
6289
Hall Liuf6668912018-10-31 17:05:23 -07006290 /**
6291 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6292 * support for the feature and device firmware support.
6293 *
6294 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6295 */
6296 @Override
6297 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006299 final Phone phone = getPhone(subscriptionId);
6300 if (phone == null) {
6301 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6302 return false;
6303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006305 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6307 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006308 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 return isCarrierSupported && isDeviceSupported;
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
Hall Liu98187582018-01-22 19:15:32 -08006313 }
6314
Hall Liuf6668912018-10-31 17:05:23 -07006315 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006316 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6317 * RTT setting, will return true if the device and carrier both support RTT.
6318 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006319 */
6320 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 final long identity = Binder.clearCallingIdentity();
6322 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006323 boolean isRttSupported = isRttSupported(subscriptionId);
6324 boolean isUserRttSettingOn = Settings.Secure.getInt(
6325 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6326 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6327 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6328 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006332 }
6333
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006334 @Deprecated
6335 @Override
6336 public String getDeviceId(String callingPackage) {
6337 return getDeviceIdWithFeature(callingPackage, null);
6338 }
6339
Sanket Padawe7310cc72015-01-14 09:53:20 -08006340 /**
6341 * Returns the unique device ID of phone, for example, the IMEI for
6342 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6343 *
6344 * <p>Requires Permission:
6345 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6346 */
6347 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006348 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006349 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006350 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006351 return null;
6352 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006353 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006354 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006355 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006356 return null;
6357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358
6359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 return phone.getDeviceId();
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006365 }
6366
Ping Sunc67b7c22016-03-02 19:16:45 +08006367 /**
6368 * {@hide}
6369 * Returns the IMS Registration Status on a particular subid
6370 *
6371 * @param subId
6372 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006373 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006374 Phone phone = getPhone(subId);
6375 if (phone != null) {
6376 return phone.isImsRegistered();
6377 } else {
6378 return false;
6379 }
6380 }
6381
Santos Cordon7a1885b2015-02-03 11:15:19 -08006382 @Override
6383 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006390 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006391
Tyler Gunnf70ed162019-04-03 15:28:53 -07006392 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006393 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006394 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006396 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006397 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6398 }
6399 final long identity = Binder.clearCallingIdentity();
6400 try {
6401 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
6405 }
6406
6407 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006408 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 Phone phone = getPhone(subscriptionId);
6412 if (phone == null) {
6413 return null;
6414 }
6415 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
6419 }
6420
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006421 /**
6422 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006423 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006424 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 Phone phone = getPhone(subId);
6428 if (phone != null) {
6429 return phone.isWifiCallingEnabled();
6430 } else {
6431 return false;
6432 }
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006435 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006436 }
6437
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006438 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006439 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006440 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006441 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 Phone phone = getPhone(subId);
6445 if (phone != null) {
6446 return phone.isVideoEnabled();
6447 } else {
6448 return false;
6449 }
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006452 }
6453 }
6454
6455 /**
6456 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6457 * defined in {@link ImsRegistrationImplBase}.
6458 */
6459 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 Phone phone = getPhone(subId);
6463 if (phone != null) {
6464 return phone.getImsRegistrationTech();
6465 } else {
6466 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6467 }
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006470 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006471 }
6472
Stuart Scott8eef64f2015-04-08 15:13:54 -07006473 @Override
6474 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006475 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006476 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6477 return;
6478 }
6479
Svet Ganovcc087f82015-05-12 20:35:54 -07006480 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006481
Svet Ganovcc087f82015-05-12 20:35:54 -07006482 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006483 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6484 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006485 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006486 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006487 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006488 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6489 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006490 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006491 // There has been issues when Sms raw table somehow stores orphan
6492 // fragments. They lead to garbled message when new fragments come
6493 // in and combined with those stale ones. In case this happens again,
6494 // user can reset all network settings which will clean up this table.
6495 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006496 // Clean up IMS settings as well here.
6497 int slotId = getSlotIndex(subId);
6498 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6499 ImsManager.getInstance(mApp, slotId).factoryReset();
6500 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006501
6502 // Erase modem config if erase modem on network setting is enabled.
6503 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6504 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6505 if (configValue != null && Boolean.parseBoolean(configValue)) {
6506 sendEraseModemConfig(getDefaultPhone());
6507 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006508 } finally {
6509 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006510 }
6511 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006512
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006513 private void cleanUpSmsRawTable(Context context) {
6514 ContentResolver resolver = context.getContentResolver();
6515 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6516 resolver.delete(uri, null, null);
6517 }
6518
Narayan Kamath1c496c22015-04-16 14:40:19 +01006519 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006520 public String getSimLocaleForSubscriber(int subId) {
6521 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6522 final Phone phone = getPhone(subId);
6523 if (phone == null) {
6524 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006525 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006527 final long identity = Binder.clearCallingIdentity();
6528 try {
chen xu5d3637b2019-01-21 23:31:38 -08006529 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006530 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006531 if (info == null) {
6532 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6533 return null;
6534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 // Try and fetch the locale from the carrier properties or from the SIM language
6536 // preferences (EF-PL and EF-LI)...
6537 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006539 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6540 if (localeFromDefaultSim != null) {
6541 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6542 if (DBG) log("Using locale from subId: " + subId + " locale: "
6543 + localeFromDefaultSim);
6544 return localeFromDefaultSim.toLanguageTag();
6545 } else {
6546 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 }
6548 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 // The SIM language preferences only store a language (e.g. fr = French), not an
6551 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6552 // the SIM and carrier preferences does not include a country we add the country
6553 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006554 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006556 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 return mccLocale.toLanguageTag();
6558 }
6559
6560 if (DBG) log("No locale found - returning null");
6561 return null;
6562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006565 }
6566
6567 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006568 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6569 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006570 }
6571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 /**
6573 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6574 */
6575 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006576 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6577 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006578 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006579
Chenjie Yu1ba97252018-01-11 18:16:20 -08006580 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006581 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006582
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006583 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006584 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6585 * representing the state of the modem.
6586 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006587 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6588 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006589 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006590 */
6591 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006592 public void requestModemActivityInfo(ResultReceiver result) {
6593 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
sqian1a1be542020-03-05 11:37:28 -08006598 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 } finally {
6600 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006601 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006602 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006603
Siddharth Rayb8114062018-06-17 15:02:38 -07006604 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6605 // less than total activity duration.
6606 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6607 if (info == null) {
6608 return false;
6609 }
6610 int activityDurationMs =
6611 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6612 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006613 int[] txTimeMs = info.getTransmitTimeMillis();
6614 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6615 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006616 }
6617 return (info.isValid()
6618 && (info.getSleepTimeMillis() <= activityDurationMs)
6619 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006620 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006621 && (totalTxTimeMs <= activityDurationMs));
6622 }
6623
Jack Yu85bd38a2015-11-09 11:34:32 -08006624 /**
6625 * {@hide}
6626 * Returns the service state information on specified subscription.
6627 */
6628 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006629 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6630 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006632 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006633 return null;
6634 }
6635
Hall Liuf19c44f2018-11-27 14:38:17 -08006636 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6637 LocationAccessPolicy.checkLocationPermission(mApp,
6638 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6639 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006640 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006641 .setCallingPid(Binder.getCallingPid())
6642 .setCallingUid(Binder.getCallingUid())
6643 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006644 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006645 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6646 .build());
6647
6648 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6649 LocationAccessPolicy.checkLocationPermission(mApp,
6650 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6651 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006652 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006653 .setCallingPid(Binder.getCallingPid())
6654 .setCallingUid(Binder.getCallingUid())
6655 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006656 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006657 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6658 .build());
6659 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6660 boolean hasFinePermission =
6661 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6662 boolean hasCoarsePermission =
6663 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 final Phone phone = getPhone(subId);
6668 if (phone == null) {
6669 return null;
6670 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006671
Hall Liuf19c44f2018-11-27 14:38:17 -08006672 ServiceState ss = phone.getServiceState();
6673
6674 // Scrub out the location info in ServiceState depending on what level of access
6675 // the caller has.
6676 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006677 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6678 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006682 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006683
6684 /**
6685 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6686 *
6687 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6688 * voicemail ringtone.
6689 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6690 * PhoneAccount.
6691 */
6692 @Override
6693 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6697 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006698 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
6704 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006705 }
6706
6707 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006708 * Sets the per-account voicemail ringtone.
6709 *
6710 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6711 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6712 *
6713 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6714 * voicemail ringtone.
6715 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6716 * PhoneAccount.
6717 */
6718 @Override
6719 public void setVoicemailRingtoneUri(String callingPackage,
6720 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006721 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006723 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6724 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6726 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6727 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729
6730 final long identity = Binder.clearCallingIdentity();
6731 try {
6732 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6733 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006734 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 }
6736 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6737 } finally {
6738 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006739 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006740 }
6741
6742 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006743 * Returns whether vibration is set for voicemail notification in Phone settings.
6744 *
6745 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6746 * voicemail vibration setting.
6747 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6748 */
6749 @Override
6750 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 final long identity = Binder.clearCallingIdentity();
6752 try {
6753 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6754 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006755 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006762 }
6763
Youhan Wange64578a2016-05-02 15:32:42 -07006764 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006765 * Sets the per-account voicemail vibration.
6766 *
6767 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6768 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6769 *
6770 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6771 * voicemail vibration setting.
6772 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6773 * specific PhoneAccount.
6774 */
6775 @Override
6776 public void setVoicemailVibrationEnabled(String callingPackage,
6777 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006778 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006779 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006780 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6781 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6783 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6784 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006785 }
6786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 final long identity = Binder.clearCallingIdentity();
6788 try {
6789 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6790 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006791 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 }
6793 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006796 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006797 }
6798
6799 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006800 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6801 *
6802 * @throws SecurityException if the caller does not have the required permission
6803 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006804 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006805 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006806 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006807 }
6808
6809 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006810 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6811 * permission.
6812 *
6813 * @throws SecurityException if the caller does not have the required permission
6814 */
6815 private void enforceSendSmsPermission() {
6816 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6817 }
6818
6819 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006820 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006821 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006822 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006823 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006824 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 final long identity = Binder.clearCallingIdentity();
6826 try {
6827 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006828 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 if (componentName == null) {
6830 throw new SecurityException(
6831 "Caller not current active visual voicemail package[null]");
6832 }
6833 String vvmPackage = componentName.getPackageName();
6834 if (!callingPackage.equals(vvmPackage)) {
6835 throw new SecurityException("Caller not current active visual voicemail package["
6836 + vvmPackage + "]");
6837 }
6838 } finally {
6839 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006840 }
6841 }
6842
6843 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006844 * Return the application ID for the app type.
6845 *
6846 * @param subId the subscription ID that this request applies to.
6847 * @param appType the uicc app type.
6848 * @return Application ID for specificied app type, or null if no uicc.
6849 */
6850 @Override
6851 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006852 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006853 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854
6855 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006856 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 if (phone == null) {
6858 return null;
6859 }
6860 String aid = null;
6861 try {
6862 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6863 .getApplicationByType(appType).getAid();
6864 } catch (Exception e) {
6865 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6866 }
6867 return aid;
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006870 }
Youhan Wange64578a2016-05-02 15:32:42 -07006871 }
6872
Youhan Wang4001d252016-05-11 10:29:41 -07006873 /**
6874 * Return the Electronic Serial Number.
6875 *
6876 * @param subId the subscription ID that this request applies to.
6877 * @return ESN or null if error.
6878 */
6879 @Override
6880 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006881 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006882 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883
6884 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006885 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 if (phone == null) {
6887 return null;
6888 }
6889 String esn = null;
6890 try {
6891 esn = phone.getEsn();
6892 } catch (Exception e) {
6893 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6894 }
6895 return esn;
6896 } finally {
6897 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006898 }
Youhan Wang4001d252016-05-11 10:29:41 -07006899 }
6900
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006901 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006902 * Return the Preferred Roaming List Version.
6903 *
6904 * @param subId the subscription ID that this request applies to.
6905 * @return PRLVersion or null if error.
6906 */
6907 @Override
6908 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006909 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006910 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911
6912 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006913 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 if (phone == null) {
6915 return null;
6916 }
6917 String cdmaPrlVersion = null;
6918 try {
6919 cdmaPrlVersion = phone.getCdmaPrlVersion();
6920 } catch (Exception e) {
6921 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6922 }
6923 return cdmaPrlVersion;
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006926 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006927 }
6928
6929 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006930 * Get snapshot of Telephony histograms
6931 * @return List of Telephony histograms
6932 * @hide
6933 */
6934 @Override
6935 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6937 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938
6939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 return RIL.getTelephonyRILTimingHistograms();
6942 } finally {
6943 Binder.restoreCallingIdentity(identity);
6944 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006945 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006946
6947 /**
6948 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006949 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6950 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006951 * Require system privileges. In the future we may add this to carrier APIs.
6952 *
Michele Berionne482f8202018-11-27 18:57:59 -08006953 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006954 */
6955 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006956 @TelephonyManager.SetCarrierRestrictionResult
6957 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006958 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006959 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006960
Michele Berionne482f8202018-11-27 18:57:59 -08006961 if (carrierRestrictionRules == null) {
6962 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006963 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 final long identity = Binder.clearCallingIdentity();
6966 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006967 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006968 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006972 }
6973
6974 /**
6975 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006976 * Get the allowed carrier list and the excluded carrier list, including the priority between
6977 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006978 * Require system privileges. In the future we may add this to carrier APIs.
6979 *
Michele Berionne482f8202018-11-27 18:57:59 -08006980 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006981 */
6982 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006983 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006984 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986
6987 final long identity = Binder.clearCallingIdentity();
6988 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006989 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6990 if (response instanceof CarrierRestrictionRules) {
6991 return (CarrierRestrictionRules) response;
6992 }
6993 // Response is an Exception of some kind,
6994 // which is signalled to the user as a NULL retval
6995 return null;
6996 } catch (Exception e) {
6997 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6998 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007002 }
7003
fionaxu59545b42016-05-25 15:53:37 -07007004 /**
7005 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7006 * @param subId the subscription ID that this action applies to.
7007 * @param enabled control enable or disable metered apns.
7008 * {@hide}
7009 */
7010 @Override
7011 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7012 enforceModifyPermission();
7013 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014
7015 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007016 if (phone == null) {
7017 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7018 return;
7019 }
7020 try {
7021 phone.carrierActionSetMeteredApnsEnabled(enabled);
7022 } catch (Exception e) {
7023 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 } finally {
7025 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007026 }
7027 }
7028
7029 /**
7030 * Action set from carrier signalling broadcast receivers to enable/disable radio
7031 * @param subId the subscription ID that this action applies to.
7032 * @param enabled control enable or disable radio.
7033 * {@hide}
7034 */
7035 @Override
7036 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7037 enforceModifyPermission();
7038 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039
7040 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007041 if (phone == null) {
7042 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7043 return;
7044 }
7045 try {
7046 phone.carrierActionSetRadioEnabled(enabled);
7047 } catch (Exception e) {
7048 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 } finally {
7050 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007051 }
7052 }
7053
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007054 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007055 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7056 * network status based on which carrier apps could apply actions accordingly,
7057 * enable/disable default url handler for example.
7058 *
7059 * @param subId the subscription ID that this action applies to.
7060 * @param report control start/stop reporting the default network status.
7061 * {@hide}
7062 */
7063 @Override
7064 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7065 enforceModifyPermission();
7066 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067
7068 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007069 if (phone == null) {
7070 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7071 return;
7072 }
7073 try {
7074 phone.carrierActionReportDefaultNetworkStatus(report);
7075 } catch (Exception e) {
7076 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007079 }
7080 }
7081
7082 /**
fionaxud9622282017-07-17 17:51:30 -07007083 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7084 * @param subId the subscription ID that this action applies to.
7085 * {@hide}
7086 */
7087 @Override
7088 public void carrierActionResetAll(int subId) {
7089 enforceModifyPermission();
7090 final Phone phone = getPhone(subId);
7091 if (phone == null) {
7092 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7093 return;
7094 }
7095 try {
7096 phone.carrierActionResetAll();
7097 } catch (Exception e) {
7098 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7099 }
7100 }
7101
7102 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007103 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7104 * bug report is being generated.
7105 */
7106 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007107 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007108 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7109 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007110 writer.println("Permission Denial: can't dump Phone from pid="
7111 + Binder.getCallingPid()
7112 + ", uid=" + Binder.getCallingUid()
7113 + "without permission "
7114 + android.Manifest.permission.DUMP);
7115 return;
7116 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007117 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007118 }
Jack Yueb89b242016-06-22 13:27:47 -07007119
Brad Ebingerdac2f002018-04-03 15:17:52 -07007120 @Override
7121 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7122 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7123 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007124 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7125 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007126 }
7127
Jack Yueb89b242016-06-22 13:27:47 -07007128 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007129 * Policy control of data connection. Usually used when data limit is passed.
7130 * @param enabled True if enabling the data, otherwise disabling.
7131 * @param subId Subscription index
7132 * {@hide}
7133 */
7134 @Override
7135 public void setPolicyDataEnabled(boolean enabled, int subId) {
7136 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137
7138 final long identity = Binder.clearCallingIdentity();
7139 try {
7140 Phone phone = getPhone(subId);
7141 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007142 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 }
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007146 }
7147 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007148
7149 /**
7150 * Get Client request stats
7151 * @return List of Client Request Stats
7152 * @hide
7153 */
7154 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007155 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7156 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007158 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007159 return null;
7160 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007161 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 if (phone != null) {
7166 return phone.getClientRequestStats();
7167 }
7168
7169 return null;
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007173 }
7174
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007175 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007176 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007177 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007178 }
Jack Yueb4124c2017-02-16 15:32:43 -08007179
7180 /**
Grace Chen70990072017-03-24 17:21:30 -07007181 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007182 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007183 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007184 * @param state State of SIM (power down, power up, pass through)
7185 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7186 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7187 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007188 *
7189 **/
7190 @Override
Grace Chen70990072017-03-24 17:21:30 -07007191 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007192 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007193 Phone phone = PhoneFactory.getPhone(slotIndex);
7194
vagdeviaf9a5b92018-08-15 16:01:53 -07007195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007200 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 }
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007204 }
7205 }
Shuo Qiandd210312017-04-12 22:11:33 +00007206
Tyler Gunn65d45c22017-06-05 11:22:26 -07007207 private boolean isUssdApiAllowed(int subId) {
7208 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007209 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007210 if (configManager == null) {
7211 return false;
7212 }
7213 PersistableBundle pb = configManager.getConfigForSubId(subId);
7214 if (pb == null) {
7215 return false;
7216 }
7217 return pb.getBoolean(
7218 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7219 }
7220
Shuo Qiandd210312017-04-12 22:11:33 +00007221 /**
7222 * Check if phone is in emergency callback mode
7223 * @return true if phone is in emergency callback mode
7224 * @param subId sub id
7225 */
goneil9c5f4872017-12-05 14:07:56 -08007226 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007227 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007228 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007229 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 if (phone != null) {
7234 return phone.isInEcm();
7235 } else {
7236 return false;
7237 }
7238 } finally {
7239 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007240 }
7241 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007242
7243 /**
7244 * Get the current signal strength information for the given subscription.
7245 * Because this information is not updated when the device is in a low power state
7246 * it should not be relied-upon to be current.
7247 * @param subId Subscription index
7248 * @return the most recent cached signal strength info from the modem
7249 */
7250 @Override
7251 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 Phone p = getPhone(subId);
7255 if (p == null) {
7256 return null;
7257 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 return p.getSignalStrength();
7260 } finally {
7261 Binder.restoreCallingIdentity(identity);
7262 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007263 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007264
Pengquan Meng77b7f132018-08-22 14:49:57 -07007265 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007266 * Get the current modem radio state for the given slot.
7267 * @param slotIndex slot index.
7268 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007269 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007270 * @return the current radio power state from the modem
7271 */
7272 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007273 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007274 Phone phone = PhoneFactory.getPhone(slotIndex);
7275 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7277 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007278 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7279 }
7280
7281 final long identity = Binder.clearCallingIdentity();
7282 try {
7283 return phone.getRadioPowerState();
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
7286 }
7287 }
7288 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7289 }
7290
7291 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007292 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7293 *
7294 * <p>Requires one of the following permissions:
7295 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7296 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7297 * privileges.
7298 *
7299 * @param subId subscription id
7300 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7301 * {@code false}.
7302 */
7303 @Override
7304 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007305 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7306 null /* message */);
7307
Pengquan Menga1bb6272018-09-06 09:59:22 -07007308 boolean isEnabled = false;
7309 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007310 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007311 Phone phone = getPhone(subId);
7312 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007313 } catch (Exception e) {
7314 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7315 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007316 } finally {
7317 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007318 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007319 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007320 }
7321
7322
7323 /**
7324 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7325 *
7326 * <p> Requires permission:
7327 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7328 * privileges.
7329 *
7330 * @param subId subscription id
7331 * @param isEnabled {@code true} means enable, {@code false} means disable.
7332 */
7333 @Override
7334 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7336 mApp, subId, "setDataRoamingEnabled");
7337
Pengquan Menga1bb6272018-09-06 09:59:22 -07007338 final long identity = Binder.clearCallingIdentity();
7339 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007340 Phone phone = getPhone(subId);
7341 if (phone != null) {
7342 phone.setDataRoamingEnabled(isEnabled);
7343 }
7344 } finally {
7345 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007346 }
7347 }
7348
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007349 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007350 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007351 TelephonyPermissions
7352 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007353 mApp, subId, "isManualNetworkSelectionAllowed");
7354
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007355 boolean isAllowed = true;
7356 final long identity = Binder.clearCallingIdentity();
7357 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007358 Phone phone = getPhone(subId);
7359 if (phone != null) {
7360 isAllowed = phone.isCspPlmnEnabled();
7361 }
7362 } finally {
7363 Binder.restoreCallingIdentity(identity);
7364 }
7365 return isAllowed;
7366 }
7367
7368 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007369 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007370 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007371 try {
7372 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007373 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007374 } catch (SecurityException e) {
7375 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7376 // has carrier privileges on an active UICC
7377 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7378 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007379 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007380 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007381 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007382
7383 final long identity = Binder.clearCallingIdentity();
7384 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007385 UiccController uiccController = UiccController.getInstance();
7386 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007387 if (hasReadPermission) {
7388 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007389 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007390
7391 // Remove private info if the caller doesn't have access
7392 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7393 for (UiccCardInfo cardInfo : cardInfos) {
7394 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7395 // is available
7396 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7397 if (card == null || card.getUiccProfile() == null) {
7398 // assume no access if the card or profile is unavailable
7399 filteredInfos.add(cardInfo.getUnprivileged());
7400 continue;
7401 }
7402 UiccProfile profile = card.getUiccProfile();
7403 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7404 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7405 filteredInfos.add(cardInfo);
7406 } else {
7407 filteredInfos.add(cardInfo.getUnprivileged());
7408 }
7409 }
7410 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
7414 }
7415
7416 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007417 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007418 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 final long identity = Binder.clearCallingIdentity();
7421 try {
7422 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7423 if (slots == null) {
7424 Rlog.i(LOG_TAG, "slots is null.");
7425 return null;
7426 }
7427
7428 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7429 for (int i = 0; i < slots.length; i++) {
7430 UiccSlot slot = slots[i];
7431 if (slot == null) {
7432 continue;
7433 }
7434
Jordan Liu7be7e652019-05-06 18:55:02 +00007435 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 UiccCard card = slot.getUiccCard();
7437 if (card != null) {
7438 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007439 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007440 cardId = slot.getEid();
7441 if (TextUtils.isEmpty(cardId)) {
7442 cardId = slot.getIccId();
7443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 }
7445
Jordan Liu857451f2019-05-09 16:35:35 -07007446 if (cardId != null) {
7447 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7448 // if cardId is an EID, it's all digits so this is fine
7449 cardId = IccUtils.stripTrailingFs(cardId);
7450 }
7451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 int cardState = 0;
7453 switch (slot.getCardState()) {
7454 case CARDSTATE_ABSENT:
7455 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7456 break;
7457 case CARDSTATE_PRESENT:
7458 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7459 break;
7460 case CARDSTATE_ERROR:
7461 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7462 break;
7463 case CARDSTATE_RESTRICTED:
7464 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7465 break;
7466 default:
7467 break;
7468
7469 }
7470
7471 infos[i] = new UiccSlotInfo(
7472 slot.isActive(),
7473 slot.isEuicc(),
7474 cardId,
7475 cardState,
7476 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007477 slot.isExtendedApduSupported(),
7478 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 }
7480 return infos;
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007483 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007484 }
7485
7486 @Override
7487 public boolean switchSlots(int[] physicalSlots) {
7488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007496 }
Jack Yu4c988042018-02-27 15:30:01 -08007497
7498 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007499 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007500 final long identity = Binder.clearCallingIdentity();
7501 try {
7502 return UiccController.getInstance().getCardIdForDefaultEuicc();
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505 }
7506 }
7507
Pengquan Meng85728fb2018-03-12 16:31:21 -07007508 /**
goneil47ffb6e2018-04-06 15:40:58 -07007509 * A test API to reload the UICC profile.
7510 *
7511 * <p>Requires that the calling app has permission
7512 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7513 * @hide
7514 */
7515 @Override
7516 public void refreshUiccProfile(int subId) {
7517 enforceModifyPermission();
7518
7519 final long identity = Binder.clearCallingIdentity();
7520 try {
7521 Phone phone = getPhone(subId);
7522 if (phone == null) {
7523 return;
7524 }
7525 UiccCard uiccCard = phone.getUiccCard();
7526 if (uiccCard == null) {
7527 return;
7528 }
7529 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7530 if (uiccProfile == null) {
7531 return;
7532 }
7533 uiccProfile.refresh();
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
7537 }
7538
7539 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007540 * Returns false if the mobile data is disabled by default, otherwise return true.
7541 */
7542 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007543 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007544 }
7545
7546 /**
7547 * Returns true if the data roaming is enabled by default, i.e the system property
7548 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7549 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7550 */
7551 private boolean getDefaultDataRoamingEnabled(int subId) {
7552 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007553 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007554 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007555 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7556 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7557 return isDataRoamingEnabled;
7558 }
7559
7560 /**
7561 * Returns the default network type for the given {@code subId}, if the default network type is
7562 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7563 */
7564 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007565 List<Integer> list = TelephonyProperties.default_network();
7566 int phoneId = mSubscriptionController.getPhoneId(subId);
7567 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7568 return list.get(phoneId);
7569 }
7570 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007571 }
fionaxua13278b2018-03-21 00:08:13 -07007572
7573 @Override
7574 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007575 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577
7578 final long identity = Binder.clearCallingIdentity();
7579 try {
7580 final Phone phone = getPhone(subId);
7581 if (phone == null) {
7582 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7583 return;
7584 }
chen xueaba88a2019-03-15 13:15:10 -07007585 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7586 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 } finally {
7588 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007589 }
fionaxua13278b2018-03-21 00:08:13 -07007590 }
7591
7592 @Override
7593 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007594 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 final Phone phone = getPhone(subId);
7599 if (phone == null) {
7600 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7601 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7602 }
7603 return phone.getCarrierIdListVersion();
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007606 }
fionaxua13278b2018-03-21 00:08:13 -07007607 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007608
7609 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007610 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7611 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007612 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007613 mApp, subId, callingPackage, callingFeatureId,
7614 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007615 return -1;
7616 }
7617
7618 final long identity = Binder.clearCallingIdentity();
7619 try {
7620 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007625
7626 @Override
7627 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007628 TelephonyPermissions
7629 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007630 mApp, subId, "getCdmaRoamingMode");
7631
7632 final long identity = Binder.clearCallingIdentity();
7633 try {
7634 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
7638 }
7639
7640 @Override
7641 public boolean setCdmaRoamingMode(int subId, int mode) {
7642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7643 mApp, subId, "setCdmaRoamingMode");
7644
7645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
7650 }
7651 }
7652
7653 @Override
7654 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7656 mApp, subId, "setCdmaSubscriptionMode");
7657
7658 final long identity = Binder.clearCallingIdentity();
7659 try {
7660 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7661 } finally {
7662 Binder.restoreCallingIdentity(identity);
7663 }
7664 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007665
sqianc5eccab2018-10-19 18:46:41 -07007666 @Override
sqian8c685422019-02-22 15:55:18 -08007667 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007668 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007670 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7671 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007672 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7673 }
7674 final long identity = Binder.clearCallingIdentity();
7675 try {
sqian854d44b2018-12-12 16:48:18 -08007676 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7677 for (Phone phone: PhoneFactory.getPhones()) {
7678 if (phone.getEmergencyNumberTracker() != null
7679 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7680 emergencyNumberListInternal.put(
7681 phone.getSubId(),
7682 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7683 }
sqian11b7a0e2018-12-05 18:48:28 -08007684 }
sqian854d44b2018-12-12 16:48:18 -08007685 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
sqianc5eccab2018-10-19 18:46:41 -07007689 }
7690
7691 @Override
sqian8c685422019-02-22 15:55:18 -08007692 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007693 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007694 if (!exactMatch) {
7695 TelephonyPermissions
7696 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007697 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007698 }
7699 final long identity = Binder.clearCallingIdentity();
7700 try {
sqian854d44b2018-12-12 16:48:18 -08007701 for (Phone phone: PhoneFactory.getPhones()) {
7702 if (phone.getEmergencyNumberTracker() != null
7703 && phone.getEmergencyNumberTracker() != null) {
7704 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7705 number, exactMatch)) {
7706 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007707 }
7708 }
sqian11b7a0e2018-12-05 18:48:28 -08007709 }
7710 return false;
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
7713 }
7714 }
7715
sqianf4ca7ed2019-01-15 18:32:07 -08007716 /**
7717 * Update emergency number list for test mode.
7718 */
7719 @Override
7720 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7721 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7722 "updateEmergencyNumberListTestMode");
7723
7724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 for (Phone phone: PhoneFactory.getPhones()) {
7727 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7728 if (tracker != null) {
7729 tracker.executeEmergencyNumberTestModeCommand(action, num);
7730 }
7731 }
7732 } finally {
7733 Binder.restoreCallingIdentity(identity);
7734 }
7735 }
7736
7737 /**
7738 * Get the full emergency number list for test mode.
7739 */
7740 @Override
7741 public List<String> getEmergencyNumberListTestMode() {
7742 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7743 "getEmergencyNumberListTestMode");
7744
7745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 Set<String> emergencyNumbers = new HashSet<>();
7748 for (Phone phone: PhoneFactory.getPhones()) {
7749 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7750 if (tracker != null) {
7751 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7752 emergencyNumbers.add(num.getNumber());
7753 }
7754 }
7755 }
7756 return new ArrayList<>(emergencyNumbers);
7757 } finally {
7758 Binder.restoreCallingIdentity(identity);
7759 }
7760 }
7761
chen xud6b45bd2018-10-30 22:27:10 -07007762 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007763 public int getEmergencyNumberDbVersion(int subId) {
7764 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7765
7766 final long identity = Binder.clearCallingIdentity();
7767 try {
7768 final Phone phone = getPhone(subId);
7769 if (phone == null) {
7770 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7771 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7772 }
7773 return phone.getEmergencyNumberDbVersion();
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
7776 }
7777 }
7778
7779 @Override
7780 public void notifyOtaEmergencyNumberDbInstalled() {
7781 enforceModifyPermission();
7782
7783 final long identity = Binder.clearCallingIdentity();
7784 try {
7785 for (Phone phone: PhoneFactory.getPhones()) {
7786 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7787 if (tracker != null) {
7788 tracker.updateOtaEmergencyNumberDatabase();
7789 }
7790 }
7791 } finally {
7792 Binder.restoreCallingIdentity(identity);
7793 }
7794 }
7795
7796 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007797 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007798 enforceActiveEmergencySessionPermission();
7799
7800 final long identity = Binder.clearCallingIdentity();
7801 try {
7802 for (Phone phone: PhoneFactory.getPhones()) {
7803 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7804 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007805 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7806 }
7807 }
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
7810 }
7811 }
7812
7813 @Override
7814 public void resetOtaEmergencyNumberDbFilePath() {
7815 enforceActiveEmergencySessionPermission();
7816
7817 final long identity = Binder.clearCallingIdentity();
7818 try {
7819 for (Phone phone: PhoneFactory.getPhones()) {
7820 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7821 if (tracker != null) {
7822 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007823 }
7824 }
7825 } finally {
7826 Binder.restoreCallingIdentity(identity);
7827 }
7828 }
7829
7830 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007831 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7832 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7833 Phone phone = getPhone(subId);
7834 if (phone == null) {
7835 return null;
7836 }
7837 final long identity = Binder.clearCallingIdentity();
7838 try {
7839 UiccProfile profile = UiccController.getInstance()
7840 .getUiccProfileForPhone(phone.getPhoneId());
7841 if (profile != null) {
7842 return profile.getCertsFromCarrierPrivilegeAccessRules();
7843 }
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 return null;
7848 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007849
7850 /**
7851 * Enable or disable a modem stack.
7852 */
7853 @Override
7854 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7855 enforceModifyPermission();
7856
7857 final long identity = Binder.clearCallingIdentity();
7858 try {
7859 Phone phone = PhoneFactory.getPhone(slotIndex);
7860 if (phone == null) {
7861 return false;
7862 } else {
7863 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7864 }
7865 } finally {
7866 Binder.restoreCallingIdentity(identity);
7867 }
7868 }
Michelecea4cf22018-12-21 15:00:11 -08007869
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007870 /**
7871 * Whether a modem stack is enabled or not.
7872 */
7873 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007874 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7875 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007876 Phone phone = PhoneFactory.getPhone(slotIndex);
7877 if (phone == null) return false;
7878
7879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007880 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7881 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007882 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7883 }
7884
7885 final long identity = Binder.clearCallingIdentity();
7886 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007887 try {
7888 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7889 } catch (NoSuchElementException ex) {
7890 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7891 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
7895 }
7896
Michelecea4cf22018-12-21 15:00:11 -08007897 @Override
Michele0ea7d782019-03-19 14:58:42 -07007898 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007899 enforceModifyPermission();
7900
7901 final long identity = Binder.clearCallingIdentity();
7902 try {
7903 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007904 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007905 .commit();
7906 } finally {
7907 Binder.restoreCallingIdentity(identity);
7908 }
7909 }
7910
7911 @Override
Michele0ea7d782019-03-19 14:58:42 -07007912 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007913 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007915 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7916 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007917 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007918 }
Michelecea4cf22018-12-21 15:00:11 -08007919
7920 final long identity = Binder.clearCallingIdentity();
7921 try {
Michele0ea7d782019-03-19 14:58:42 -07007922 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007923 } finally {
7924 Binder.restoreCallingIdentity(identity);
7925 }
7926 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007927
Michele0ea7d782019-03-19 14:58:42 -07007928 @TelephonyManager.IsMultiSimSupportedResult
7929 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007930 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7931 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7932 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007933 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7934 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007935 }
7936 // Check if the hardware supports multisim functionality. If usage of multisim is not
7937 // supported by the modem, indicate that it is restricted.
7938 PhoneCapability staticCapability =
7939 mPhoneConfigurationManager.getStaticPhoneCapability();
7940 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007941 loge("isMultiSimSupportedInternal: no static configuration available");
7942 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007943 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00007944 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007945 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7946 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007947 }
7948 // Check if support of multiple SIMs is restricted by carrier
7949 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007950 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007951 }
7952
Michele0ea7d782019-03-19 14:58:42 -07007953 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007954 }
7955
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007956 /**
7957 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007958 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7959 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7960 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007961 * @param numOfSims number of active sims we want to switch to
7962 */
7963 @Override
7964 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007965 if (numOfSims == 1) {
7966 enforceModifyPermission();
7967 } else {
7968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7969 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7970 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007971 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007972
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007973 try {
Michele30b57b22019-03-01 12:01:14 -08007974 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007975 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007976 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7977 return;
7978 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007979 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
7982 }
7983 }
7984
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007985 @Override
7986 public boolean isApplicationOnUicc(int subId, int appType) {
7987 enforceReadPrivilegedPermission("isApplicationOnUicc");
7988 Phone phone = getPhone(subId);
7989 if (phone == null) {
7990 return false;
7991 }
7992 final long identity = Binder.clearCallingIdentity();
7993 try {
7994 UiccCard uiccCard = phone.getUiccCard();
7995 if (uiccCard == null) {
7996 return false;
7997 }
7998 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7999 if (uiccProfile == null) {
8000 return false;
8001 }
8002 if (TelephonyManager.APPTYPE_SIM <= appType
8003 && appType <= TelephonyManager.APPTYPE_ISIM) {
8004 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8005 }
8006 return false;
8007 } finally {
8008 Binder.restoreCallingIdentity(identity);
8009 }
8010 }
8011
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008012 /**
chen xub4baa772019-04-03 10:23:41 -07008013 * Get whether making changes to modem configurations will trigger reboot.
8014 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008015 */
8016 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008017 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8018 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008020 mApp, subId, callingPackage, callingFeatureId,
8021 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008022 return false;
8023 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008024 final long identity = Binder.clearCallingIdentity();
8025 try {
8026 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
8030 }
8031
Nathan Harold29f5f052019-02-15 13:41:57 -08008032 private void updateModemStateMetrics() {
8033 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8034 // TODO: check the state for each modem if the api is ready.
8035 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8036 }
8037
Pengquan Meng3889a572019-01-23 11:16:29 -08008038 @Override
8039 public int[] getSlotsMapping() {
8040 enforceReadPrivilegedPermission("getSlotsMapping");
8041
8042 final long identity = Binder.clearCallingIdentity();
8043 try {
8044 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8045 // All logical slots should have a mapping to a physical slot.
8046 int[] logicalSlotsMapping = new int[phoneCount];
8047 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8048 for (int i = 0; i < slotInfos.length; i++) {
8049 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8050 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8051 }
8052 }
8053 return logicalSlotsMapping;
8054 } finally {
8055 Binder.restoreCallingIdentity(identity);
8056 }
8057 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008058
8059 /**
8060 * Get the IRadio HAL Version
8061 */
8062 @Override
8063 public int getRadioHalVersion() {
8064 Phone phone = getDefaultPhone();
8065 if (phone == null) return -1;
8066 HalVersion hv = phone.getHalVersion();
8067 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8068 return hv.major * 100 + hv.minor;
8069 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008070
8071 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008072 * Get the current calling package name.
8073 * @return the current calling package name
8074 */
8075 @Override
8076 public String getCurrentPackageName() {
8077 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8078 }
8079
8080 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008081 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8082 * corresponding network requests on a subId.
8083 *
8084 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008085 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008086 * 2) APN is un-metered for this subscription, or
8087 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008088 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008089 *
8090 * @return whether data is allowed for a apn type.
8091 *
8092 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008093 */
8094 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008095 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008096 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8097 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008098
8099 // Now that all security checks passes, perform the operation as ourselves.
8100 final long identity = Binder.clearCallingIdentity();
8101 try {
8102 Phone phone = getPhone(subId);
8103 if (phone == null) return false;
8104
Jack Yu41407ee2019-05-13 16:54:09 -07008105 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008106 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8107 } finally {
8108 Binder.restoreCallingIdentity(identity);
8109 }
8110 }
8111
8112 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008113 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008114 enforceReadPrivilegedPermission("isApnMetered");
8115
8116 // Now that all security checks passes, perform the operation as ourselves.
8117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 Phone phone = getPhone(subId);
8120 if (phone == null) return true; // By default return true.
8121
Jack Yu41407ee2019-05-13 16:54:09 -07008122 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008123 } finally {
8124 Binder.restoreCallingIdentity(identity);
8125 }
8126 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008127
8128 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008129 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8130 int subscriptionId, IBooleanConsumer resultCallback) {
8131 enforceModifyPermission();
8132 long token = Binder.clearCallingIdentity();
8133 try {
8134 Phone phone = getPhone(subscriptionId);
8135 if (phone == null) {
8136 try {
8137 if (resultCallback != null) {
8138 resultCallback.accept(false);
8139 }
8140 } catch (RemoteException e) {
8141 // ignore
8142 }
8143 return;
8144 }
8145 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8146 Pair.create(specifiers, (x) -> {
8147 try {
8148 if (resultCallback != null) {
8149 resultCallback.accept(x);
8150 }
8151 } catch (RemoteException e) {
8152 // ignore
8153 }
8154 });
8155 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8156 } finally {
8157 Binder.restoreCallingIdentity(token);
8158 }
8159 }
8160
8161 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008162 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8163 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8164 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8165 if (iccRecords == null) {
8166 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8167 return false;
8168 }
8169 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8170 }
8171
8172 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008173 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8174 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008175 if (callingPackage == null) {
8176 callingPackage = getCurrentPackageName();
8177 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008178 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8179 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008180 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8181 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008182 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8183 }
8184 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8185 Intent intent = new Intent();
8186 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8187 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8188 // Bring up choose default SMS subscription dialog right now
8189 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8190 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8191 mApp.startActivity(intent);
8192 }
chen xud5ca2d52019-05-28 15:20:57 -07008193
8194 @Override
8195 public String getMmsUAProfUrl(int subId) {
8196 //TODO investigate if this API should require proper permission check in R b/133791609
8197 final long identity = Binder.clearCallingIdentity();
8198 try {
8199 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8200 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
8204 }
8205
8206 @Override
8207 public String getMmsUserAgent(int subId) {
8208 //TODO investigate if this API should require proper permission check in R b/133791609
8209 final long identity = Binder.clearCallingIdentity();
8210 try {
8211 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8212 .getString(com.android.internal.R.string.config_mms_user_agent);
8213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
8216 }
Jack Yub07d4972019-05-28 16:12:25 -07008217
8218 @Override
8219 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8220 enforceModifyPermission();
8221
8222 // Now that all security checks passes, perform the operation as ourselves.
8223 final long identity = Binder.clearCallingIdentity();
8224 try {
8225 Phone phone = getPhone(subId);
8226 if (phone == null) return false;
8227
8228 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8229 } finally {
8230 Binder.restoreCallingIdentity(identity);
8231 }
8232 }
8233
8234 @Override
8235 public boolean isDataAllowedInVoiceCall(int subId) {
8236 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
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().isDataAllowedInVoiceCall();
8245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
8248 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008249
changbetty97defcf2019-12-24 15:40:37 +08008250 @Override
8251 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8252 enforceModifyPermission();
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().setAlwaysAllowMmsData(alwaysAllow);
8261 } finally {
8262 Binder.restoreCallingIdentity(identity);
8263 }
8264 }
8265
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008266 /**
8267 * Updates whether conference event pacakge handling is enabled.
8268 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8269 * otherwise.
8270 */
8271 @Override
8272 public void setCepEnabled(boolean isCepEnabled) {
8273 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8274
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8278 for (Phone phone : PhoneFactory.getPhones()) {
8279 Phone defaultPhone = phone.getImsPhone();
8280 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8281 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8282 ImsPhoneCallTracker imsPhoneCallTracker =
8283 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8284 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8285 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8286 + imsPhone.getMsisdn());
8287 }
8288 }
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
8292 }
allenwtsu46dcc572020-01-08 18:24:03 +08008293
8294 /**
8295 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8296 *
8297 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8298 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8299 * before being read.
8300 */
8301 @Override
8302 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8303 isCompressed) {
8304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8305 mApp, subId, "notifyRcsAutoConfigurationReceived");
8306 try {
8307 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8308 if (configBinder == null) {
8309 Rlog.e(LOG_TAG, "null result for getImsConfig");
8310 } else {
8311 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8312 }
8313 } catch (RemoteException e) {
8314 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8315 }
8316 }
zoey chenf95ca592019-12-30 16:11:23 +08008317
8318 @Override
8319 public boolean isIccLockEnabled(int subId) {
8320 enforceReadPrivilegedPermission("isIccLockEnabled");
8321
8322 // Now that all security checks passes, perform the operation as ourselves.
8323 final long identity = Binder.clearCallingIdentity();
8324 try {
8325 Phone phone = getPhone(subId);
8326 if (phone != null && phone.getIccCard() != null) {
8327 return phone.getIccCard().getIccLockEnabled();
8328 } else {
8329 return false;
8330 }
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
8334 }
8335
8336 /**
8337 * Set the ICC pin lock enabled or disabled..
8338 *
8339 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8340 * 0 or a positive integer as the attempts remaining value.
8341 *
8342 */
8343 @Override
8344 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8345 enforceModifyPermission();
8346
8347 Phone phone = getPhone(subId);
8348 if (phone == null) {
8349 return 0;
8350 }
8351 // Now that all security checks passes, perform the operation as ourselves.
8352 final long identity = Binder.clearCallingIdentity();
8353 try {
8354 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8355 new Pair<Boolean, String>(enabled, password), phone, null);
8356 return attemptsRemaining;
8357
8358 } catch (Exception e) {
8359 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
8363 return 0;
8364 }
8365
8366 /**
8367 * Change the ICC password used in ICC pin lock.
8368 *
8369 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8370 * 0 or a positive integer as the attempts remaining value.
8371 *
8372 */
8373 @Override
8374 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8375 enforceModifyPermission();
8376
8377 Phone phone = getPhone(subId);
8378 if (phone == null) {
8379 return 0;
8380 }
8381 // Now that all security checks passes, perform the operation as ourselves.
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8385 new Pair<String, String>(oldPassword, newPassword), phone, null);
8386 return attemptsRemaining;
8387
8388 } catch (Exception e) {
8389 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8390 } finally {
8391 Binder.restoreCallingIdentity(identity);
8392 }
8393 return 0;
8394 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008395
8396 @Override
8397 public boolean canConnectTo5GInDsdsMode() {
8398 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008400}